Skip to content

Commit 90250aa

Browse files
authored
Ensure run dependencies are fulfilled before module promise resolves (#24768)
The existing code didn't take into account that async compilation is not the only source of async run dependencies. Without this change the test fails because the module promise is not used and the module is returned before its run dependencies have been fulfilled.
1 parent 27c3512 commit 90250aa

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/postamble_modularize.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// We assign to the `moduleRtn` global here and configure closure to see
55
// this as and extern so it won't get minified.
66

7-
#if WASM_ASYNC_COMPILATION
8-
97
#if USE_READY_PROMISE
108
if (runtimeInitialized) {
119
moduleRtn = Module;
@@ -20,12 +18,6 @@ if (runtimeInitialized) {
2018
moduleRtn = {};
2119
#endif
2220

23-
#else // WASM_ASYNC_COMPILATION
24-
25-
moduleRtn = Module;
26-
27-
#endif // WASM_ASYNC_COMPILATION
28-
2921
#if ASSERTIONS
3022
// Assertion for attempting to access module properties on the incoming
3123
// moduleArg. In the past we used this object as the prototype of the module

test/test_other.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,6 +7142,22 @@ def test_modularize_incoming(self, args):
71427142
output = self.run_js('run.mjs')
71437143
self.assertContained('done init\nhello, world!\ngot module\n', output)
71447144

7145+
def test_modularize_run_dependency(self):
7146+
# Ensure that dependencies are fulfilled before the module promise is resolved.
7147+
create_file('pre.js', '''
7148+
Module.preRun = () => { dbg("add-dep"); addRunDependency("my dep"); }
7149+
// Remove the run dependency in 100 milliseconds
7150+
setTimeout(() => { dbg("remove-dep"); removeRunDependency("my dep") }, 100);
7151+
''')
7152+
create_file('run.mjs', '''
7153+
import Module from './hello_world.mjs';
7154+
await Module();
7155+
console.log('got module');
7156+
''')
7157+
self.cflags += ['-sEXPORT_ES6', '-sMODULARIZE', '-sWASM_ASYNC_COMPILATION=0', '--pre-js=pre.js']
7158+
self.emcc(test_file('hello_world.c'), output_filename='hello_world.mjs')
7159+
self.assertContained('add-dep\nremove-dep\nhello, world!\ngot module\n', self.run_js('run.mjs'))
7160+
71457161
def test_modularize_instantiation_error(self):
71467162
self.run_process([EMCC, test_file('hello_world.c'), '-o', 'out.mjs'] + self.get_cflags())
71477163
create_file('run.mjs', '''

0 commit comments

Comments
 (0)