Skip to content

Commit 71ec929

Browse files
authored
Fix MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION under node. NFC (#24782)
We cannot actually use this API under node since the fetch API doesn't support local files. However, this failure was going undetected for two reason: 1. The test was only looking for the string 'hello' in the output which also appears in backtraces. 2. The instantiation error was being swallowed by a catch block that simply printed the error the console, so the node process was exiting with success.
1 parent 40782fe commit 71ec929

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/postamble_minimal.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ var imports = {
108108

109109
#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
110110
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
111-
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || MIN_NODE_VERSION < 180100 || MIN_SAFARI_VERSION < 150000
111+
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE
112112
#if ASSERTIONS && !WASM2JS
113113
// Module['wasm'] should contain a typed array of the Wasm object data, or a
114114
// precompiled WebAssembly Module.
115115
assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM');
116116
#endif
117117
(WebAssembly.instantiateStreaming
118+
#if ENVIRONMENT_MAY_BE_NODE
119+
// Node's fetch API cannot be used for local files, so we cannot use instantiateStreaming
120+
&& !ENVIRONMENT_IS_NODE
121+
#endif
118122
? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports)
119123
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
120124
#else
@@ -221,13 +225,12 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
221225
#endif
222226
}
223227

224-
#if ASSERTIONS || WASM == 2
228+
#if WASM == 2
225229
, (error) => {
226230
#if ASSERTIONS
227231
console.error(error);
228232
#endif
229233

230-
#if WASM == 2
231234
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
232235
if (typeof location != 'undefined') {
233236
#endif
@@ -239,9 +242,8 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
239242
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
240243
}
241244
#endif
242-
#endif // WASM == 2
243245
}
244-
#endif // ASSERTIONS || WASM == 2
246+
#endif // WASM == 2
245247
);
246248

247249
#if PTHREADS || WASM_WORKERS

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8805,7 +8805,7 @@ def test_minimal_runtime_hello_world(self, args):
88058805
self.cflags = args
88068806
self.set_setting('MINIMAL_RUNTIME')
88078807
self.maybe_closure()
8808-
self.do_runf('small_hello_world.c', 'hello')
8808+
self.do_runf('small_hello_world.c', 'hello!')
88098809

88108810
# Test that printf() works in MINIMAL_RUNTIME=1
88118811
@no_wasmfs('https://github.com/emscripten-core/emscripten/issues/16816')

0 commit comments

Comments
 (0)