-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: fix passing multiple SharedArrayBuffers at once
V8 has a handle scope below each `GetSharedArrayBufferId()` call, so using a `v8::Local` that outlives that handle scope to store references to `SharedArrayBuffer`s is invalid and may cause accidental de-duplication of passed `SharedArrayBuffer`s. Use a persistent handle instead to address this issue. Fixes: #28559 PR-URL: #28582 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
2 changed files
with
24 additions
and
3 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
17 changes: 17 additions & 0 deletions
17
test/parallel/test-worker-message-port-multiple-sharedarraybuffers.js
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,17 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { MessageChannel } = require('worker_threads'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/28559 | ||
|
||
const obj = [ | ||
[ new SharedArrayBuffer(0), new SharedArrayBuffer(1) ], | ||
[ new SharedArrayBuffer(2), new SharedArrayBuffer(3) ] | ||
]; | ||
|
||
const { port1, port2 } = new MessageChannel(); | ||
port1.once('message', common.mustCall((message) => { | ||
assert.deepStrictEqual(message, obj); | ||
})); | ||
port2.postMessage(obj); |