You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert createWasm async/await where possible (#23157)
The advantage if using `await` in the cases where we can is that it
avoids the generation or wrapper function for each export.
So instead of:
```
var wasmExport = createWasm(); // returns empty object
...
var malloc = (..) => (malloc = wasmExports['malloc'])(..);
```
We can generate:
```
var wasmExport = await createWasm(); // returns actual exports
...
var malloc = wasmExports['malloc'];
```
This only currently works in MODULARIZE mode where the code is running
inside a factory function. Otherwise it would end up using
top-level-await.
One wrinkle here is that this is not currently supported when closure is
enabled because we run closure only on the contents of the factory
function so closure ends up seeing this as a top level await when its
not.
There are two minor observable effects of this change:
1. In `MODULARIZE` mode its no longer possible to call `new Foo()` with
factory function. We already added a debug error for in #23210.
2. Because we now can `await` for createWasm to return, the `run` method
can run on first call, which means it runs `main` on first call, which
means main will now run before `postjs` code, just like it would with
sync instantiation.
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
1042
1042
// When the regression is fixed, can restore the above PTHREADS-enabled path.
1043
-
receiveInstance(result['instance']);
1043
+
returnreceiveInstance(result['instance']);
1044
1044
#endif
1045
1045
}
1046
1046
#endif // WASM_ASYNC_COMPILATION
@@ -1076,8 +1076,7 @@ function getWasmImports() {
1076
1076
// Instantiate from the module posted from the main thread.
1077
1077
// We can just use sync instantiation in the worker.
0 commit comments