Skip to content

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

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

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>
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (54b4e37) to head (7e54b9a).
⚠️ Report is 251 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #65531   +/-   ##
=======================================
  Coverage   90.13%   90.13%           
=======================================
  Files         751      751           
  Lines      253635   253654   +19     
  Branches    47786    47798   +12     
=======================================
+ Hits       228615   228642   +27     
+ Misses      16268    16265    -3     
+ Partials     8752     8747    -5     
Files with missing lines Coverage Δ
lib/internal/worker/io.js 99.22% <100.00%> (+0.02%) ⬆️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@santusht06

Copy link
Copy Markdown
Author

Closing to focus on one PR at a time as per contributor guidelines. Will revisit after #65580 is merged.

@santusht06 santusht06 closed this Sep 6, 2026
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