Skip to content

fix(ext/web): make MessageEvent.ports a frozen array#34773

Merged
crowlKats merged 1 commit into
mainfrom
fix/messageevent-ports-frozen
Jun 3, 2026
Merged

fix(ext/web): make MessageEvent.ports a frozen array#34773
crowlKats merged 1 commit into
mainfrom
fix/messageevent-ports-frozen

Conversation

@crowlbot

@crowlbot crowlbot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What

MessageEvent.ports is specified as a FrozenArray<MessagePort>, so the
array exposed by the event must be read-only. The constructor assigned a
plain mutable array, so event.ports could be mutated — e.g.
event.ports.push(...) silently succeeded instead of throwing a
TypeError.

This freezes the array in both branches of the MessageEvent
constructor (empty and populated). Message delivery in
ext/web/13_message_port.js constructs the event via the same
constructor (new MessageEvent("message", { ports })), so delivered
events get a frozen ports array too.

Spec

HTML — the MessageEvent interface:
readonly attribute FrozenArray<MessagePort> ports;

WPT subtests now passing

webmessaging/Channel_postMessage_ports_readonly_array.any.html and
.any.worker.html:

  • The postMessage() method - Make new ports into a read only array.

tests/wpt/runner/expectations/webmessaging.json flipped from false to
true for both files.

Root cause

MessageEvent in ext/web/02_event.js stored this.ports as a plain
(non-frozen) array.

`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}.
@crowlbot

crowlbot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@crowlKats ready for review

The wpt job is green — webmessaging/Channel_postMessage_ports_readonly_array.any.{html,worker.html} now pass. The red test specs checks (macos/windows-aarch64) are the unrelated flaky Playwright "Failed to download Chromium" infra failures; I've re-run the failed jobs.

@crowlKats
crowlKats merged commit d325319 into main Jun 3, 2026
267 of 270 checks passed
@crowlKats
crowlKats deleted the fix/messageevent-ports-frozen branch June 3, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants