diff --git a/src/audio_worklet.js b/src/audio_worklet.js index e427e4ee3519a..d3880a5e47e81 100644 --- a/src/audio_worklet.js +++ b/src/audio_worklet.js @@ -153,6 +153,10 @@ class BootstrapMessages extends AudioWorkletProcessor { messagePort = this.port; /** @suppress {checkTypes} */ messagePort.onmessage = async (msg) => { +#if MINIMAL_RUNTIME + // Wait for the module instantiation before processing messages. + await instantiatePromise; +#endif let d = msg.data; if (d['_wpn']) { // '_wpn' is short for 'Worklet Processor Node', using an identifier diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 247d1a4c765e3..420df69a4f41d 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -92,6 +92,8 @@ var wasmExports; var wasmModule; #endif +var instantiatePromise; + #if PTHREADS || WASM_WORKERS function loadModule() { assignWasmImports(); @@ -114,11 +116,11 @@ var imports = { // precompiled WebAssembly Module. assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM'); #endif -(WebAssembly.instantiateStreaming +instantiatePromise = (WebAssembly.instantiateStreaming ? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports) : WebAssembly.instantiate(Module['wasm'], imports)).then((output) => { #else -WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => { +instantiatePromise = WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => { #endif #else // Non-streaming instantiation @@ -132,7 +134,7 @@ assert(Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm {{{ exportJSSymbols() }}} -WebAssembly.instantiate(Module['wasm'], imports).then((output) => { +instantiatePromise = WebAssembly.instantiate(Module['wasm'], imports).then((output) => { #endif #if !LibraryManager.has('libexports.js')