diff --git a/src/preamble.js b/src/preamble.js index b256582a05589..4f4dc32dba0ca 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -603,8 +603,13 @@ function instrumentWasmTableWithAbort() { } #endif +#if SINGLE_FILE +// In SINGLE_FILE mode the wasm binary is encoded inline here as a data: URL. +var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}'; +#else +var wasmBinaryFile; function findWasmBinary() { -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE && !AUDIO_WORKLET +#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET if (Module['locateFile']) { #endif var f = '{{{ WASM_BINARY_FILE }}}'; @@ -614,7 +619,7 @@ function findWasmBinary() { } #endif return f; -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE && !AUDIO_WORKLET // In single-file mode, repeating WASM_BINARY_FILE would emit the contents again. For an Audio Worklet, we cannot use `new URL()`. +#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // In single-file mode, repeating WASM_BINARY_FILE would emit the contents again. For an Audio Worklet, we cannot use `new URL()`. } #if ENVIRONMENT_MAY_BE_SHELL if (ENVIRONMENT_IS_SHELL) @@ -624,8 +629,7 @@ function findWasmBinary() { return new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href; #endif } - -var wasmBinaryFile; +#endif function getBinarySync(file) { if (file == wasmBinaryFile && wasmBinary) { @@ -1079,7 +1083,9 @@ function getWasmImports() { } #endif +#if !SINGLE_FILE wasmBinaryFile ??= findWasmBinary(); +#endif #if WASM_ASYNC_COMPILATION #if RUNTIME_DEBUG