blob: 6990e48e5cb801a90286eeb65d29448510179821 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 clone object of unsupported type\.$/
});
port1.close();
}
|