Skip to content

events,bootstrap: make globalThis extend EventTarget

This is probably a breaking change. I will add tests once the actual implementation's been approved just so I don't waste time writing tests for a feature that won't land 😄. Same with docs.

Changes:

  • Moves all EventTarget symbols to one symbol, to prevent exposing 4 symbols to globalThis.
  • Fallback to globalThis as the this value in EventTarget if this is null or undefined. This is needed to make the "floating" methods work (ie. addEventListener(...)). It's also a webidl thing, https://webidl.spec.whatwg.org/#dfn-create-operation-function
  • Adds 3 'globals', dispatchEvent, addEventListener, removeEventListener.
addEventListener('fetch', (event) => {
  console.log(event)
})

// somewhere else
dispatchEvent(new Event('fetch'))

Fixes: https://github.com/nodejs/node/issues/45981

Merge request reports

Loading