-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: do not crash when JSTransferable lists untransferable value
This can currently be triggered when posting a closing FileHandle. Refs: #34746 (comment) PR-URL: #34766 Backport-PR-URL: #34814 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
04defba
commit 03d6013
Showing
2 changed files
with
45 additions
and
5 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
38 changes: 38 additions & 0 deletions
38
test/parallel/test-worker-message-port-jstransferable-nested-untransferable.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,38 @@ | ||
// Flags: --expose-internals --no-warnings | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { | ||
JSTransferable, kTransfer, kTransferList | ||
} = require('internal/worker/js_transferable'); | ||
const { MessageChannel } = require('worker_threads'); | ||
|
||
// Transferring a JSTransferable that refers to another, untransferable, value | ||
// in its transfer list should not crash hard. | ||
|
||
class OuterTransferable extends JSTransferable { | ||
constructor() { | ||
super(); | ||
// Create a detached MessagePort at this.inner | ||
const c = new MessageChannel(); | ||
this.inner = c.port1; | ||
c.port2.postMessage(this.inner, [ this.inner ]); | ||
} | ||
|
||
[kTransferList] = common.mustCall(() => { | ||
return [ this.inner ]; | ||
}); | ||
|
||
[kTransfer] = common.mustCall(() => { | ||
return { | ||
data: { inner: this.inner }, | ||
deserializeInfo: 'does-not:matter' | ||
}; | ||
}); | ||
} | ||
|
||
const { port1 } = new MessageChannel(); | ||
const ot = new OuterTransferable(); | ||
assert.throws(() => { | ||
port1.postMessage(ot, [ot]); | ||
}, { name: 'DataCloneError' }); |