Skip to content

Commit 033194e

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 71e0500 commit 033194e

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
@@ -164,7 +164,7 @@ var imports = {
164164
// precompiled WebAssembly Module.
165165
assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM');
166166
#endif
167-
#if AUDIO_WORKLET
167+
#if AUDIO_WORKLET || MODULARIZE
168168
instantiatePromise =
169169
#endif
170170
(WebAssembly.instantiateStreaming
@@ -175,7 +175,7 @@ instantiatePromise =
175175
? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports)
176176
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
177177
#else
178-
#if AUDIO_WORKLET
178+
#if AUDIO_WORKLET || MODULARIZE
179179
instantiatePromise =
180180
#endif
181181
WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => {
@@ -194,7 +194,7 @@ assert(Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm
194194

195195
// Add missingProperties supression here because closure compiler doesn't know that
196196
// WebAssembly.instantiate is polymorphic in its return value.
197-
#if AUDIO_WORKLET
197+
#if AUDIO_WORKLET || MODULARIZE
198198
instantiatePromise =
199199
#endif
200200
WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProperties} */ (output) => {
@@ -315,3 +315,10 @@ WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProp
315315
// When running in a background thread we delay module loading until we have
316316
{{{ runIfMainThread('loadModule();') }}}
317317
#endif
318+
319+
#if MODULARIZE
320+
// The semantics of MODULARIZE and --post-js foo.js scripts require that main()
321+
// should run before any of the --post-js scripts. Therefore await instantiation
322+
// here before reaching execution to the --post-js scripts.
323+
await instantiatePromise;
324+
#endif

0 commit comments

Comments
 (0)