mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

This aligns the behaviour better with the web. PR-URL: https://github.com/nodejs/node/pull/28025 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
38 lines
975 B
JavaScript
38 lines
975 B
JavaScript
// 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();
|
|
}
|