Skip to content

worker: define Symbol.toStringTag on messaging prototypes - #65531

Open
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:fix-message-channel-string-tag
Open

worker: define Symbol.toStringTag on messaging prototypes#65531
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:fix-message-channel-string-tag

Conversation

@santusht06

@santusht06 santusht06 commented Aug 25, 2026

Copy link
Copy Markdown

Per the HTML and WebIDL specifications, interface prototypes must define @@toStringTag (Symbol.toStringTag) with the interface name as a configurable, non-writable, non-enumerable property.

In Node.js, MessageChannel, MessagePort, and BroadcastChannel prototypes lacked explicit Symbol.toStringTag definitions. This resulted in incorrect string representations:

  • Object.prototype.toString.call(new MessageChannel()) returned [object Object]
  • Object.prototype.toString.call(new MessageChannel().port1) returned [object EventTarget] (inherited from EventTarget.prototype)
  • Object.prototype.toString.call(new BroadcastChannel('foo')) returned [object EventTarget]

Changes

  • Defined [SymbolToStringTag] on MessagePort.prototype with { configurable: true, value: 'MessagePort' }.
  • Defined [SymbolToStringTag] on MessageChannel.prototype with { configurable: true, value: 'MessageChannel' }.
  • Defined [SymbolToStringTag] on BroadcastChannel.prototype with { configurable: true, value: 'BroadcastChannel' }.
  • Added test/parallel/test-worker-messaging-string-tag.js to test prototype property descriptors and toString tags for instances and globals.
  • Updated test/parallel/test-worker-message-port-inspect-during-init-hook.js and test/parallel/test-eventtarget-memoryleakwarning.js to reflect that inspect / warning output now formats as MessagePort instead of MessagePort [EventTarget].

Fixes: #65527

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API. labels Aug 25, 2026
Ensure compliance with the HTML and WebIDL specifications by defining
Symbol.toStringTag on MessageChannel.prototype, MessagePort.prototype,
and BroadcastChannel.prototype.

Fixes: nodejs#65527
Signed-off-by: Santusht kotai <115890693+santusht06@users.noreply.github.com>
@santusht06
santusht06 force-pushed the fix-message-channel-string-tag branch from 28dc74e to 7e54b9a Compare August 25, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Symbol.toStringTag on MessageChannel and MessagePort

2 participants