diff --git a/spec/abstract-operations.html b/spec/abstract-operations.html index 58977f5..71f5c79 100644 --- a/spec/abstract-operations.html +++ b/spec/abstract-operations.html @@ -58,11 +58,8 @@

AsyncGeneratorResolve ( _generator_, _value_, _done_ )

1. Assert: _queue_ is not an empty List. 1. Remove the first element from _queue_ and let _next_ be the value of that element. 1. Let _promiseCapability_ be _next_.[[Capability]]. - 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _value_ »). - 1. Let _onFulfilled_ be a new built-in function object as defined in . - 1. Set _onFulfilled_.[[Done]] to _done_. - 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Let _iteratorResult_ be ! CreateIterResultObject(_value_, _done_). + 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _iteratorResult_ »). 1. Perform ! AsyncGeneratorResumeNext(_generator_). 1. Return *undefined*. @@ -88,6 +85,7 @@

AsyncGeneratorResumeNext ( _generator_ )

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_. @@ -98,8 +96,21 @@

AsyncGeneratorResumeNext ( _generator_ )

1. Set _generator_.[[AsyncGeneratorState]] to `"completed"`. 1. Set _state_ to `"completed"`. 1. If _state_ is `"completed"`, then - 1. If _completion_.[[Type]] is ~return~, then return ! AsyncGeneratorResolve(_generator_, _completion_.[[Value]], *true*). - 1. Else, return ! AsyncGeneratorReject(_generator_, _completion_.[[Value]]). + 1. If _completion_.[[Type]] is ~return~: + 1. Set _generator_.[[AsyncGeneratorState]] to `"awaiting-return"`. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _completion_.[[Value]] »). + 1. Let _onFulfilled_ be a new built-in function object as defined in . + 1. Let _onRejected_ be a new built-in function object as defined in . + 1. Set _onFulfilled_ and _onRejected_'s [[Generator]] internal slots to _generator_. + 1. Let _throwawayCapability_ be NewPromiseCapability(%Promise%). + 1. Set _throwawayCapability_.[[Promise]].[[PromiseIsHandled]] to *true*. + 1. Perform ! PerformPromiseThen(_promiseCapability_.[[Promise]], _onFulfilled_, _onRejected_, _throwawayCapability_). + 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"`, then return ! AsyncGeneratorResolve(_generator_, *undefined*, *true*). 1. Assert: _state_ is either `"suspendedStart"` or `"suspendedYield"`. 1. Let _genContext_ be _generator_.[[AsyncGeneratorContext]]. @@ -112,6 +123,36 @@

AsyncGeneratorResumeNext ( _generator_ )

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*. + + +

AsyncGeneratorResumeNext Return Processor Fulfilled Functions

+ +

An AsyncGeneratorResumeNext return processor fulfilled function is an anonymous built-in function that is used as part of the AsyncGeneratorResumeNext specification device to unwrap promises passed in to the method. Each AsyncGeneratorResumeNext return processor fulfilled function has a [[Generator]] internal slot.

+ +

When an AsyncGeneratorResumeNext return processor fulfilled function _F_ is called with argument _value_, the following steps are taken:

+ + + 1. Set _F_.[[Generator]].[[AsyncGeneratorState]] to `"completed"`. + 1. Return ! AsyncGeneratorResolve(_F_.[[Generator]], _value_, *true*). + + +

The `length` property of an AsyncGeneratorResumeNext return processor fulfilled function is 1.

+
+ + +

AsyncGeneratorResumeNext Return Processor Rejected Functions

+ +

An AsyncGeneratorResumeNext return processor rejected function is an anonymous built-in function that is used as part of the AsyncGeneratorResumeNext specification device to unwrap promises passed in to the method. Each AsyncGeneratorResumeNext return processor rejected function has a [[Generator]] internal slot.

+ +

When an AsyncGeneratorResumeNext return processor rejected function _F_ is called with argument _reason_, the following steps are taken:

+ + + 1. Set _F_.[[Generator]].[[AsyncGeneratorState]] to `"completed"`. + 1. Return ! AsyncGeneratorReject(_F_.[[Generator]], _reason_). + + +

The `length` property of an AsyncGeneratorResumeNext return processor rejected function is 1.

+
@@ -141,11 +182,16 @@

AsyncGeneratorYield ( _value_ )

1. Assert: _genContext_ is the execution context of a generator. 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. Return _resumptionValue_. - 1. NOTE: This returns to the evaluation of the |YieldExpression| production that originally called this abstract operation. + 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_. diff --git a/spec/async-generator-objects.html b/spec/async-generator-objects.html index b194839..d6afba3 100644 --- a/spec/async-generator-objects.html +++ b/spec/async-generator-objects.html @@ -62,7 +62,7 @@

Properties of AsyncGenerator Instances

[[AsyncGeneratorState]] - The current execution state of the async generator. The possible values are: *undefined*, `"suspendedStart"`, `"suspendedYield"`, `"executing"`, and `"completed"`. + The current execution state of the async generator. The possible values are: *undefined*, `"suspendedStart"`, `"suspendedYield"`, `"executing"`, `"awaiting-return"`, and `"completed"`. [[AsyncGeneratorContext]] diff --git a/spec/generator-abstract-ops-patch.html b/spec/generator-abstract-ops-patch.html index a0326bc..15765a2 100644 --- a/spec/generator-abstract-ops-patch.html +++ b/spec/generator-abstract-ops-patch.html @@ -2,7 +2,7 @@

GetGeneratorKind ( )

1. Let _genContext_ be the running execution context. - 1. Assert: _genContext_ has a Generator component. + 1. If _genContext_ does not have a Generator component, return ~non-generator~. 1. Let _generator_ be the Generator component of _genContext_. 1. If _generator_ has an [[AsyncGeneratorState]] internal slot, return ~async~. 1. Else, return ~normal~. diff --git a/spec/generator-definitions-patch.html b/spec/generator-definitions-patch.html index 62e8599..ec54782 100644 --- a/spec/generator-definitions-patch.html +++ b/spec/generator-definitions-patch.html @@ -34,9 +34,7 @@

Runtime Semantics: Evaluation

1. If Type(_innerResult_) is not Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_innerResult_). 1. If _done_ is *true*, then - 1. Let _resultValue_ be Return ? IteratorValue(_innerResult_). - 1. If _generatorKind_ is ~async~, then set _resultValue_ to ? Await(_resultValue_). - 1. Return _resultValue_. + 1. Return ? IteratorValue(_innerResult_). 1. If _generatorKind_ is ~async~, then let _received_ be AsyncGeneratorYield(? IteratorValue(_innerResult_)). 1. Else, lLet _received_ be GeneratorYield(_innerResult_). 1. Else if _received_.[[Type]] is ~throw~, then @@ -48,9 +46,7 @@

Runtime Semantics: Evaluation

1. If Type(_innerResult_) is not Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_innerResult_). 1. If _done_ is *true*, then - 1. Let _resultValue_ be Return ? IteratorValue(_innerResult_). - 1. If _generatorKind_ is ~async~, then set _resultValue_ to ? Await(_resultValue_). - 1. Return _resultValue_. + 1. Return ? IteratorValue(_innerResult_). 1. If _generatorKind_ is ~async~, then let _received_ be AsyncGeneratorYield(? IteratorValue(_innerResult_)). 1. Else, lLet _received_ be GeneratorYield(_innerResult_). 1. Else, @@ -70,7 +66,6 @@

Runtime Semantics: Evaluation

1. Let _done_ be ? IteratorComplete(_innerReturnResult_). 1. If _done_ is *true*, then 1. Let _value_ be ? IteratorValue(_innerReturnResult_). - 1. If _generatorKind_ is ~async~, then set _value_ to ? Await(_value_). 1. Return Completion{[[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~}. 1. If _generatorKind_ is ~async~, then let _received_ be AsyncGeneratorYield(? IteratorValue(_innerResult_)). 1. Else, lLet _received_ be GeneratorYield(_innerResult_). diff --git a/spec/index.html b/spec/index.html index 0674d29..6b40d92 100644 --- a/spec/index.html +++ b/spec/index.html @@ -62,13 +62,21 @@

ECMAScript Function Objects

- -

Iteration Statements

+ +

ECMAScript Language: Statements and Declarations

- These patches modify clauses of and add clauses to . + These patches modify clauses of and add clauses to . - + +

The `return` Statement

+ +
+ + +

Iteration Statements

+ +
diff --git a/spec/iteration.html b/spec/iteration.html index 4dd686c..2e86ce7 100644 --- a/spec/iteration.html +++ b/spec/iteration.html @@ -80,18 +80,6 @@

The AsyncIterator Interface

Typically callers of these methods should check for their existence before invoking them. Certain ECMAScript language features including `for`-`await`-`of` and `yield*` call these methods after performing an existence check.

- - -

Async Iterator Value Unwrap Functions

- -

An async iterator value unwrap function is an anonymous built-in function that is used when processing the `value` field of an IteratorResult object, in order to wait for its value if it is a promise and re-package the result in a new "unwrapped" IteratorResult object. Each async iterator value unwrap function has a [[Done]] internal slot.

- -

When an async iterator unwrap function _F_ is called with argument _value_, the following steps are taken:

- - - 1. Return ! CreateIterResultObject(_value_, _F_.[[Done]]). - -
@@ -149,7 +137,7 @@

%AsyncFromSyncIteratorPrototype%.next ( _value_ )

1. IfAbruptRejectPromise(_nextValue_, _promiseCapability_). 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _nextValue_ »). - 1. Let _onFulfilled_ be a new built-in function object as defined in . + 1. Let _onFulfilled_ be a new built-in function object as defined in . 1. Set _onFulfilled_.[[Done]] to _nextDone_. 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -184,7 +172,7 @@

%AsyncFromSyncIteratorPrototype%.return ( _value_ )

1. IfAbruptRejectPromise(_returnValue_, _promiseCapability_). 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _returnValue_ »). - 1. Let _onFulfilled_ be a new built-in function object as defined in . + 1. Let _onFulfilled_ be a new built-in function object as defined in . 1. Set _onFulfilled_.[[Done]] to _returnDone_. 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -218,7 +206,7 @@

%AsyncFromSyncIteratorPrototype%.throw ( _value_ )

1. IfAbruptRejectPromise(_throwValue_, _promiseCapability_). 1. Let _valueWrapperCapability_ be ! NewPromiseCapability(%Promise%). 1. Perform ! Call(_valueWrapperCapability_.[[Resolve]], *undefined*, « _throwValue_ »). - 1. Let _onFulfilled_ be a new built-in function object as defined in . + 1. Let _onFulfilled_ be a new built-in function object as defined in . 1. Set _onFulfilled_.[[Done]] to _throwDone_. 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). 1. Return _promiseCapability_.[[Promise]]. @@ -230,6 +218,18 @@

%AsyncFromSyncIteratorPrototype% [ @@toStringTag ]

The initial value of the @@toStringTag property is the String value `"Async-from-Sync Iterator"`.

This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.

+ + +

Async-from-Sync Iterator Value Unwrap Functions

+ +

An async-from-sync iterator value unwrap function is an anonymous built-in function that is used by methods of %AsyncFromSyncIteratorPrototype% when processing the `value` field of an IteratorResult object, in order to wait for its value if it is a promise and re-package the result in a new "unwrapped" IteratorResult object. Each async iterator value unwrap function has a [[Done]] internal slot.

+ +

When an async-from-sync iterator value unwrap function _F_ is called with argument _value_, the following steps are taken:

+ + + 1. Return ! CreateIterResultObject(_value_, _F_.[[Done]]). + +
diff --git a/spec/return-statement-patch.html b/spec/return-statement-patch.html new file mode 100644 index 0000000..8d15d6c --- /dev/null +++ b/spec/return-statement-patch.html @@ -0,0 +1,25 @@ +

Syntax

+ + ReturnStatement[Yield, Await] : + `return` `;` + `return` [no LineTerminator here] Expression[+In, ?Yield, ?Await] `;` + + +

A `return` statement causes a function to cease execution and return a value to the caller. If |Expression| is omitted, the return value is *undefined*. Otherwise, the return value is the value of |Expression|.

+
+ + + +

Runtime Semantics: Evaluation

+ ReturnStatement : `return` `;` + + 1. Return Completion{[[Type]]: ~return~, [[Value]]: *undefined*, [[Target]]: ~empty~}. + + ReturnStatement : `return` Expression `;` + + 1. Let _exprRef_ be the result of evaluating |Expression|. + 1. Let _exprValue_ be ? GetValue(_exprRef_). + 1. If ! GetGeneratorKind() is ~async~, set _exprValue_ to ? Await(_exprValue_). + 1. Return Completion{[[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~}. + +