Skip to content

Commit cd908df

Browse files
lazergpanva
authored andcommitted
worker: add Symbol.toStringTag to BroadcastChannel
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com> PR-URL: #65532 Fixes: #65527 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b456adb commit cd908df

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎lib/internal/worker/io.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,16 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, {
211211

212212
ObjectDefineProperty(MessagePort.prototype, SymbolToStringTag, {
213213
__proto__: null,
214+
writable: false,
215+
enumerable: false,
214216
configurable: true,
215217
value: 'MessagePort',
216218
});
217219

218220
ObjectDefineProperty(MessageChannel.prototype, SymbolToStringTag, {
219221
__proto__: null,
222+
writable: false,
223+
enumerable: false,
220224
configurable: true,
221225
value: 'MessageChannel',
222226
});
@@ -474,6 +478,13 @@ class BroadcastChannel extends EventTarget {
474478
}
475479

476480
ObjectDefineProperties(BroadcastChannel.prototype, {
481+
[SymbolToStringTag]: {
482+
__proto__: null,
483+
writable: false,
484+
enumerable: false,
485+
configurable: true,
486+
value: 'BroadcastChannel',
487+
},
477488
name: kEnumerableProperty,
478489
close: kEnumerableProperty,
479490
postMessage: kEnumerableProperty,

test/parallel/test-messagechannel-string-tag.js renamed to test/parallel/test-messaging-string-tag.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require('../common');
44

55
const assert = require('assert');
66

7-
const classesToBeTested = [ MessageChannel, MessagePort ];
7+
const classesToBeTested = [ MessageChannel, MessagePort, BroadcastChannel ];
88

99
classesToBeTested.forEach((cls) => {
1010
assert.strictEqual(cls.prototype[Symbol.toStringTag], cls.name);
@@ -15,3 +15,7 @@ classesToBeTested.forEach((cls) => {
1515
const channel = new MessageChannel();
1616
assert.strictEqual(Object.prototype.toString.call(channel), '[object MessageChannel]');
1717
assert.strictEqual(Object.prototype.toString.call(channel.port1), '[object MessagePort]');
18+
19+
const broadcastChannel = new BroadcastChannel('string-tag');
20+
assert.strictEqual(Object.prototype.toString.call(broadcastChannel), '[object BroadcastChannel]');
21+
broadcastChannel.close();

0 commit comments

Comments
 (0)