Skip to content

Commit 0e25a13

Browse files
authored
[dylink] Use an async iife to loadAsync loadWebAssemblyModule (#24021)
Split from #23619
1 parent b1ef10f commit 0e25a13

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/lib/libdylink.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,18 @@ var LibraryDylink = {
871871
}
872872

873873
if (flags.loadAsync) {
874-
if (binary instanceof WebAssembly.Module) {
875-
var instance = new WebAssembly.Instance(binary, info);
876-
return Promise.resolve(postInstantiation(binary, instance));
877-
}
878-
return WebAssembly.instantiate(binary, info).then(
879-
(result) => postInstantiation(result.module, result.instance)
880-
);
874+
return (async () => {
875+
var instance;
876+
if (binary instanceof WebAssembly.Module) {
877+
instance = new WebAssembly.Instance(binary, info);
878+
} else {
879+
// Destructuring assignment without declaration has to be wrapped
880+
// with parens or parser will treat the l-value as an object
881+
// literal instead.
882+
({ module: binary, instance } = await WebAssembly.instantiate(binary, info));
883+
}
884+
return postInstantiation(binary, instance);
885+
})();
881886
}
882887

883888
var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5858
1+
5863
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12832
1+
12844

0 commit comments

Comments
 (0)