Expand description
The WHATWG Event / EventTarget / CustomEvent globals — a port of
node’s lib/internal/event_target.js, restricted to what a non-DOM target
can observe (there is no tree, so there is no capture or bubble PATH: every
dispatch runs at the target, eventPhase is AT_TARGET while listeners
run and composedPath() is [target]).
AbortSignal is an EventTarget in node, and its abort listeners get a
real Event; fetch::abort_signal dispatches through dispatch so the
two share one listener list and one ordering rule.
Storage: a target keeps @@listeners, a hidden object mapping an event type
to an ARRAY of listener records. A record is a plain hidden object carrying
@@cb (the callback or handleEvent object), @@capture, @@once, and
@@handler — the latter marks the slot an on<type> event-handler
attribute occupies: node’s defineEventHandler registers that wrapper the
FIRST time the attribute is assigned and only swaps its callback afterwards,
which is why signal.onabort = f set before an addEventListener runs
first no matter how often it is reassigned. The wrapper reads the current
callback from the target’s @@on<type> slot at dispatch time.
Constants§
- CLASSES
- The classes this module constructs, as bare globals.
- EVENT_
ACCESSORS (name, settable)for everyEvent.prototypeaccessor.srcElement,returnValueandcancelBubbleare COMPUTED from other slots (seeinstance_call’s@get@arms); the rest read their own@@<name>slot.- EVENT_
LATE_ METHODS - EVENT_
METHODS Event.prototypemembers in node’s definition order are methods and accessors interleaved; the prototype builder lays out methods, then accessors, thenEVENT_LATE_METHODS, so the two method groups bracket the accessor block the way node’sinitEvent…preventDefaultandcomposedPath/stopPropagationdo.- EVENT_
TARGET_ METHODS
Functions§
- accessor_
written - An
Eventaccessor SETTER:cancelBubble = truthyisstopPropagation(),returnValue = falsyispreventDefault(). Neither stores the value. - add_
listener target.addEventListener(type, listener[, options]).- constant
- The
eventPhaseconstants, on the constructor (Event.AT_TARGET). - construct
- dispatch
target.dispatchEvent(event)— run the listeners forevent.typein registration order, then report whetherpreventDefault()was NOT called.- ensure_
handler_ slot - Install the event-handler attribute slot for
on<type>ontargetif this is the first assignment (defineEventHandler’s wrapper). The callback is read from@@on<type>at dispatch time, so a reassignment keeps the slot’s position in the listener order. - event_
target_ call - The three
EventTarget.prototypemethods.AbortSignalroutes here too. - instance_
call - is_
class - new_
listener_ map - A fresh, empty listener map for a target under construction.
- remove_
listener target.removeEventListener(type, listener[, options]).- rethrow
- The
@@rethrow:<idx>thunk body: raise the stored error. - unlisten
- The
@@evunlisten:<idx>thunk body: remove the listener the record at heap indexidxdescribes.