mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 13:28:42 +00:00

Refactor the C++ code for creating `MessagePort`s to skip calling the constructor and instead directly instantiating the `InstanceTemplate`, and always throw an error from the `MessagePort` constructor. This aligns behaviour with the web, and creating single `MessagePort`s does not make sense anyway. PR-URL: https://github.com/nodejs/node/pull/28032 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
28 lines
692 B
JavaScript
28 lines
692 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { MessageChannel, MessagePort } = require('worker_threads');
|
|
|
|
// Make sure that `MessagePort` is the constructor for MessagePort instances,
|
|
// but not callable.
|
|
const { port1 } = new MessageChannel();
|
|
|
|
assert(port1 instanceof MessagePort);
|
|
assert.strictEqual(port1.constructor, MessagePort);
|
|
|
|
assert.throws(() => MessagePort(), {
|
|
constructor: TypeError,
|
|
code: 'ERR_CONSTRUCT_CALL_INVALID'
|
|
});
|
|
|
|
assert.throws(() => new MessagePort(), {
|
|
constructor: TypeError,
|
|
code: 'ERR_CONSTRUCT_CALL_INVALID'
|
|
});
|
|
|
|
assert.throws(() => MessageChannel(), {
|
|
constructor: TypeError,
|
|
code: 'ERR_CONSTRUCT_CALL_REQUIRED'
|
|
});
|