mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
worker: add Symbol.toStringTag to MessageChannel and MessagePort
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65532 Fixes: https://github.com/nodejs/node/issues/65527 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
7ff62671a5
commit
b456adbcd6
4 files changed
+33
-3
No files matched your search
@@ -15,6 +15,7 @@ const {
|
||||
ReflectApply,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolToStringTag,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
@@ -208,6 +209,18 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, {
|
||||
},
|
||||
});
|
||||
|
||||
ObjectDefineProperty(MessagePort.prototype, SymbolToStringTag, {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: 'MessagePort',
|
||||
});
|
||||
|
||||
ObjectDefineProperty(MessageChannel.prototype, SymbolToStringTag, {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
value: 'MessageChannel',
|
||||
});
|
||||
|
||||
function setupPortReferencing(port, eventEmitter, eventName) {
|
||||
// Keep track of whether there are any workerMessage listeners:
|
||||
// If there are some, ref() the channel so it keeps the event loop alive.
|
||||
|
||||
@@ -15,12 +15,12 @@ common.expectWarning({
|
||||
'EventTarget. MaxListeners is 2. Use events.setMaxListeners() ' +
|
||||
'to increase limit'],
|
||||
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
|
||||
'[MessagePort [EventTarget]]. ' +
|
||||
'[MessagePort]. ' +
|
||||
'MaxListeners is 2. ' +
|
||||
'Use events.setMaxListeners() to increase ' +
|
||||
'limit'],
|
||||
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
|
||||
'[MessagePort [EventTarget]]. ' +
|
||||
'[MessagePort]. ' +
|
||||
'MaxListeners is 2. ' +
|
||||
'Use events.setMaxListeners() to increase ' +
|
||||
'limit'],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const classesToBeTested = [ MessageChannel, MessagePort ];
|
||||
|
||||
classesToBeTested.forEach((cls) => {
|
||||
assert.strictEqual(cls.prototype[Symbol.toStringTag], cls.name);
|
||||
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(cls.prototype, Symbol.toStringTag),
|
||||
{ configurable: true, enumerable: false, value: cls.name, writable: false });
|
||||
});
|
||||
|
||||
const channel = new MessageChannel();
|
||||
assert.strictEqual(Object.prototype.toString.call(channel), '[object MessageChannel]');
|
||||
assert.strictEqual(Object.prototype.toString.call(channel.port1), '[object MessagePort]');
|
||||
@@ -12,7 +12,7 @@ async_hooks.createHook({
|
||||
init: common.mustCall((id, type, triggerId, resource) => {
|
||||
assert.strictEqual(
|
||||
util.inspect(resource),
|
||||
'MessagePort [EventTarget] { active: true, refed: false }');
|
||||
'MessagePort { active: true, refed: false }');
|
||||
}, 2)
|
||||
}).enable();
|
||||
|
||||
|
||||
Reference in new issue
Block a user