Skip to content

Commit e15b12e

Browse files
committed
Error and promise rejection events must be fired on the global object
As decided in today's meeting, this PR specifies that the `error`, `unhandledrejection` and `rejectionhandled` events are fired on the global object. It also adds the `ErrorEvent` and `PromiseRejectionEvent` interfaces, and the `onerror`, `onunhandledrejection` and `onrejectionhandled` event handler properties, to the minimum common API list. This PR also has a note covering the likely case that Node.js will not support this due to legacy.
1 parent d0f9079 commit e15b12e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

index.bs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Interfaces:
4848
* {{CryptoKey}}
4949
* <code class="idl"><a data-link-type="idl" href="https://wicg.github.io/compression/#decompression-stream">DecompressionStream</a></code>
5050
* {{DOMException}}
51+
* {{ErrorEvent}}
5152
* {{Event}}
5253
* {{EventTarget}}
5354
* {{File}}
@@ -59,6 +60,7 @@ Interfaces:
5960
Cloudflare Workers ignores all parameters.
6061

6162
* {{Headers}}
63+
* {{PromiseRejectionEvent}}
6264
* {{ReadableByteStreamController}}
6365
* {{ReadableStream}}
6466
* {{ReadableStreamBYOBReader}}
@@ -95,6 +97,9 @@ Global methods / properties:
9597
* globalThis.{{crypto}}
9698
* globalThis.{{fetch()}}
9799
* globalThis.{{navigator}}.{{userAgent}}
100+
* globalThis.onerror (on {{GlobalEventHandlers/onerror|Window}} and {{WorkerGlobalScope/onerror|WorkerGlobalScope}})
101+
* globalThis.onunhandledrejection (on {{WindowEventHandlers/onunhandledrejection|Window}} and {{WorkerGlobalScope/onunhandledrejection|WorkerGlobalScope}})
102+
* globalThis.onrejectionhandled (on {{WindowEventHandlers/onrejectionhandled|Window}} and {{WorkerGlobalScope/onrejectionhandled|WorkerGlobalScope}})
98103
* globalThis.{{performance}}.{{Performance/now()}}
99104
* globalThis.{{performance}}.{{timeOrigin}}
100105
* globalThis.{{queueMicrotask()}}
@@ -114,6 +119,12 @@ The exact type of the global scope (`globalThis`) can vary across runtimes. Most
114119

115120
With many runtimes, adding a new global-scoped property can introduce breaking changes when the new global conflicts with existing application code. Many Web Platform APIs define global properties using the `readonly` attribute. To avoid introducing breaking changes, runtimes conforming to this specification MAY choose to ignore the `readonly` attribute for properties being added to the global scope.
116121

122+
The global object on {{Window}}-like and worker environments must always be an instance of {{EventTarget}}. Web-interoperable runtimes must follow the <a>report an exception</a> algorithm, and the JavaScript <a href="https://tc39.es/ecma262/#sec-host-promise-rejection-tracker">HostPromiseRejectionTracker</a> host hook, as defined in [[HTML]]. This includes firing the {{Window/error}}, {{Window/unhandledrejection}} and {{Window/rejectionhandled}} events on the global object.
123+
124+
Note: Some runtimes might not support firing those events following the HTML specification exactly due to legacy reasons.
125+
For example, in Node.js the global object does not implement {{EventTarget}}, and the relevant events are fired on the `process` object with the names `uncaughtException`, `unhandledRejection` and `rejectionHandled`, respectively.
126+
Such runtimes should not support the {{GlobalEventHandlers/onerror}}, {{WindowEventHandlers/onunhandledrejection}} and {{WindowEventHandlers/onrejectionhandled}} global properties, but they might implement the {{ErrorEvent}} and {{PromiseRejectionEvent}} interfaces.
127+
117128
Requirements for navigator.userAgent {#navigator-useragent-requirements}
118129
========================================================================
119130

0 commit comments

Comments
 (0)