Skip to content

Commit 32f8202

Browse files
authored
Fix for MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION + ENVIRONMENT=web (#24863)
With `MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION` we know that we always get a only an instance back. The default case is unchanged: assume we get a pair of instance/module back. With pthreads we have to support both cases. Fixes: #24743
1 parent 7f17327 commit 32f8202

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/postamble_minimal.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ assert(Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm
136136

137137
{{{ exportJSSymbols() }}}
138138

139-
WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
139+
// Add missingProperties supression here because closure compiler doesn't know that
140+
// WebAssembly.instantiate is polymorphic in its return value.
141+
WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProperties} */ (output) => {
140142
#endif
141143

142144
#if !LibraryManager.has('libexports.js')
@@ -150,17 +152,16 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
150152
// output.module objects. But if Module['wasm'] is an already compiled
151153
// WebAssembly module, then output is the WebAssembly instance itself.
152154
// Depending on the build mode, Module['wasm'] can mean a different thing.
153-
#if MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION || MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION || PTHREADS
154-
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
155-
#if MIN_FIREFOX_VERSION < 58 || MIN_CHROME_VERSION < 61 || MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE || PTHREADS
155+
#if PTHREADS
156156
// In pthreads, Module['wasm'] is an already compiled WebAssembly.Module. In
157157
// that case, 'output' is a WebAssembly.Instance.
158158
// In main thread, Module['wasm'] is either a typed array or a fetch stream.
159159
// In that case, 'output.instance' is the WebAssembly.Instance.
160160
wasmExports = (output.instance || output).exports;
161-
#else
161+
#elif MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION
162+
// In MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION mode, Module['wasm'] is the
163+
// compiled module so we just get the instance back.
162164
wasmExports = output.exports;
163-
#endif
164165
#else
165166
wasmExports = output.instance.exports;
166167
#endif

test/test_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5045,8 +5045,8 @@ def test_minimal_runtime_loader_shell(self, args):
50455045
# Tests that -sMINIMAL_RUNTIME works well in different build modes
50465046
@parameterized({
50475047
'': ([],),
5048-
'streaming': (['-sMINIMAL_RUNTIME_STREAMING_WASM_COMPILATION', '--closure=1'],),
5049-
'streaming_inst': (['-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION', '--closure=1'],),
5048+
'streaming_compile': (['-sMINIMAL_RUNTIME_STREAMING_WASM_COMPILATION', '-sENVIRONMENT=web', '--closure=1'],),
5049+
'streaming_inst': (['-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION', '-sENVIRONMENT=web', '--closure=1'],),
50505050
})
50515051
def test_minimal_runtime_hello_world(self, args):
50525052
self.btest_exit('small_hello_world.c', cflags=args + ['-sMINIMAL_RUNTIME'])

0 commit comments

Comments
 (0)