-
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: throw for duplicates in transfer list
Throw a `DataCloneError` exception when encountering duplicate `ArrayBuffer`s or `MessagePort`s in the transfer list. Fixes: #25786 PR-URL: #25815 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
test/parallel/test-worker-message-port-transfer-duplicate.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,29 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { MessageChannel } = require('worker_threads'); | ||
|
||
// Test that passing duplicate transferrables in the transfer list throws | ||
// DataCloneError exceptions. | ||
|
||
{ | ||
const { port1, port2 } = new MessageChannel(); | ||
port2.once('message', common.mustNotCall()); | ||
|
||
const port3 = new MessageChannel().port1; | ||
assert.throws(() => { | ||
port1.postMessage(port3, [port3, port3]); | ||
}, /^DataCloneError: Transfer list contains duplicate MessagePort$/); | ||
port1.close(); | ||
} | ||
|
||
{ | ||
const { port1, port2 } = new MessageChannel(); | ||
port2.once('message', common.mustNotCall()); | ||
|
||
const buf = new Uint8Array(10); | ||
assert.throws(() => { | ||
port1.postMessage(buf, [buf.buffer, buf.buffer]); | ||
}, /^DataCloneError: Transfer list contains duplicate ArrayBuffer$/); | ||
port1.close(); | ||
} |