From cd908df27ff00a12353827c80701575f2cbfc02a Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Tue, 25 Aug 2026 15:02:46 +0500 Subject: [PATCH] worker: add Symbol.toStringTag to BroadcastChannel Signed-off-by: Lazizbek Ergashev PR-URL: https://github.com/nodejs/node/pull/65532 Fixes: https://github.com/nodejs/node/issues/65527 Reviewed-By: James M Snell --- lib/internal/worker/io.js | 11 +++++++++++ ...nel-string-tag.js => test-messaging-string-tag.js} | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) rename test/parallel/{test-messagechannel-string-tag.js => test-messaging-string-tag.js} (69%) 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();