-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
In browsers, deno, bun, workers and other runtimes, globalThis implements the Web platform standard EventTarget API. While there are differences in the specific events emitted at the global scope, the unhandledrejection and rejectionhandled events are common to all of these runtimes. In Node.js our globalThis, of course, does not implement EventTarget and implements unhandled rejection events using EventEmitter instead. This ends up causing some interop headaches for library authors who have to special case handling of these events across runtimes.
We've discussed this before but I'd like to re-open the discussion for consideration around the questions:
- Should Node.js
globalThisimplementEventTarget - Should we emit the Web standard
unhandledrejectionandrejectionhandledevents onglobalThisand either (a) deprecate or (b) mark as legacy the equivalent events onprocess? - Should we support other Web standard events on
globalThisincluding:beforeunload(equivalent toprocess'beforeExitevent)error(equivalent toprocess'uncaughtExceptioneventloadmessage(equivalent toprocess'messageevent)messageerror- etc
@nodejs/tsc @nodejs/web-standards
Context: this came up in a WinterCG discussion around whether interoperable/consistent handling of unhandled errors and rejections should be covered by the WinterCG common minimum API spec.