-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: use DataCloneError for unknown native objects
This aligns the behaviour better with the web. PR-URL: #28025 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
- Loading branch information
Showing
5 changed files
with
49 additions
and
9 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
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,37 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { MessageChannel } = require('worker_threads'); | ||
const { internalBinding } = require('internal/test/binding'); | ||
|
||
// Test that passing native objects and functions to .postMessage() throws | ||
// DataCloneError exceptions. | ||
|
||
{ | ||
const { port1, port2 } = new MessageChannel(); | ||
port2.once('message', common.mustNotCall()); | ||
|
||
assert.throws(() => { | ||
port1.postMessage(function foo() {}); | ||
}, { | ||
name: 'DataCloneError', | ||
message: /function foo\(\) \{\} could not be cloned\.$/ | ||
}); | ||
port1.close(); | ||
} | ||
|
||
{ | ||
const { port1, port2 } = new MessageChannel(); | ||
port2.once('message', common.mustNotCall()); | ||
|
||
const nativeObject = new (internalBinding('js_stream').JSStream)(); | ||
|
||
assert.throws(() => { | ||
port1.postMessage(nativeObject); | ||
}, { | ||
name: 'DataCloneError', | ||
message: /Cannot transfer object of unsupported type\.$/ | ||
}); | ||
port1.close(); | ||
} |