From 8d46778dcd1d96493d1feafb950fa79a7d587d7f Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 15 Dec 2024 12:33:03 -0800 Subject: [PATCH] Remove USE_ES6_IMPORT_META setting This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: https://github.com/tc39/proposal-import-meta/pull/21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See #9234 and #8729 --- ChangeLog.md | 4 ++++ .../docs/tools_reference/settings_reference.rst | 12 ------------ src/lib/libpthread.js | 6 +++--- src/parseTools.mjs | 2 +- src/preamble.js | 4 ++-- src/settings.js | 8 +------- test/test_other.py | 15 --------------- tools/link.py | 14 +++++++------- tools/settings.py | 1 - 9 files changed, 18 insertions(+), 48 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 51468e5e800bb..4ec36825d0a48 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -27,6 +27,10 @@ See docs/process.md for more on how version tagging works. (#20735) - Added Lua contrib port (`--use-port=contrib.lua`) to easily embed the Lua scripting language in any C/C++ Emscripten project (#23682) +- The `USE_ES6_IMPORT_META` settings was removed. This setting was always + on by default, but now it cannot be disabled. This setting was originally + added in 2019 as a temporary measure while engines and bundlers learned to + deal with `import.meta`. (#23171) 4.0.3 - 02/07/25 ---------------- diff --git a/site/source/docs/tools_reference/settings_reference.rst b/site/source/docs/tools_reference/settings_reference.rst index ebdfa0d3593c5..b0a81110c0fc5 100644 --- a/site/source/docs/tools_reference/settings_reference.rst +++ b/site/source/docs/tools_reference/settings_reference.rst @@ -1978,18 +1978,6 @@ This is implicitly enabled if the output suffix is set to 'mjs'. Default value: false -.. _use_es6_import_meta: - -USE_ES6_IMPORT_META -=================== - -Use the ES6 Module relative import feature 'import.meta.url' -to auto-detect WASM Module path. -It might not be supported on old browsers / toolchains. This setting -may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*). - -Default value: true - .. _export_name: EXPORT_NAME diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index 18619aae19201..e30b73c2f311d 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -418,7 +418,7 @@ var LibraryPThread = { // Creates a new web Worker and places it in the unused worker pool to wait for its use. allocateUnusedWorker() { var worker; -#if EXPORT_ES6 && USE_ES6_IMPORT_META +#if EXPORT_ES6 // If we're using module output, use bundler-friendly pattern. #if PTHREADS_DEBUG dbg(`Allocating a new web worker from ${import.meta.url}`); @@ -440,7 +440,7 @@ var LibraryPThread = { // the first case in their bundling step. The latter ends up producing an invalid // URL to import from the server (e.g., for webpack the file:// path). worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}}); -#else +#else // EXPORT_ES6 var pthreadMainJs = _scriptName; #if expectToReceiveOnModule('mainScriptUrlOrBlob') // We can't use makeModuleReceiveWithVar here since we want to also @@ -463,7 +463,7 @@ var LibraryPThread = { } else #endif worker = new Worker(pthreadMainJs, {{{ pthreadWorkerOptions }}}); -#endif // EXPORT_ES6 && USE_ES6_IMPORT_META +#endif // EXPORT_ES6 PThread.unusedWorkers.push(worker); }, diff --git a/src/parseTools.mjs b/src/parseTools.mjs index 7959afefec8d4..327e3d1ab2a79 100644 --- a/src/parseTools.mjs +++ b/src/parseTools.mjs @@ -65,7 +65,7 @@ function findIncludeFile(filename, currentDir) { // Also handles #include x.js (similar to C #include ) export function preprocess(filename) { let text = readFile(filename); - if (EXPORT_ES6 && USE_ES6_IMPORT_META) { + if (EXPORT_ES6) { // `eval`, Terser and Closure don't support module syntax; to allow it, // we need to temporarily replace `import.meta` and `await import` usages // with placeholders during preprocess phase, and back after all the other ops. diff --git a/src/preamble.js b/src/preamble.js index c1a20b16515dc..4d516dab9d9a1 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -564,11 +564,11 @@ var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}'; #else var wasmBinaryFile; function findWasmBinary() { -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET +#if EXPORT_ES6 && !AUDIO_WORKLET if (Module['locateFile']) { #endif return locateFile('{{{ WASM_BINARY_FILE }}}'); -#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`. +#if EXPORT_ES6 && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`. } #if ENVIRONMENT_MAY_BE_SHELL if (ENVIRONMENT_IS_SHELL) { diff --git a/src/settings.js b/src/settings.js index db19c959bc2e7..533a797aad347 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1353,13 +1353,6 @@ var MODULARIZE = false; // [link] var EXPORT_ES6 = false; -// Use the ES6 Module relative import feature 'import.meta.url' -// to auto-detect WASM Module path. -// It might not be supported on old browsers / toolchains. This setting -// may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*). -// [link] -var USE_ES6_IMPORT_META = true; - // Global variable to export the module as for environments without a // standardized module loading system (e.g. the browser and SM shell). // [link] @@ -2270,4 +2263,5 @@ var LEGACY_SETTINGS = [ ['MIN_IE_VERSION', [0x7FFFFFFF], 'No longer supported'], ['WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG', [0], 'No longer supported'], ['AUTO_ARCHIVE_INDEXES', [0, 1], 'No longer needed'], + ['USE_ES6_IMPORT_META', [1], 'Disabling is no longer supported'], ]; diff --git a/test/test_other.py b/test/test_other.py index 0777545c2a703..dadaefb3b326d 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -402,16 +402,6 @@ def test_emcc_output_mjs_closure(self): self.assertContained('new URL("hello_world.wasm", import.meta.url)', src) self.assertContained('hello, world!', self.run_js('hello_world.mjs')) - def test_emcc_output_mjs_web_no_import_meta(self): - # Ensure we don't emit import.meta.url at all for: - # ENVIRONMENT=web + EXPORT_ES6 + USE_ES6_IMPORT_META=0 - self.run_process([EMCC, '-o', 'hello_world.mjs', - test_file('hello_world.c'), - '-sENVIRONMENT=web', '-sUSE_ES6_IMPORT_META=0']) - src = read_file('hello_world.mjs') - self.assertNotContained('import.meta.url', src) - self.assertContained('export default Module;', src) - def test_export_es6_implies_modularize(self): self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6']) src = read_file('a.out.js') @@ -421,11 +411,6 @@ def test_export_es6_requires_modularize(self): err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0']) self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err) - def test_export_es6_node_requires_import_meta(self): - err = self.expect_fail([EMCC, test_file('hello_world.c'), - '-sENVIRONMENT=node', '-sEXPORT_ES6', '-sUSE_ES6_IMPORT_META=0']) - self.assertContained('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set', err) - @parameterized({ '': ([],), # load a worker before startup to check ES6 modules there as well diff --git a/tools/link.py b/tools/link.py index ba0d8007f6563..ca8d64620f6e8 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1432,11 +1432,11 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915 set_initial_memory() - if settings.EXPORT_ES6 and settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META: - # EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url - if 'USE_ES6_IMPORT_META' in user_settings: - exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set') - settings.USE_ES6_IMPORT_META = 1 + if settings.EXPORT_ES6 and not settings.MODULARIZE: + # EXPORT_ES6 requires output to be a module + if 'MODULARIZE' in user_settings: + exit_with_error('EXPORT_ES6 requires MODULARIZE to be set') + settings.MODULARIZE = 1 if settings.MODULARIZE and not settings.DECLARE_ASM_MODULE_EXPORTS: # When MODULARIZE option is used, currently requires declaring all module exports @@ -2065,7 +2065,7 @@ def phase_source_transforms(options): # both main code and libraries. # See also: `preprocess` in parseTools.js. def fix_es6_import_statements(js_file): - if not settings.EXPORT_ES6 or not settings.USE_ES6_IMPORT_META: + if not settings.EXPORT_ES6: return src = read_file(js_file) @@ -2415,7 +2415,7 @@ def modularize(): # In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module # webworker running in strict mode, so doesn't have access to 'document'. # In this case use 'import.meta' instead. - if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META: + if settings.EXPORT_ES6: script_url = 'import.meta.url' else: script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined" diff --git a/tools/settings.py b/tools/settings.py index 955ec23ad4e40..88a643bc8a7e9 100644 --- a/tools/settings.py +++ b/tools/settings.py @@ -68,7 +68,6 @@ 'HEADLESS', 'MODULARIZE', 'EXPORT_ES6', - 'USE_ES6_IMPORT_META', 'EXPORT_NAME', 'DYNAMIC_EXECUTION', 'PTHREAD_POOL_SIZE',