diff --git a/src/preamble.js b/src/preamble.js index 032eff4b8eeb8..b70af7d848f16 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -608,14 +608,14 @@ function instrumentWasmTableWithAbort() { #endif var wasmBinaryFile; -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE +#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE && !AUDIO_WORKLET // `URL` is undefined in Audio Worklet scope, so we cannot use `new URL()`. if (Module['locateFile']) { #endif wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}'; if (!isDataURI(wasmBinaryFile)) { wasmBinaryFile = locateFile(wasmBinaryFile); } -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE // in single-file mode, repeating WASM_BINARY_FILE would emit the contents again +#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()`. } else { #if ENVIRONMENT_MAY_BE_SHELL if (ENVIRONMENT_IS_SHELL) @@ -1001,7 +1001,7 @@ function createWasm() { assert(wasmTable, 'table not found in wasm exports'); #endif -#if AUDIO_WORKLET +#if AUDIO_WORKLET && !(EXPORT_ES6 && ASSERTIONS) // If EXPORT_ES6, we may have already done this. // If we are in the audio worklet environment, we can only access the Module object // and not the global scope of the main JS script. Therefore we need to export // all functions that the audio worklet scope needs onto the Module object. diff --git a/test/test_browser.py b/test/test_browser.py index 5182b42d66a3d..e5d545e7adfe0 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5759,6 +5759,8 @@ def test_full_js_library_strict(self): 'pthreads_and_closure': (['-pthread', '--closure', '1', '-Oz'],), 'minimal_runtime': (['-sMINIMAL_RUNTIME'],), 'minimal_runtime_pthreads_and_closure': (['-sMINIMAL_RUNTIME', '-pthread', '--closure', '1', '-Oz'],), + 'pthreads_es6': (['-pthread', '-sPTHREAD_POOL_SIZE=2', '-sEXPORT_ES6'],), + 'es6': (['-sEXPORT_ES6'],), }) def test_audio_worklet(self, args): if '-sMEMORY64' in args and is_firefox(): diff --git a/tools/link.py b/tools/link.py index 97882439c9eb4..5a6cd771925b8 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1350,6 +1350,10 @@ def phase_linker_setup(options, state, newargs): # MINIMAL_RUNTIME exports these manually, since this export mechanism is placed # in global scope that is not suitable for MINIMAL_RUNTIME loader. settings.EXPORTED_RUNTIME_METHODS += ['stackSave', 'stackAlloc', 'stackRestore'] + if settings.EXPORT_ES6 and settings.ASSERTIONS: + # With ASSERTIONS, EXPORT_ES6 assigns a read-only getter that prevents assigning + # Module['wasmTable'], which will then prevent the Audio Worklet from loading. + settings.EXPORTED_RUNTIME_METHODS += ['wasmTable'] if settings.FORCE_FILESYSTEM and not settings.MINIMAL_RUNTIME: # when the filesystem is forced, we export by default methods that filesystem usage