From f3637934640dc43ebf505bbda83786b0ba1a471b Mon Sep 17 00:00:00 2001 From: Maya Lekova Date: Fri, 8 Jun 2018 09:00:53 +0200 Subject: [PATCH] Normative: Improve consistency in async-related algorithms Used the PromiseResolve primitive instead of creating a promise capability for the following clauses: 6.2.3.1 Await 25.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next 25.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return 25.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw 25.5.3.5 AsyncGeneratorResumeNext to make them consistent with: 25.6.5.3.1 Then Finally Functions 25.6.5.3.2 Catch Finally Functions --- spec.html | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/spec.html b/spec.html index e5481e346bc..970fe8216d4 100644 --- a/spec.html +++ b/spec.html @@ -3045,15 +3045,14 @@

Await

Algorithm steps that say

- 1. Let _completion_ be Await(_promise_). + 1. Let _completion_ be Await(_value_).

mean the same thing as:

1. Let _asyncContext_ be the running execution context. - 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _promise_ »). + 1. Let _promise_ be ? PromiseResolve(« _value_ »). 1. Let _stepsFulfilled_ be the algorithm steps defined in . 1. Let _onFulfilled_ be CreateBuiltinFunction(_stepsFulfilled_, « [[AsyncContext]] »). 1. Set _onFulfilled_.[[AsyncContext]] to _asyncContext_. @@ -3062,7 +3061,7 @@

Await

1. Set _onRejected_.[[AsyncContext]] to _asyncContext_. 1. Let _throwawayCapability_ be ! NewPromiseCapability(%Promise%). 1. Set _throwawayCapability_.[[Promise]].[[PromiseIsHandled]] to *true*. - 1. Perform ! PerformPromiseThen(_promiseCapability_.[[Promise]], _onFulfilled_, _onRejected_, _throwawayCapability_). + 1. Perform ! PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_, _throwawayCapability_). 1. Remove _asyncContext_ from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context. 1. Set the code evaluation state of _asyncContext_ such that when evaluation is resumed with a Completion _completion_, the following steps of the algorithm that invoked Await will be performed, with _completion_ available.
@@ -3073,14 +3072,14 @@

Await

Await can be combined with the `?` and `!` prefixes, so that for example

- 1. Let _value_ be ? Await(_promise_). + 1. Let _result_ be ? Await(_value_).

means the same thing as:

- 1. Let _value_ be Await(_promise_). - 1. ReturnIfAbrupt(_value_). + 1. Let _result_ be Await(_value_). + 1. ReturnIfAbrupt(_result_). @@ -37908,12 +37907,11 @@

%AsyncFromSyncIteratorPrototype%.next ( _value_ )

1. IfAbruptRejectPromise(_nextDone_, _promiseCapability_). 1. Let _nextValue_ be IteratorValue(_nextResult_). 1. IfAbruptRejectPromise(_nextValue_, _promiseCapability_). - 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _nextValue_ »). + 1. Let _valueWrapper_ be ? PromiseResolve(« _nextValue_ »). 1. Let _steps_ be the algorithm steps defined in . 1. Let _onFulfilled_ be CreateBuiltinFunction(_steps_, « [[Done]] »). 1. Set _onFulfilled_.[[Done]] to _nextDone_. - 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Perform ! PerformPromiseThen(_valueWrapper_, _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -37944,12 +37942,11 @@

%AsyncFromSyncIteratorPrototype%.return ( _value_ )

1. IfAbruptRejectPromise(_returnDone_, _promiseCapability_). 1. Let _returnValue_ be IteratorValue(_returnResult_). 1. IfAbruptRejectPromise(_returnValue_, _promiseCapability_). - 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _returnValue_ »). + 1. Let _valueWrapper_ be ? PromiseResolve(« _returnValue_ »). 1. Let _steps_ be the algorithm steps defined in . 1. Let _onFulfilled_ be CreateBuiltinFunction(_steps_, « [[Done]] »). 1. Set _onFulfilled_.[[Done]] to _returnDone_. - 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Perform ! PerformPromiseThen(_valueWrapper_, _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -37979,12 +37976,11 @@

%AsyncFromSyncIteratorPrototype%.throw ( _value_ )

1. IfAbruptRejectPromise(_throwDone_, _promiseCapability_). 1. Let _throwValue_ be IteratorValue(_throwResult_). 1. IfAbruptRejectPromise(_throwValue_, _promiseCapability_). - 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _throwValue_ »). + 1. Let _valueWrapper_ be ? PromiseResolve(« _throwValue_ »). 1. Let _steps_ be the algorithm steps defined in . 1. Let _onFulfilled_ be CreateBuiltinFunction(_steps_, « [[Done]] »). 1. Set _onFulfilled_.[[Done]] to _throwDone_. - 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Perform ! PerformPromiseThen(_valueWrapper_, _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -38687,8 +38683,7 @@

AsyncGeneratorResumeNext ( _generator_ )

1. If _state_ is `"completed"`, then 1. If _completion_.[[Type]] is ~return~, then 1. Set _generator_.[[AsyncGeneratorState]] to `"awaiting-return"`. - 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _completion_.[[Value]] »). + 1. Let _promise_ be ? PromiseResolve(« _completion_.[[Value]] »). 1. Let _stepsFulfilled_ be the algorithm steps defined in . 1. Let _onFulfilled_ be CreateBuiltinFunction(_stepsFulfilled_, « [[Generator]] »). 1. Set _onFulfilled_.[[Generator]] to _generator_. @@ -38697,7 +38692,7 @@

AsyncGeneratorResumeNext ( _generator_ )

1. Set _onRejected_.[[Generator]] to _generator_. 1. Let _throwawayCapability_ be ! NewPromiseCapability(%Promise%). 1. Set _throwawayCapability_.[[Promise]].[[PromiseIsHandled]] to *true*. - 1. Perform ! PerformPromiseThen(_promiseCapability_.[[Promise]], _onFulfilled_, _onRejected_, _throwawayCapability_). + 1. Perform ! PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_, _throwawayCapability_). 1. Return *undefined*. 1. Else, 1. Assert: _completion_.[[Type]] is ~throw~.