fix(ext/web): make MessageEvent.ports a frozen array#34773
Merged
Conversation
`MessageEvent.ports` is a `FrozenArray<MessagePort>` per the HTML spec,
so the exposed array must be read-only. The constructor assigned a plain
mutable array, so user code could mutate it (e.g. `event.ports.push(...)`
silently succeeded instead of throwing). Freeze the array in both the
empty and populated branches; message delivery in 13_message_port.js
goes through this same constructor, so delivered events get a frozen
ports array too.
Fixes WPT webmessaging/Channel_postMessage_ports_readonly_array.any.{html,worker.html}.
Contributor
Author
|
@crowlKats ready for review The wpt job is green — |
crowlKats
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MessageEvent.portsis specified as aFrozenArray<MessagePort>, so thearray exposed by the event must be read-only. The constructor assigned a
plain mutable array, so
event.portscould be mutated — e.g.event.ports.push(...)silently succeeded instead of throwing aTypeError.This freezes the array in both branches of the
MessageEventconstructor (empty and populated). Message delivery in
ext/web/13_message_port.jsconstructs the event via the sameconstructor (
new MessageEvent("message", { ports })), so deliveredevents get a frozen
portsarray too.Spec
HTML — the MessageEvent interface:
readonly attribute FrozenArray<MessagePort> ports;WPT subtests now passing
webmessaging/Channel_postMessage_ports_readonly_array.any.htmland.any.worker.html:tests/wpt/runner/expectations/webmessaging.jsonflipped fromfalsetotruefor both files.Root cause
MessageEventinext/web/02_event.jsstoredthis.portsas a plain(non-frozen) array.