-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Use new URL(..., import.meta.url) pattern in minimal runtime if EXPORT_ES6 is enabled
#26039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,15 @@ var imports = { | |
| }; | ||
|
|
||
| #if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION | ||
| #if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET | ||
| var moduleUrl = new URL('{{{ TARGET_BASENAME }}}.wasm', import.meta.url); | ||
| #elif !EXPORT_ES6 || AUDIO_WORKLET | ||
| var moduleUrl = '{{{ TARGET_BASENAME }}}.wasm'; | ||
| #else | ||
| var moduleUrl = ENVIRONMENT_IS_AUDIO_WORKLET ? | ||
| '{{{ TARGET_BASENAME }}}.wasm' : | ||
| new URL('{{{ TARGET_BASENAME }}}.wasm', import.meta.url); | ||
| #endif | ||
| // https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming | ||
| #if MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE | ||
| #if ASSERTIONS && !WASM2JS | ||
|
|
@@ -197,13 +206,13 @@ instantiatePromise = | |
| // Node's fetch API cannot be used for local files, so we cannot use instantiateStreaming | ||
| && !ENVIRONMENT_IS_NODE | ||
| #endif | ||
| ? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports) | ||
| ? WebAssembly.instantiateStreaming(fetch(moduleUrl), imports) | ||
| : WebAssembly.instantiate(Module['wasm'], imports)).then((output) => { | ||
| #else | ||
| #if AUDIO_WORKLET | ||
| instantiatePromise = | ||
| #endif | ||
| WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => { | ||
| WebAssembly.instantiateStreaming(fetch(moduleUrl), imports).then((output) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use the same trick we use in i.e. do |
||
| #endif | ||
|
|
||
| #else // Non-streaming instantiation | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1702,6 +1702,18 @@ def test_minimal_runtime_errors(self): | |
| expected = 'emcc: error: MINIMAL_RUNTIME is not compatible with --preload-file' | ||
| self.assert_fail([EMCC, test_file('hello_world.c'), '-sMINIMAL_RUNTIME', '--preload-file', 'foo'], expected) | ||
|
|
||
| def test_minimal_runtime_esm_streaming_instantiation(self): | ||
valadaptive marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.run_process([EMCC, '-o', 'test.mjs', | ||
| '-sMINIMAL_RUNTIME', | ||
| '-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION', | ||
| '-sEXPORT_ES6', | ||
| '-sENVIRONMENT=web', | ||
| test_file('hello_world.c')]) | ||
|
|
||
| src = read_file('test.mjs') | ||
| # Verify that the generated code uses import.meta.url for the wasm URL | ||
| self.assertContained("new URL('test.wasm', import.meta.url)", src) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have IIUC we could add a variant of that test that uses |
||
|
|
||
| def test_export_all_and_exported_functions(self): | ||
| # EXPORT_ALL should not export library functions by default. | ||
| # This means that to export library function you also need to explicitly | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.