Skip to content

Commit eb58b29

Browse files
committed
Fix --post-js scripts in MINIMAL_RUNTIME to execute after main() in MODULARIZE mode. Fixes test minimal0.test_unicode_js_library after this change: https://github.com/emscripten-core/emscripten/pull/23157/files#r1889243405
1 parent 8d9966a commit eb58b29

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/postamble_minimal.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var imports = {
128128
// precompiled WebAssembly Module.
129129
assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM');
130130
#endif
131-
#if AUDIO_WORKLET
131+
#if AUDIO_WORKLET || MODULARIZE
132132
instantiatePromise =
133133
#endif
134134
(WebAssembly.instantiateStreaming
@@ -139,7 +139,7 @@ instantiatePromise =
139139
? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports)
140140
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
141141
#else
142-
#if AUDIO_WORKLET
142+
#if AUDIO_WORKLET || MODULARIZE
143143
instantiatePromise =
144144
#endif
145145
WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => {
@@ -158,7 +158,7 @@ assert(Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm
158158

159159
// Add missingProperties supression here because closure compiler doesn't know that
160160
// WebAssembly.instantiate is polymorphic in its return value.
161-
#if AUDIO_WORKLET
161+
#if AUDIO_WORKLET || MODULARIZE
162162
instantiatePromise =
163163
#endif
164164
WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProperties} */ (output) => {
@@ -279,3 +279,10 @@ WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProp
279279
// When running in a background thread we delay module loading until we have
280280
{{{ runIfMainThread('loadModule();') }}}
281281
#endif
282+
283+
#if MODULARIZE
284+
// The semantics of MODULARIZE and --post-js foo.js scripts require that main()
285+
// should run before any of the --post-js scripts. Therefore await instantiation
286+
// here before reaching execution to the --post-js scripts.
287+
await instantiatePromise;
288+
#endif

0 commit comments

Comments
 (0)