diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index f9dcd70da9a..cdca2d84884 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -211,12 +211,16 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, { ObjectDefineProperty(MessagePort.prototype, SymbolToStringTag, { __proto__: null, + writable: false, + enumerable: false, configurable: true, value: 'MessagePort', }); ObjectDefineProperty(MessageChannel.prototype, SymbolToStringTag, { __proto__: null, + writable: false, + enumerable: false, configurable: true, value: 'MessageChannel', }); @@ -474,6 +478,13 @@ class BroadcastChannel extends EventTarget { } ObjectDefineProperties(BroadcastChannel.prototype, { + [SymbolToStringTag]: { + __proto__: null, + writable: false, + enumerable: false, + configurable: true, + value: 'BroadcastChannel', + }, name: kEnumerableProperty, close: kEnumerableProperty, postMessage: kEnumerableProperty, diff --git a/test/parallel/test-messagechannel-string-tag.js b/test/parallel/test-messaging-string-tag.js similarity index 69% rename from test/parallel/test-messagechannel-string-tag.js rename to test/parallel/test-messaging-string-tag.js index d824f3e4ffc..77f9484ef55 100644 --- a/test/parallel/test-messagechannel-string-tag.js +++ b/test/parallel/test-messaging-string-tag.js @@ -4,7 +4,7 @@ require('../common'); const assert = require('assert'); -const classesToBeTested = [ MessageChannel, MessagePort ]; +const classesToBeTested = [ MessageChannel, MessagePort, BroadcastChannel ]; classesToBeTested.forEach((cls) => { assert.strictEqual(cls.prototype[Symbol.toStringTag], cls.name); @@ -15,3 +15,7 @@ classesToBeTested.forEach((cls) => { const channel = new MessageChannel(); assert.strictEqual(Object.prototype.toString.call(channel), '[object MessageChannel]'); assert.strictEqual(Object.prototype.toString.call(channel.port1), '[object MessagePort]'); + +const broadcastChannel = new BroadcastChannel('string-tag'); +assert.strictEqual(Object.prototype.toString.call(broadcastChannel), '[object BroadcastChannel]'); +broadcastChannel.close();