The abstract operation AsyncGeneratorReject takes arguments _generator_ and _exception_. It performs the following steps when called:
+
- AsyncGeneratorResumeNext ( _generator_ )
- The abstract operation AsyncGeneratorResumeNext takes argument _generator_. It performs the following steps when called:
+
+ AsyncGeneratorResume ( _generator_, _completion_ )
+ The abstract operation AsyncGeneratorResume takes arguments _generator_ (an AsyncGenerator) and _completion_ (a Completion Record). It performs the following steps when called:
- 1. Assert: _generator_ is an AsyncGenerator instance.
- 1. Let _state_ be _generator_.[[AsyncGeneratorState]].
- 1. Assert: _state_ is not ~executing~.
- 1. If _state_ is ~awaiting-return~, return *undefined*.
- 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]].
- 1. If _queue_ is an empty List, return *undefined*.
- 1. Let _next_ be the value of the first element of _queue_.
- 1. Assert: _next_ is an AsyncGeneratorRequest record.
- 1. Let _completion_ be _next_.[[Completion]].
- 1. If _completion_ is an abrupt completion, then
- 1. If _state_ is ~suspendedStart~, then
- 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
- 1. Set _state_ to ~completed~.
- 1. If _state_ is ~completed~, then
- 1. If _completion_.[[Type]] is ~return~, then
- 1. Set _generator_.[[AsyncGeneratorState]] to ~awaiting-return~.
- 1. Let _promise_ be ? PromiseResolve(%Promise%, _completion_.[[Value]]).
- 1. Let _fulfilledClosure_ be a new Abstract Closure with parameters (_value_) that captures _generator_ and performs the following steps when called:
- 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
- 1. Return ! AsyncGeneratorResolve(_generator_, _value_, *true*).
- 1. Let _onFulfilled_ be ! CreateBuiltinFunction(_fulfilledClosure_, 1, *""*, « »).
- 1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _generator_ and performs the following steps when called:
- 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
- 1. Return ! AsyncGeneratorReject(_generator_, _reason_).
- 1. Let _onRejected_ be ! CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »).
- 1. Perform ! PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_).
- 1. Return *undefined*.
- 1. Else,
- 1. Assert: _completion_.[[Type]] is ~throw~.
- 1. Perform ! AsyncGeneratorReject(_generator_, _completion_.[[Value]]).
- 1. Return *undefined*.
- 1. Else if _state_ is ~completed~, return ! AsyncGeneratorResolve(_generator_, *undefined*, *true*).
- 1. Assert: _state_ is either ~suspendedStart~ or ~suspendedYield~.
+ 1. Assert: _generator_.[[AsyncGeneratorState]] is either ~suspendedStart~ or ~suspendedYield~.
1. Let _genContext_ be _generator_.[[AsyncGeneratorContext]].
1. Let _callerContext_ be the running execution context.
1. Suspend _callerContext_.
@@ -40067,27 +40075,18 @@ AsyncGeneratorResumeNext ( _generator_ )
1. Resume the suspended evaluation of _genContext_ using _completion_ as the result of the operation that suspended it. Let _result_ be the completion record returned by the resumed computation.
1. Assert: _result_ is never an abrupt completion.
1. Assert: When we return here, _genContext_ has already been removed from the execution context stack and _callerContext_ is the currently running execution context.
- 1. Return *undefined*.
-
- AsyncGeneratorEnqueue ( _generator_, _completion_, _generatorBrand_ )
- The abstract operation AsyncGeneratorEnqueue takes arguments _generator_, _completion_ (a Completion Record), and _generatorBrand_. It performs the following steps when called:
+
+ AsyncGeneratorUnwrapYieldResumption ( _resumptionValue_ )
+ The abstract operation AsyncGeneratorUnwrapYieldResumption takes argument _resumptionValue_ (a Completion Record). It performs the following steps when called:
- 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
- 1. Let _check_ be AsyncGeneratorValidate(_generator_, _generatorBrand_).
- 1. If _check_ is an abrupt completion, then
- 1. Let _badGeneratorError_ be a newly created *TypeError* object.
- 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _badGeneratorError_ »).
- 1. Return _promiseCapability_.[[Promise]].
- 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]].
- 1. Let _request_ be AsyncGeneratorRequest { [[Completion]]: _completion_, [[Capability]]: _promiseCapability_ }.
- 1. Append _request_ to the end of _queue_.
- 1. Let _state_ be _generator_.[[AsyncGeneratorState]].
- 1. If _state_ is not ~executing~, then
- 1. Perform ! AsyncGeneratorResumeNext(_generator_).
- 1. Return _promiseCapability_.[[Promise]].
+ 1. If _resumptionValue_.[[Type]] is not ~return~, return Completion(_resumptionValue_).
+ 1. Let _awaited_ be Await(_resumptionValue_.[[Value]]).
+ 1. If _awaited_.[[Type]] is ~throw~, return Completion(_awaited_).
+ 1. Assert: _awaited_.[[Type]] is ~normal~.
+ 1. Return Completion { [[Type]]: ~return~, [[Value]]: _awaited_.[[Value]], [[Target]]: ~empty~ }.
@@ -40100,17 +40099,76 @@ AsyncGeneratorYield ( _value_ )
1. Let _generator_ be the value of the Generator component of _genContext_.
1. Assert: GetGeneratorKind() is ~async~.
1. Set _value_ to ? Await(_value_).
- 1. Set _generator_.[[AsyncGeneratorState]] to ~suspendedYield~.
- 1. Remove _genContext_ 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 _genContext_ such that when evaluation is resumed with a Completion _resumptionValue_ the following steps will be performed:
- 1. If _resumptionValue_.[[Type]] is not ~return~, return Completion(_resumptionValue_).
- 1. Let _awaited_ be Await(_resumptionValue_.[[Value]]).
- 1. If _awaited_.[[Type]] is ~throw~, return Completion(_awaited_).
- 1. Assert: _awaited_.[[Type]] is ~normal~.
- 1. Return Completion { [[Type]]: ~return~, [[Value]]: _awaited_.[[Value]], [[Target]]: ~empty~ }.
- 1. NOTE: When one of the above steps returns, it returns to the evaluation of the |YieldExpression| production that originally called this abstract operation.
- 1. Return ! AsyncGeneratorResolve(_generator_, _value_, *false*).
- 1. NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of _genContext_.
+ 1. Let _completion_ be NormalCompletion(_value_).
+ 1. Assert: The execution context stack has at least two elements.
+ 1. Let _previousContext_ be the second to top element of the execution context stack.
+ 1. Let _previousRealm_ be _previousContext_'s Realm.
+ 1. Perform ! AsyncGeneratorCompleteStep(_generator_, _completion_, *false*, _previousRealm_).
+ 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]].
+ 1. If _queue_ is not empty, then
+ 1. NOTE: Execution continues without suspending the generator.
+ 1. Let _toYield_ be the first element of _queue_.
+ 1. Let _resumptionValue_ be _toYield_.[[Completion]].
+ 1. Return AsyncGeneratorUnwrapYieldResumption(_resumptionValue_).
+ 1. Else,
+ 1. Set _generator_.[[AsyncGeneratorState]] to ~suspendedYield~.
+ 1. Remove _genContext_ 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 _genContext_ such that when evaluation is resumed with a Completion _resumptionValue_ the following steps will be performed:
+ 1. Return AsyncGeneratorUnwrapYieldResumption(_resumptionValue_).
+ 1. NOTE: When the above step returns, it returns to the evaluation of the |YieldExpression| production that originally called this abstract operation.
+ 1. Return *undefined*.
+ 1. NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of _genContext_.
+
+
+
+
+ AsyncGeneratorAwaitReturn ( _generator_ )
+ The abstract operation AsyncGeneratorAwaitReturn takes argument _generator_ (an AsyncGenerator). It performs the following steps when called:
+
+ 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]].
+ 1. Assert: _queue_ is not empty.
+ 1. Let _next_ be the first element of _queue_.
+ 1. Let _completion_ be _next_.[[Completion]].
+ 1. Assert: _completion_.[[Type]] is ~return~.
+ 1. Let _promise_ be ? PromiseResolve(%Promise%, _completion_.[[Value]]).
+ 1. Let _fulfilledClosure_ be a new Abstract Closure with parameters (_value_) that captures _generator_ and performs the following steps when called:
+ 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
+ 1. Let _result_ be NormalCompletion(_value_).
+ 1. Perform ! AsyncGeneratorCompleteStep(_generator_, _result_, *true*).
+ 1. Perform ! AsyncGeneratorDrainQueue(_generator_).
+ 1. Return *undefined*.
+ 1. Let _onFulfilled_ be ! CreateBuiltinFunction(_fulfilledClosure_, 1, *""*, « »).
+ 1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _generator_ and performs the following steps when called:
+ 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
+ 1. Let _result_ be ThrowCompletion(_reason_).
+ 1. Perform ! AsyncGeneratorCompleteStep(_generator_, _result_, *true*).
+ 1. Perform ! AsyncGeneratorDrainQueue(_generator_).
+ 1. Return *undefined*.
+ 1. Let _onRejected_ be ! CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »).
+ 1. Perform ! PerformPromiseThen(_promise_, _onFulfilled_, _onRejected_).
+
+
+
+
+ AsyncGeneratorDrainQueue ( _generator_ )
+ The abstract operation AsyncGeneratorDrainQueue takes argument _generator_ (an AsyncGenerator). It drains the generator's AsyncGeneratorQueue until it encounters an AsyncGeneratorRequest which holds a completion whose type is ~return~. It performs the following steps when called:
+
+ 1. Assert: _generator_.[[AsyncGeneratorState]] is ~completed~.
+ 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]].
+ 1. If _queue_ is empty, return.
+ 1. Let _done_ be *false*.
+ 1. Repeat, while _done_ is *false*,
+ 1. Let _next_ be the first element of _queue_.
+ 1. Let _completion_ be _next_.[[Completion]].
+ 1. If _completion_.[[Type]] is ~return~, then
+ 1. Set _generator_.[[AsyncGeneratorState]] to ~awaiting-return~.
+ 1. Perform ! AsyncGeneratorAwaitReturn(_generator_).
+ 1. Set _done_ to *true*.
+ 1. Else,
+ 1. If _completion_.[[Type]] is ~normal~, then
+ 1. Set _completion_ to NormalCompletion(*undefined*).
+ 1. Perform ! AsyncGeneratorCompleteStep(_generator_, _completion_, *true*).
+ 1. If _queue_ is empty, set _done_ to *true*.
@@ -43052,7 +43110,7 @@ Additions and Changes That Introduce Incompatibilities with Prior Editions
In ECMAScript 2015, the RegExp prototype object is not a RegExp instance. In previous editions it was a RegExp instance whose pattern is the empty String.
In ECMAScript 2015, *"source"*, *"global"*, *"ignoreCase"*, and *"multiline"* are accessor properties defined on the RegExp prototype object. In previous editions they were data properties defined on RegExp instances.
: In ECMAScript 2019, `Atomics.wake` has been renamed to `Atomics.notify` to prevent confusion with `Atomics.wait`.
- , : In ECMAScript 2019, the number of Jobs enqueued by `await` was reduced, which could create an observable difference in resolution order between a `then()` call and an `await` expression.
+ , : In ECMAScript 2019, the number of Jobs enqueued by `await` was reduced, which could create an observable difference in resolution order between a `then()` call and an `await` expression.
Colophon