Skip to content

fix: initialise MessageEvent instances in place - #6080

Open
blueDaydreaming725 wants to merge 1 commit into
nodejs:mainfrom
blueDaydreaming725:fix/init-message-event-in-place
Open

blueDaydreaming725 wants to merge 1 commit into
nodejs:mainfrom
blueDaydreaming725:fix/init-message-event-in-place

Conversation

@blueDaydreaming725

Copy link
Copy Markdown

This relates to...

The legacy MessageEvent initializer: https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-initmessageevent

Rationale

event.initMessageEvent('new-type', ..., data) currently constructs and returns a different event. Callers using its declared void return contract keep the original event, whose type and data never change.

Changes

Reuse the existing Web IDL converters to convert arguments in positional order, then use Node's native initEvent() and update the current MessageEvent's fields. Return undefined. During dispatch, convert the arguments but leave the event unchanged. Copy ports through the existing sequence converter rather than freezing the caller's array.

Features

N/A

Bug Fixes

Initialisation now updates the same event. Omitted fields reset to their defaults, and conversion failures leave the event unchanged.

Breaking Changes and Deprecations

Code relying on the previous, non-standard return of a new MessageEvent must use the original instance instead. The declaration already specifies a void return.

Status

  • I have read and agreed to the Developer's Certificate of Origin
  • Tested: four regression cases failed before the fix; all 181 WebSocket tests and 153 EventSource tests passed, along with lint. Tests cover argument order, dispatch-time calls, failed conversions, defaults and port-array ownership.
  • Benchmarked (optional)
  • Documented: existing void declaration remains accurate
  • Review ready
  • In review
  • Merge ready

Full JavaScript/WPT suites and other Node versions were not run. Base Event initialisation is delegated to Node's existing implementation; this does not change its handling of event flags.

Implemented, tested and reviewed with OpenAI Codex assistance.

This branch has not been deployed

No deployments
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.

1 participant