Skip to content

Commit af94025

Browse files
committed
Use new URL pattern in minimal runtime
1 parent ee00f8a commit af94025

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/postamble_minimal.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ var imports = {
182182
};
183183

184184
#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
185+
#if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET
186+
var moduleUrl = new URL('{{{ TARGET_BASENAME }}}.wasm', import.meta.url);
187+
#elif !EXPORT_ES6 || AUDIO_WORKLET
188+
var moduleUrl = '{{{ TARGET_BASENAME }}}.wasm';
189+
#else
190+
var moduleUrl = ENVIRONMENT_IS_AUDIO_WORKLET ?
191+
'{{{ TARGET_BASENAME }}}.wasm' :
192+
new URL('{{{ TARGET_BASENAME }}}.wasm', import.meta.url);
193+
#endif
185194
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
186195
#if MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE
187196
#if ASSERTIONS && !WASM2JS
@@ -197,13 +206,13 @@ instantiatePromise =
197206
// Node's fetch API cannot be used for local files, so we cannot use instantiateStreaming
198207
&& !ENVIRONMENT_IS_NODE
199208
#endif
200-
? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports)
209+
? WebAssembly.instantiateStreaming(fetch(moduleUrl), imports)
201210
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
202211
#else
203212
#if AUDIO_WORKLET
204213
instantiatePromise =
205214
#endif
206-
WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => {
215+
WebAssembly.instantiateStreaming(fetch(moduleUrl), imports).then((output) => {
207216
#endif
208217

209218
#else // Non-streaming instantiation

test/test_other.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,19 @@ def test_minimal_runtime_errors(self):
17021702
expected = 'emcc: error: MINIMAL_RUNTIME is not compatible with --preload-file'
17031703
self.assert_fail([EMCC, test_file('hello_world.c'), '-sMINIMAL_RUNTIME', '--preload-file', 'foo'], expected)
17041704

1705+
def test_minimal_runtime_esm_streaming_instantiation(self):
1706+
os.mkdir('subdir')
1707+
self.run_process([EMCC, '-o', 'test.mjs',
1708+
'-sMINIMAL_RUNTIME',
1709+
'-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION',
1710+
'-sEXPORT_ES6',
1711+
'-sENVIRONMENT=web',
1712+
test_file('hello_world.c')])
1713+
1714+
src = read_file('test.mjs')
1715+
# Verify that the generated code uses import.meta.url for the wasm URL
1716+
self.assertContained("new URL('test.wasm', import.meta.url)", src)
1717+
17051718
def test_export_all_and_exported_functions(self):
17061719
# EXPORT_ALL should not export library functions by default.
17071720
# This means that to export library function you also need to explicitly

0 commit comments

Comments
 (0)