diff --git a/spec.html b/spec.html index 9ffbca2..f2cc541 100644 --- a/spec.html +++ b/spec.html @@ -318,9 +318,94 @@

-

Control Abstraction Objects

+ + +

Promise Objects

+ + +

Promise Jobs

+ + +

+ NewPromiseReactionJob ( + _reaction_: a PromiseReaction Record, + _argument_: an ECMAScript language value, + ): a Record with fields [[Job]] (a Job Abstract Closure) and [[Realm]] (a Realm Record or *null*) +

+
+
description
+
It returns a new Job Abstract Closure that applies the appropriate handler to the incoming value, and uses the handler's return value to resolve or reject the derived promise associated with that handler.
+
+ + 1. Let _job_ be a new Job Abstract Closure with no parameters that captures _reaction_ and _argument_ and performs the following steps when called: + 1. Let _promiseCapability_ be _reaction_.[[Capability]]. + 1. Let _type_ be _reaction_.[[Type]]. + 1. Let _handler_ be _reaction_.[[Handler]]. + 1. If _handler_ is ~empty~, then + 1. If _type_ is ~Fulfill~, let _handlerResult_ be NormalCompletion(_argument_). + 1. Else, + 1. Assert: _type_ is ~Reject~. + 1. Let _handlerResult_ be ThrowCompletion(_argument_). + 1. Else, let _handlerResult_ be Completion(HostCallJobCallback(_handler_, *undefined*, « _argument_ »)). + 1. If _promiseCapability_ is *undefined*, then + 1. Assert: _handlerResult_ is not an abrupt completion. + 1. Return ~empty~. + 1. Assert: _promiseCapability_ is a PromiseCapability Record. + 1. If _handlerResult_ is an abrupt completion, then + 1. Return ? Call(_promiseCapability_.[[Reject]], *undefined*, « _handlerResult_.[[Value]] »). + 1. Let _previousContextMapping_ be AsyncContextSwap(_handler_.[[AsyncContextSnapshot]]). + 1. Let _rejectResult_ be Completion(Call(_promiseCapability_.[[Reject]], *undefined*, « _handlerResult_.[[Value]] »)). + 1. AsyncContextSwap(_previousContextMapping_). + 1. Return _rejectResult_. + 1. Else, + 1. Return ? Call(_promiseCapability_.[[Resolve]], *undefined*, « _handlerResult_.[[Value]] »). + 1. Let _handlerRealm_ be *null*. + 1. If _reaction_.[[Handler]] is not ~empty~, then + 1. Let _getHandlerRealmResult_ be Completion(GetFunctionRealm(_reaction_.[[Handler]].[[Callback]])). + 1. If _getHandlerRealmResult_ is a normal completion, set _handlerRealm_ to _getHandlerRealmResult_.[[Value]]. + 1. Else, set _handlerRealm_ to the current Realm Record. + 1. NOTE: _handlerRealm_ is never *null* unless the handler is *undefined*. When the handler is a revoked Proxy and no ECMAScript code runs, _handlerRealm_ is used to create error objects. + 1. Return the Record { [[Job]]: _job_, [[Realm]]: _handlerRealm_ }. + +
+ + +

+ NewPromiseResolveThenableJob ( + _promiseToResolve_: a Promise, + _thenable_: an Object, + _then_: a JobCallback Record, + ): a Record with fields [[Job]] (a Job Abstract Closure) and [[Realm]] (a Realm Record) +

+
+
+ + 1. Let _job_ be a new Job Abstract Closure with no parameters that captures _promiseToResolve_, _thenable_, and _then_ and performs the following steps when called: + 1. Let _resolvingFunctions_ be CreateResolvingFunctions(_promiseToResolve_). + 1. Let _thenCallResult_ be Completion(HostCallJobCallback(_then_, _thenable_, « _resolvingFunctions_.[[Resolve]], _resolvingFunctions_.[[Reject]] »)). + 1. If _thenCallResult_ is an abrupt completion, then + 1. Return ? Call(_resolvingFunctions_.[[Reject]], *undefined*, « _thenCallResult_.[[Value]] »). + 1. Let _previousContextMapping_ be AsyncContextSwap(_then_.[[AsyncContextSnapshot]]). + 1. Let _rejectResult_ be Completion(Call(_resolvingFunctions_.[[Reject]], *undefined*, « _thenCallResult_.[[Value]] »)). + 1. AsyncContextSwap(_previousContextMapping_). + 1. Return _rejectResult_. + 1. Return ? _thenCallResult_. + 1. Let _getThenRealmResult_ be Completion(GetFunctionRealm(_then_.[[Callback]])). + 1. If _getThenRealmResult_ is a normal completion, let _thenRealm_ be _getThenRealmResult_.[[Value]]. + 1. Else, let _thenRealm_ be the current Realm Record. + 1. NOTE: _thenRealm_ is never *null*. When _then_.[[Callback]] is a revoked Proxy and no code runs, _thenRealm_ is used to create error objects. + 1. Return the Record { [[Job]]: _job_, [[Realm]]: _thenRealm_ }. + + +

This Job uses the supplied thenable and its `then` method to resolve the given promise. This process must take place as a Job to ensure that the evaluation of the `then` method occurs after evaluation of any surrounding code has completed.

+
+
+
+
+ +

AsyncContext Objects

@@ -500,6 +585,6 @@

Properties of AsyncContext Instances

+
-