The global object is an EventTarget and reports callback exceptions to its error event
Date: 2026-12-04
Area: runtime
Supersedes in part: ADR 0104's deviation on listener exceptions ("an
exception thrown by a listener propagates out of dispatchEvent"); ADR 0104's other decisions stand.
Refines: ADR 0214: a timer's or a queued
callback's exception goes to the global error event first, and is the run's uncaught error only when no listener
cancels it.
Related: Fetch — EventTarget,
Errors, #2596
Context
The global object was not an EventTarget: globalThis.addEventListener, removeEventListener and dispatchEvent
did not exist. In a worker and in a window the global scope is an EventTarget, and code written for them registers
listeners on it. web-platform-tests use it too: dom/events/EventTarget-removeEventListener.any.js calls
globalThis.removeEventListener, and html/webappapis/microtask-queuing/queue-microtask-exceptions.any.js listens to
the global error event for a queueMicrotask callback's exception.
ADR 0104 let a listener's exception propagate out of dispatchEvent, because GocciaScript had no global
error-reporting channel. The DOM Standard's "inner invoke" (§ 2.9) instead reports it with HTML's "report an
exception" (§ 8.1.4.6), which fires a cancelable ErrorEvent named error at the global object. HTML invokes timer
handlers and queueMicrotask callbacks with "report" the same way.
WinterTC's Minimum Common Web API (Ecma, 2025 snapshot), § 6 "The global scope", says a runtime's global object
should be an instance of EventTarget and that web-interoperable runtimes should follow "report an exception",
firing error on the global object; § 5 lists ErrorEvent, reportError() and onerror among the common surface.
An error no listener cancels is, in a browser, written to the developer console. GocciaScript decided in ADR 0214
that a timer's or a queued callback's exception fails the run outside a test runner, as Node and Bun do, and a test
runner fails the unit that scheduled it. Deno, which follows the same WinterTC section, reports the exception to the
global error event first and ends the process when no listener called preventDefault().
Decision
- The global object is an
EventTarget: it has anEventTarget's internal slots (one listener list for the realm) andEventTarget.prototypeis its[[Prototype]], soaddEventListener,removeEventListeneranddispatchEventwork on it, bare or throughglobalThis, andglobalThis instanceof EventTargetholds. ErrorEventis a runtime global, withmessage,filename,lineno,colnoanderror.- "Report an exception" fires a trusted, cancelable
ErrorEventnamederrorat the global object. Itserroris the exception; itsfilename,linenoandcolnocome from the first located frame of an error's stack; itsmessagereads as a browser's (Uncaught TypeError: …). An exception reported while one is being reported (a throwingerrorlistener) fires no second event, as HTML's error reporting mode has it. - The exceptions reported are those of an event listener (DOM inner invoke), a real timer's callback, a
queueMicrotaskcallback, andreportError(e)'s argument.onerroron the global object is HTML'sOnErrorEventHandler: it is called with(message, source, lineno, colno, error)and returningtruecancels the event. - An exception no listener cancels is the run's uncaught error, as Deno has it and as ADR 0214 decided: a timer's or a
queued callback's is thrown on where it was before; a listener's or
reportError's becomes one once the current job ends.dispatchEventandcontroller.abort()no longer throw on a listener's behalf. - Fake timers are unchanged: a fake timer's callback is not reported, and its exception is rethrown at the advance that ran it, as Vitest's is.
- Not covered here: a script's or module's own top-level exception stays the run's result, and the global object
fires no
unhandledrejectionorrejectionhandledevents; #2633 tracks the promise rejection events.
Consequences
- Code written for workers that registers
errorlisteners on the global scope runs unchanged, and can keep a callback's exception from failing the run by canceling the event. - The two known failures for #2596 in
tests/web-platform-tests/helpers/expectations.jsare removed. The web-platform-tests adapter cancels eacherrorevent after testharness.js has seen it, as a browser would only write it to its console.negative-setinterval,negative-settimeout,type-long-setintervalandtype-long-settimeoutinhtml/webappapis/timersstay left out for another reason: each is asingle_testthat the worker wrapper'sdone()completes before its timers run, so it would pass whatever the timers do. Object.prototype.toString.call(globalThis)is[object EventTarget], andglobalThis.constructorisEventTarget.