Skip to content

Commit ca1d374

Browse files
authored
Enable wasm workers to run under node (#19322)
This means we can run the tests without depending on the browser.
1 parent 9eff02b commit ca1d374

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

src/library_wasm_worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ mergeInto(LibraryManager.library, {
139139
'sb': stackLowestAddress, // sb = stack bottom (lowest stack address, SP points at this when stack is full)
140140
'sz': stackSize, // sz = stack size
141141
});
142-
worker.addEventListener('message', __wasm_worker_runPostMessage);
142+
worker.onmessage = __wasm_worker_runPostMessage;
143143
return _wasm_workers_id++;
144144
},
145145

src/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ if (ENVIRONMENT_IS_NODE) {
263263

264264
Module['inspect'] = () => '[Emscripten Module object]';
265265

266-
#if PTHREADS
266+
#if PTHREADS || WASM_WORKERS
267267
let nodeWorkerThreads;
268268
try {
269269
nodeWorkerThreads = require('worker_threads');

test/code_size/hello_wasm_worker_wasm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ WebAssembly.instantiate(b.wasm, {
2828
sb: a,
2929
sz: d
3030
});
31-
r.addEventListener("message", n);
31+
r.onmessage = n;
3232
return k++;
3333
},
3434
c: function() {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 737,
33
"a.html.gz": 433,
4-
"a.js": 733,
5-
"a.js.gz": 463,
4+
"a.js": 715,
5+
"a.js.gz": 465,
66
"a.wasm": 1862,
77
"a.wasm.gz": 1040,
8-
"total": 3332,
9-
"total_gz": 1936
8+
"total": 3314,
9+
"total_gz": 1938
1010
}

test/test_core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9761,6 +9761,14 @@ def test_emscripten_async_load_script(self):
97619761
self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'file1.txt', 'file2.txt', '--from-emcc', '--js-output=script2.js'])
97629762
self.do_runf(test_file('test_emscripten_async_load_script.c'), emcc_args=['-sFORCE_FILESYSTEM'])
97639763

9764+
@node_pthreads
9765+
def test_wasm_worker_hello(self):
9766+
self.do_runf(test_file('wasm_worker/hello_wasm_worker.c'), emcc_args=['-sWASM_WORKERS'])
9767+
9768+
@node_pthreads
9769+
def test_wasm_worker_malloc(self):
9770+
self.do_runf(test_file('wasm_worker/malloc_wasm_worker.c'), emcc_args=['-sWASM_WORKERS'])
9771+
97649772

97659773
# Generate tests for everything
97669774
def make_run(name, emcc_args, settings=None, env=None,

0 commit comments

Comments
 (0)