-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: enable transferring WASM modules
Enable in-memory transfer of WASM modules without recompilation. Previously, the serialization step worked, but deserialization failed because we did not explicitly enable decoding inline WASM modules, and so the message was not successfully received. PR-URL: #25314 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
4 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Flags: --experimental-worker | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const { Worker } = require('worker_threads'); | ||
const wasmModule = new WebAssembly.Module(fixtures.readSync('test.wasm')); | ||
|
||
const worker = new Worker(` | ||
const { parentPort } = require('worker_threads'); | ||
parentPort.once('message', ({ wasmModule }) => { | ||
const instance = new WebAssembly.Instance(wasmModule); | ||
parentPort.postMessage(instance.exports.addTwo(10, 20)); | ||
}); | ||
`, { eval: true }); | ||
|
||
worker.once('message', common.mustCall((num) => assert.strictEqual(num, 30))); | ||
worker.postMessage({ wasmModule }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters