Skip to content

Commit a18ff2d

Browse files
committed
Simplify MODULARIZE code to always use async factory function
The docs here were wrong. We have the `addRunDependency` system that can delay module's readiness for an arbitrary amount of time, even if async compilation is disabled. This `addRunDependency` system does not exist in MINUMAL_RUTTIME, so in some cases we can avoid the ready promise in MINIMAL_RUNTIME mode, but that is a pretty subtle distinction that only applies to MINIMAL_RUNTIME. Also even in this mode we were still marking the factory function as async (note the lack of USE_READY_PROMISE in the existing condition).
1 parent a8e7921 commit a18ff2d

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/modularize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var {{{ EXPORT_NAME }}} = (() => {
1919
// after document.currentScript is gone, so we save it.
2020
// In EXPORT_ES6 mode we can just use 'import.meta.url'.
2121
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
22-
return {{{ asyncIf(WASM_ASYNC_COMPILATION || (EXPORT_ES6 && ENVIRONMENT_MAY_BE_NODE)) }}}function(moduleArg = {}) {
22+
return async function(moduleArg = {}) {
2323
var moduleRtn;
2424

2525
"<<< INNER_JS_CODE >>>"
@@ -30,7 +30,7 @@ var {{{ EXPORT_NAME }}} = (() => {
3030
#else
3131
// When targetting node and ES6 we use `await import ..` in the generated code
3232
// so the outer function needs to be marked as async.
33-
{{{ asyncIf(WASM_ASYNC_COMPILATION || (EXPORT_ES6 && ENVIRONMENT_MAY_BE_NODE)) }}}function {{{ EXPORT_NAME }}}(moduleArg = {}) {
33+
async function {{{ EXPORT_NAME }}}(moduleArg = {}) {
3434
var moduleRtn;
3535

3636
"<<< INNER_JS_CODE >>>"

src/settings.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,9 @@ var DETERMINISTIC = false;
12571257
// By default we emit all code in a straightforward way into the output
12581258
// .js file. That means that if you load that in a script tag in a web
12591259
// page, it will use the global scope. With ``MODULARIZE`` set, we instead emit
1260-
// the code wrapped in a function that returns a promise. The promise is
1261-
// resolved with the module instance when it is safe to run the compiled code,
1262-
// similar to the ``onRuntimeInitialized`` callback. You do not need to use the
1263-
// ``onRuntimeInitialized`` callback when using ``MODULARIZE``.
1264-
//
1265-
// (If WASM_ASYNC_COMPILATION is off, that is, if compilation is
1266-
// *synchronous*, then it would not make sense to return a Promise, and instead
1267-
// the Module object itself is returned, which is ready to be used.)
1260+
// the code wrapped in an async function. This functions returns a promise that
1261+
// resolves to a module instance when once it is safe to run the compiled code
1262+
// (similar to the ``onRuntimeInitialized`` callback).
12681263
//
12691264
// The default name of the function is ``Module``, but can be changed using the
12701265
// ``EXPORT_NAME`` option. We recommend renaming it to a more typical name for a

0 commit comments

Comments
 (0)