From 5ea60a51fe8124730e49beff5be89b4df8263a17 Mon Sep 17 00:00:00 2001
From: Domenic Denicola An environment settings object also has an outstanding rejected promises weak set and
+ an about-to-be-notified rejected promises list, used in promise rejection
+ tracking. The outstanding rejected promises weak set must not create strong
+ references to any of its members, and implementations are free to limit its size, e.g. by
+ removing old entries from it when new ones are added. The relevant settings object for a global object o is the
environment settings object whose global object is o.
(There is always a 1:1 mapping of global objects to environment settings objects.)onpagehide
onpageshow
onpopstate
onrejectionhandled
onstorage
onunhandledrejection
onunload
In addition to synchronous runtime script errors, scripts
+ may experience asynchronous promise rejections, tracked via the unhandledrejection
and rejectionhandled
events.
When the user agent is required to notify about rejected promises on a given + environment settings object settings object, it must run these steps:
+ +Let list be a copy of settings object's about-to-be-notified + rejected promises list.
If list is empty, abort these steps.
Clear settings object's about-to-be-notified rejected promises + list.
Queue a task to run the following substeps for each promise p in + list:
+ +If p's [[PromiseIsHandled]] internal slot is true, continue to the next + iteration of the loop.
Let event be a new trusted
+ PromiseRejectionEvent
object that does not bubble but is cancelable, and which
+ has the event name unhandledrejection
.
Initialise event's promise
attribute to p.
Initialise event's reason
attribute to the value of
+ p's [[PromiseResult]] internal slot.
Dispatch event at settings object's global + object.
If the event was canceled, then the promise rejection is handled. Otherwise, the promise rejection is + not handled.
If p's [[PromiseIsHandled]] internal slot is false, add p to + settings object's outstanding rejected promises weak set. + +
This algorithm results in promise rejections being marked as handled or not handled. These concepts parallel + handled and not handled script errors.
+ +Implementations should use the handled/not handled state of promise rejections
+ when determining what to display in any debugging interfaces. That is, intercepting an
+ unhandledrejection
event and calling preventDefault()
should prevent
+ the corresponding rejection from showing up in any developer tools.
ECMAScript contains an implementation-defined HostPromiseRejectionTracker(promise, + realm, operation) abstract operation. User agents must + use the following implementation:
+ +Let settings object be the environment settings object of the + global object specified by realm's [[globalThis]] internal + slot.
If operation is "reject"
,
+
+
Add promise to settings object's about-to-be-notified + rejected promises list.
If operation is "handle"
,
+
+
If settings object's about-to-be-notified rejected promises + list contains promise, remove promise from that list and abort + these steps.
If settings object's outstanding rejected promises weak set + does not contain promise, abort these steps.
Remove promise from settings object's outstanding rejected + promises weak set.
Queue a task to run the following steps:
+ +Let event be a new trusted
+ PromiseRejectionEvent
object that does not bubble and is not cancelable, and
+ which has the event name rejectionhandled
.
Initialise event's promise
attribute to
+ promise.
Initialise event's reason
attribute to the value of
+ promise's [[PromiseResult]] internal slot.
Dispatch event at the global object specified by + realm's [[globalThis]] internal slot.
PromiseRejectionEvent
interface[Constructor(DOMString type, optional PromiseRejectionEventInit eventInitDict), Exposed=(Window,Worker)] +interface PromiseRejectionEvent : Event { + readonly attribute Promise<any>? promise; + readonly attribute any reason; +}; + +dictionary PromiseRejectionEventInit : EventInit { + required Promise<any>? promise; + any reason = null; +};+ +
The promise
attribute must
+ return the value it was initialised to. It represents the promise which this notification is about.
The reason
attribute must
+ return the value it was initialised to. It represents the rejection reason for the promise.
Remove the microtask run in the step above from the microtask queue, and return to the microtask queue handling step.
Done: Let the performing a microtask checkpoint flag be - false.
Done: For each environment settings object whose responsible + event loop is this event loop, notify about rejected promises + on that environment settings object.
Let the performing a microtask checkpoint flag be false.
onpagehide
pagehide
onpageshow
pageshow
onpopstate
popstate
+ onrejectionhandled
rejectionhandled
onstorage
storage
+ onunhandledrejection
unhandledrejection
onunload
unload
@@ -87460,7 +87626,9 @@ interface WindowEventHandlers {
attribute EventHandler onpagehide;
attribute EventHandler onpageshow;
attribute EventHandler onpopstate;
+ attribute EventHandler onrejectionhandled;
attribute EventHandler onstorage;
+ attribute EventHandler onunhandledrejection;
attribute EventHandler onunload;
};
@@ -94737,6 +94905,8 @@ interface WorkerGlobalScope : EventTarget {
attribute EventHandler onlanguagechange;
attribute EventHandler onoffline;
attribute EventHandler ononline;
+ attribute EventHandler onrejectionhandled;
+ attribute EventHandler onunhandledrejection;
};
A WorkerGlobalScope
object has an associated WorkerGlobalScope : EventTarget {
onlanguagechange
languagechange
onoffline
offline
ononline
online
+ onrejectionhandled
rejectionhandled
+ onunhandledrejection
unhandledrejection
onpagehide
;
onpageshow
;
onpopstate
;
+ onrejectionhandled
;
onstorage
;
+ onunhandledrejection
;
onunload
HTMLBodyElement
resize
event handler
onrejectionhandled
+ body
+ rejectionhandled
event handler for Window
object
+ onscroll
toggle
event handler
onunhandledrejection
+ body
+ unhandledrejection
event handler for Window
object
+ onunload
body
@@ -116863,6 +117049,12 @@ INSERT INTERFACES HERE
Document
Document
when it finishes parsing and again when all its subresources have finished loading
+ rejectionhandled
+ PromiseRejectionEvent
+ reset
Event
@@ -116905,6 +117097,12 @@ INSERT INTERFACES HERE
details
element
details
elements when they open or close
+ unhandledrejection
+ PromiseRejectionEvent
+ unload
Event
@@ -117221,7 +117419,7 @@ INSERT INTERFACES HERE