Skip to content

Commit 3960521

Browse files
committed
fixup! worker: enable transferring WASM modules
1 parent b94ad0f commit 3960521

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/parallel/test-worker-message-port-wasm-threads.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@ assert(buffer instanceof SharedArrayBuffer);
3232
// stopped when we exit.
3333
const worker = new Worker(`
3434
const { parentPort } = require('worker_threads');
35+
36+
// Compile the same WASM module from its source bytes.
3537
const wasmSource = new Uint8Array([${wasmSource.join(',')}]);
3638
const wasmModule = new WebAssembly.Module(wasmSource);
3739
const instance = new WebAssembly.Instance(wasmModule);
3840
parentPort.postMessage(instance.exports.memory);
41+
42+
// Do the same thing, except we receive the WASM module via transfer.
43+
parentPort.once('message', ({ wasmModule }) => {
44+
const instance = new WebAssembly.Instance(wasmModule);
45+
parentPort.postMessage(instance.exports.memory);
46+
});
3947
`, { eval: true });
40-
worker.once('message', common.mustCall(({ buffer }) => {
48+
worker.on('message', common.mustCall(({ buffer }) => {
4149
assert(buffer instanceof SharedArrayBuffer);
4250
worker.buf = buffer; // Basically just keep the reference to buffer alive.
43-
}));
51+
}, 2));
4452
worker.once('exit', common.mustCall());
4553
worker.postMessage({ wasmModule });
4654
}

0 commit comments

Comments
 (0)