Node: EventTarget - supporting "current event"

Created on 30 May 2020  路  2Comments  路  Source: nodejs/node

Hey,

Node is discussing experimentally adding EventTarget for its experimental AbortController implementation. One of the things the DOM specification has is something called "current event".

Basically a global is defined on window.event:

const et = new EventTarget();
et.addEventListener('foo', (e) => console.log(window.event)); // logs the Event instance
et.dispatchEvent(new Event('foo'))

This is part of the DOM API and a divergence from the spec. Since we are _only_ implementing EventTarget and not the whole DOM (or window), I think this is fine to not implement. The DOM specification also notes this is a legacy feature.

When I asked about this Domenic noted that it's fine to not implement as part of EventTarget as it's a part of a different API (like we're not implementing CustomEvent or MouseEvent).

The plan is currently:

  • Don't support window.event (or globalThis.event really) for event targets.
  • Don't port the WPTs that rely on window.event (if they test something else: port them to use the event argument).

It is not _hard_ to support technically (literally just setting a global before and deleting it after), but I would rather not support this feature if we can help it. Both because we can't correctly do so (no window) and because the feature exists mostly for inline event handlers (which we also don't support).

I wanted to ask for feedback regarding this plan and to see if anyone has any strong feelings one way or another.

doc events

Most helpful comment

+1 on not supporting it.

All 2 comments

+1 on not supporting it.

I think we can close this now as there's no one clamoring for us to support this. We can reopen the issue if it comes up again.

Was this page helpful?
0 / 5 - 0 ratings