[whatwg/dom] Should event dispatch check that the event target is in a fully active realm? (Issue #1084)

I can't find in the DOM or WebIDL specs where such a check exists; apologies if I missed it.

The scenario is ([jsfiddle](https://jsfiddle.net/shaseley/up7c48va/6/)):
- A page has an iframe
- The iframe creates a new AbortController (`controller`) in its realm and hangs it off of its parent
- The parent page adds an event listener (added and defined in its realm) to `controller.signal`
- The iframe gets removed
- `controller.abort()` is called in the parent page's context

Should the event handler run?

This is similar to https://github.com/whatwg/webidl/issues/993, but it's the event target that is in a "detached realm", not the event listener or call to `controller.abort()`.

All the engines are consistent though — no one runs the event listener:
 - Blink and WebKit both early out in ~2.10 of [inner invoke](https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke). 
   -  For Blink specifically, we can't create the JS wrapper for the event because the [context is gone](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/bindings/core/v8/js_based_event_listener.cc;l=103;drc=8d6a246c9be4f6b731dc7f6e680b7d5e13a512b5;bpv=0;bpt=1).
 - Gecko skips handling the event during [EventTargetChainItem::HandleEvent](https://searchfox.org/mozilla-central/source/dom/events/EventDispatcher.cpp#318)() because the EventListenerManager is null (IIUC it got cleared during detach). I think this is during targeting, just prior to starting [inner invoke](https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke).

I was a bit surprised by the behavior, but given that no engine is running these, would it make sense to add an explicit check (assuming I didn't miss it) so the spec is in sync, and if so, thoughts on where?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1084
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1084@github.com>

Received on Friday, 3 June 2022 20:52:46 UTC