From 018cd7588bed749d3f17e23bbe50a86f18cb2a37 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 2 Oct 2015 15:32:58 -0400 Subject: [PATCH] Add HostPromiseRejectionTracker This is a non-observable change that will allow HTML to provide events for tracking promise rejections, as outlined in https://github.com/domenic/unhandled-rejections-browser-spec. For more information on the original proposal and use cases (mostly on the HTML side), see https://lists.w3.org/Archives/Public/public-whatwg-archive/2014Sep/0024.html. The corresponding HTML pull request is at https://github.com/whatwg/html/pull/224. --- spec.html | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/spec.html b/spec.html index a382c36d0a3..59fcd974051 100644 --- a/spec.html +++ b/spec.html @@ -35517,7 +35517,7 @@

IsPromise ( x )

-

RejectPromise ( promise, reason)

+

RejectPromise ( promise, reason )

When the RejectPromise abstract operation is called with arguments _promise_ and _reason_ the following steps are taken:

1. Assert: the value of _promise_'s [[PromiseState]] internal slot is `"pending"`. @@ -35526,6 +35526,7 @@

RejectPromise ( promise, reason)

1. Set the value of _promise_'s [[PromiseFulfillReactions]] internal slot to *undefined*. 1. Set the value of _promise_'s [[PromiseRejectReactions]] internal slot to *undefined*. 1. Set the value of _promise_'s [[PromiseState]] internal slot to `"rejected"`. + 1. If the value of _promise_'s [[PromiseIsHandled]] internal slot is *false*, perform HostPromiseRejectionTracker(_promise_, the current Realm, `"reject"`). 1. Return TriggerPromiseReactions(_reactions_, _reason_).
@@ -35540,6 +35541,29 @@

TriggerPromiseReactions ( reactions, argument )

1. Return *undefined*. + + +

HostPromiseRejectionTracker ( promise, realm, operation )

+ +

HostPromiseRejectionTracker is an implementation-defined abstract operation that allows host environments to track promise rejections.

+ +

An implementation of HostPromiseRejectionTracker must complete normally in all cases. The default implementation of HostPromiseRejectionTracker is to do nothing.

+ + +

HostPromiseRejectionTracker is called in two scenarios:

+ +
    +
  • When a promise is rejected without any handlers, it is called with its _operation_ argument set to `"reject"`.
  • +
  • When a handler is added to a rejected promise for the first time, it is called with its _operation_ argument set to `"handle"`.
  • +
+ +

A typical implementation of HostPromiseRejectionTracker might try to notify developers of unhandled rejections, while also being careful to notify them if such previous notifications are later invalidated by new handlers being attached.

+
+ + +

If _operation_ is `"handle"`, an implementation should not hold a reference to promise in a way that would interfere with garbage collection. An implementation may hold a reference to promise if operation is `"reject"`, since it is expected that rejections will be rare and not on hot code paths.

+
+
@@ -35601,6 +35625,7 @@

Promise ( executor )

1. Set _promise_'s [[PromiseState]] internal slot to `"pending"`. 1. Set _promise_'s [[PromiseFulfillReactions]] internal slot to a new empty List. 1. Set _promise_'s [[PromiseRejectReactions]] internal slot to a new empty List. + 1. Set _promise_'s [[PromiseIsHandled]] internal slot to *false*. 1. Let _resolvingFunctions_ be CreateResolvingFunctions(_promise_). 1. Let _completion_ be Call(_executor_, *undefined*, «_resolvingFunctions_.[[Resolve]], _resolvingFunctions_.[[Reject]]»). 1. If _completion_ is an abrupt completion, then @@ -35881,7 +35906,9 @@

PerformPromiseThen ( promise, onFulfilled, onRejected, resultCapability ) @@ -35942,6 +35969,14 @@

Properties of Promise Instances

A List of PromiseReaction records to be processed when/if the promise transitions from the `"pending"` state to the `"rejected"` state. + + + [[PromiseIsHandled]] + + + A boolean indicating whether the promise has ever had a fulfillment or rejection handler; used in unhandled rejection tracking. + +