-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: make MessagePort constructor non-callable
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.
- Loading branch information
Showing
6 changed files
with
52 additions
and
30 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,27 @@ | ||
'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' | ||
}); |
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