Skip to main content

Module event_target

Module event_target 

Source
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 every Event.prototype accessor. srcElement, returnValue and cancelBubble are COMPUTED from other slots (see instance_call’s @get@ arms); the rest read their own @@<name> slot.
EVENT_LATE_METHODS
EVENT_METHODS
Event.prototype members in node’s definition order are methods and accessors interleaved; the prototype builder lays out methods, then accessors, then EVENT_LATE_METHODS, so the two method groups bracket the accessor block the way node’s initEvent…preventDefault and composedPath/stopPropagation do.
EVENT_TARGET_METHODS

Functions§

accessor_written
An Event accessor SETTER: cancelBubble = truthy is stopPropagation(), returnValue = falsy is preventDefault(). Neither stores the value.
add_listener
target.addEventListener(type, listener[, options]).
constant
The eventPhase constants, on the constructor (Event.AT_TARGET).
construct
dispatch
target.dispatchEvent(event) — run the listeners for event.type in registration order, then report whether preventDefault() was NOT called.
ensure_handler_slot
Install the event-handler attribute slot for on<type> on target if 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.prototype methods. AbortSignal routes 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 index idx describes.