Repository navigation
Call EventSource and MessagePort event handlers with the target as this - #8816
Conversation
There was a problem hiding this comment.
Superseded by the review of
9cebbd78.
This review, of 0413d51d
✅ Approved — The change is small and correct, it only applies under set_event_target_this, and tests cover it. No findings.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only affects the this of event handlers. It touches no trust boundary, input handling, secrets or authorization.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 0413d51d
The TypeScript EventSource and MessagePort set their onopen, onmessage and onerror handlers through EventTarget's C++ event handler attribute, whose trampoline calls the handler with the global object as `this`. addEventListener() listeners get the target under set_event_target_this, and HTML calls an event handler with the event's currentTarget as `this`. Nine eventsource WPT files call this.close() from an onX handler and were expected to fail. In this patch the event-target-internals seam passes C++ a trampoline that calls the handler with the target as `this` when set_event_target_this is on, and maps the trampoline back to the handler for the getter. Without the flag nothing changes. Code that relied on `this` being the global object inside a function-style handler on these two classes now sees the target; we accept that without a new flag, since set_event_target_this already covers the `this` of event handlers. The nine WPT files pass now. request-cache-control.any.js was disabled for the same reason; only its cross-origin pair stays disabled, because fetch() sends no Origin header and cors.py fails with a 500.
0413d51 to
9cebbd7
Compare
There was a problem hiding this comment.
Superseded by the review of
80f4bcb7.
This review, of 9cebbd78
✅ Approved — The change is small and correct, it only applies under set_event_target_this, and tests cover both flag states. No findings.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only affects the this of event handlers. It touches no trust boundary, input handling, secrets or authorization.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The trampoline and getter mapping are correct. Behaviour without the flag is unchanged, and the tests branch on setEventTargetThis, so they pass with the flag on or off.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 9cebbd78
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8816 +/- ##
=======================================
Coverage 67.75% 67.75%
=======================================
Files 846 846
Lines 214951 214951
Branches 32584 32584
=======================================
Hits 145633 145633
Misses 50077 50077
Partials 19241 19241 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
✅ Approved — The change is small and correct, it only applies under set_event_target_this, and tests cover both flag states. No findings.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The change only affects the this of event handlers. It touches no trust boundary, input handling, secrets or authorization.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The trampoline and getter mapping are correct. Behaviour without the flag is unchanged, and the tests branch on setEventTargetThis, so they pass with the flag on or off.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 80f4bcb7 — same changes as 9cebbd78, so this is that commit's review (no new review was run; line numbers are as of 9cebbd78)
The TypeScript EventSource and MessagePort set
onopen,onmessageandonerrorthrough EventTarget's C++ event handler attribute, whose trampoline calls the handler with the global object asthis.addEventListener()listeners already get the target underset_event_target_this, and HTML calls an event handler with the event'scurrentTargetasthis. Nine eventsource WPT files callthis.close()from anonXhandler, so they were expected to fail.In this patch the event-target-internals seam passes C++ a trampoline that calls the handler with the target as
thiswhenset_event_target_thisis on. The getter maps the trampoline back to the handler, so it still returns the value assigned. Without the flag nothing changes. Code that relied onthisbeing the global object inside afunctionhandler on these two classes now sees the target. We accept that without a new flag, becauseset_event_target_thisalready covers thethisof event handlers. The newhandlerReceivercase and the updatedonmessageHandlerReceivercase fail without the change.The nine WPT files now pass.
request-cache-control.any.jswas disabled for the same reason. Only its cross-origin pair stays disabled, becausefetch()sends no Origin header andcors.pyfails with a 500.//src/wpt:eventsource@and//src/wpt:eventsource@all-autogateseach passed 100 of 100 runs with--runs_per_test=100. The eventsource, messagechannel, events, abort and websocket tests and the dom/events, dom/abort, websockets and webmessaging WPTs pass.