From b564aa94785aa5651342b02980380bf06ab44d59 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 15 Feb 2018 12:28:32 -0500 Subject: [PATCH] Normative: add async iteration (#1066) Proposal repo: https://github.com/tc39/proposal-async-iteration --- spec.html | 1408 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 1285 insertions(+), 123 deletions(-) diff --git a/spec.html b/spec.html index 2c14d3e2f7..8ae9d81c68 100644 --- a/spec.html +++ b/spec.html @@ -993,6 +993,17 @@

Well-Known Symbols

Value and Purpose + + + @@asyncIterator + + + `"Symbol.asyncIterator"` + + + A method that returns the default AsyncIterator for an object. Called by the semantics of the `for`-`await`-`of` statement. + + @@hasInstance @@ -1832,6 +1843,16 @@

Well-Known Intrinsic Objects

The initial value of the `values` data property of %ArrayPrototype% () + + + %AsyncFromSyncIteratorPrototype% + + + + + The prototype of async-from-sync iterator objects () + + %AsyncFunction% @@ -1852,6 +1873,46 @@

Well-Known Intrinsic Objects

The initial value of the `prototype` data property of %AsyncFunction% + + + %AsyncGenerator% + + + + + The initial value of the `prototype` property of %AsyncGeneratorFunction% + + + + + %AsyncGeneratorFunction% + + + + + The constructor of async iterator objects () + + + + + %AsyncGeneratorPrototype% + + + + + The initial value of the `prototype` property of %AsyncGenerator% + + + + + %AsyncIteratorPrototype% + + + + + An object that all standard built-in async iterator objects indirectly inherit from + + %Atomics% @@ -2978,6 +3039,93 @@

The Completion Record Specification Type

The term “abrupt completion” refers to any completion with a [[Type]] value other than ~normal~.

+ +

Await

+ +

Algorithm steps that say

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

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 _realm_ be the current Realm Record. + 1. Let _stepsFulfilled_ be the algorithm steps defined in . + 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _stepsFulfilled_, %FunctionPrototype%, « [[AsyncContext]] »). + 1. Set _onFulfilled_.[[AsyncContext]] to _asyncContext_. + 1. Let _stepsRejected_ be the algorithm steps defined in . + 1. Let _onRejected_ be CreateBuiltinFunction(_realm_, _stepsRejected_, %FunctionPrototype%, « [[AsyncContext]] »). + 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. 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. + + +

where all variables in the above steps, with the exception of _completion_, are ephemeral and visible only in the steps pertaining to Await.

+ + +

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

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

means the same thing as:

+ + + 1. Let _value_ be Await(_promise_). + 1. ReturnIfAbrupt(_value_). + +
+ + +

Await Fulfilled Functions

+ +

An Await fulfilled function is an anonymous built-in function that is used as part of the Await specification device to deliver the promise fulfillment value to the caller as a normal completion. Each Await fulfilled function has an [[AsyncContext]] internal slot.

+ +

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

+ + + 1. Let _asyncContext_ be _F_.[[AsyncContext]]. + 1. Let _prevContext_ be the running execution context. + 1. Suspend _prevContext_. + 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. + 1. Resume the suspended evaluation of _asyncContext_ using NormalCompletion(_value_) as the result of the operation that suspended it. + 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. + 1. Return *undefined*. + + +

The `length` property of an Await fulfilled function is 1.

+
+ + +

Await Rejected Functions

+ +

An Await rejected function is an anonymous built-in function that is used as part of the Await specification device to deliver the promise rejection reason to the caller as an abrupt throw completion. Each Await rejected function has an [[AsyncContext]] internal slot.

+ +

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

+ + + 1. Let _asyncContext_ be _F_.[[AsyncContext]]. + 1. Let _prevContext_ be the running execution context. + 1. Suspend _prevContext_. + 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. + 1. Resume the suspended evaluation of _asyncContext_ using Completion{[[Type]]: ~throw~, [[Value]]: _reason_, [[Target]]: ~empty~} as the result of the operation that suspended it. + 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. + 1. Return *undefined*. + + +

The `length` property of an Await rejected function is 1.

+
+
+

NormalCompletion

@@ -4815,11 +4963,19 @@

Operations on Iterator Objects

-

GetIterator ( _obj_ [ , _method_ ] )

-

The abstract operation GetIterator with argument _obj_ and optional argument _method_ performs the following steps:

+

GetIterator ( _obj_ [ , _hint_ [ , _method_ ] ] )

+

The abstract operation GetIterator with argument _obj_ and optional arguments _hint_ and _method_ performs the following steps:

+ 1. If _hint_ is not present, set _hint_ to ~sync~. + 1. Assert: _hint_ is either ~sync~ or ~async~. 1. If _method_ is not present, then - 1. Set _method_ to ? GetMethod(_obj_, @@iterator). + 1. If _hint_ is ~async~, then + 1. Set _method_ to ? GetMethod(_obj_, @@asyncIterator). + 1. If _method_ is *undefined*, then + 1. Let _syncMethod_ be ? GetMethod(_obj_, @@iterator). + 1. Let _syncIteratorRecord_ be ? GetIterator(_obj_, ~sync~, _syncMethod_). + 1. Return ? CreateAsyncFromSyncIterator(_syncIteratorRecord_). + 1. Otherwise, set _method_ to ? GetMethod(_obj_, @@iterator). 1. Let _iterator_ be ? Call(_method_, _obj_). 1. If Type(_iterator_) is not Object, throw a *TypeError* exception. 1. Let _nextMethod_ be ? GetV(_iterator_, `"next"`). @@ -4892,6 +5048,24 @@

IteratorClose ( _iteratorRecord_, _completion_ )

+ +

AsyncIteratorClose ( _iteratorRecord_, _completion_ )

+

The abstract operation AsyncIteratorClose with arguments _iteratorRecord_ and _completion_ is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state:

+ + 1. Assert: Type(_iteratorRecord_.[[Iterator]]) is Object. + 1. Assert: _completion_ is a Completion Record. + 1. Let _iterator_ be _iteratorRecord_.[[Iterator]]. + 1. Let _return_ be ? GetMethod(_iterator_, `"return"`). + 1. If _return_ is *undefined*, return Completion(_completion_). + 1. Let _innerResult_ be Call(_return_, _iterator_, « »). + 1. If _innerResult_.[[Type]] is ~normal~, set _innerResult_ to Await(_innerResult_.[[Value]]). + 1. If _completion_.[[Type]] is ~throw~, return Completion(_completion_). + 1. If _innerResult_.[[Type]] is ~throw~, return Completion(_innerResult_). + 1. If Type(_innerResult_.[[Value]]) is not Object, throw a *TypeError* exception. + 1. Return Completion(_completion_). + +
+

CreateIterResultObject ( _value_, _done_ )

@@ -5494,8 +5668,8 @@

GetSuperBase ( )

Global Environment Records

A global Environment Record is used to represent the outer most scope that is shared by all of the ECMAScript |Script| elements that are processed in a common realm. A global Environment Record provides the bindings for built-in globals (clause ), properties of the global object, and for all top-level declarations (, ) that occur within a |Script|.

-

A global Environment Record is logically a single record but it is specified as a composite encapsulating an object Environment Record and a declarative Environment Record. The object Environment Record has as its base object the global object of the associated Realm Record. This global object is the value returned by the global Environment Record's GetThisBinding concrete method. The object Environment Record component of a global Environment Record contains the bindings for all built-in globals (clause ) and all bindings introduced by a |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration| or |VariableStatement| contained in global code. The bindings for all other ECMAScript declarations in global code are contained in the declarative Environment Record component of the global Environment Record.

-

Properties may be created directly on a global object. Hence, the object Environment Record component of a global Environment Record may contain both bindings created explicitly by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, or |VariableDeclaration| declarations and bindings created implicitly as properties of the global object. In order to identify which bindings were explicitly created using declarations, a global Environment Record maintains a list of the names bound using its CreateGlobalVarBinding and CreateGlobalFunctionBinding concrete methods.

+

A global Environment Record is logically a single record but it is specified as a composite encapsulating an object Environment Record and a declarative Environment Record. The object Environment Record has as its base object the global object of the associated Realm Record. This global object is the value returned by the global Environment Record's GetThisBinding concrete method. The object Environment Record component of a global Environment Record contains the bindings for all built-in globals (clause ) and all bindings introduced by a |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, |AsyncGeneratorDeclaration|, or |VariableStatement| contained in global code. The bindings for all other ECMAScript declarations in global code are contained in the declarative Environment Record component of the global Environment Record.

+

Properties may be created directly on a global object. Hence, the object Environment Record component of a global Environment Record may contain both bindings created explicitly by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, |AsyncGeneratorDeclaration|, or |VariableDeclaration| declarations and bindings created implicitly as properties of the global object. In order to identify which bindings were explicitly created using declarations, a global Environment Record maintains a list of the names bound using its CreateGlobalVarBinding and CreateGlobalFunctionBinding concrete methods.

Global Environment Records have the additional fields listed in and the additional methods listed in .

@@ -5519,7 +5693,7 @@

Global Environment Records

Object Environment Record @@ -5541,7 +5715,7 @@

Global Environment Records

Declarative Environment Record @@ -5552,7 +5726,7 @@

Global Environment Records

List of String @@ -5582,7 +5756,7 @@

Global Environment Records

HasVarDeclaration (N) @@ -7421,7 +7595,7 @@

FunctionAllocate ( _functionPrototype_, _strict_, _functionKind_ )

The abstract operation FunctionAllocate requires the three arguments _functionPrototype_, _strict_ and _functionKind_. FunctionAllocate performs the following steps:

1. Assert: Type(_functionPrototype_) is Object. - 1. Assert: _functionKind_ is either `"normal"`, `"non-constructor"`, `"generator"`, or `"async"`. + 1. Assert: _functionKind_ is either `"normal"`, `"non-constructor"`, `"generator"`, `"async"`, or `"async generator"`. 1. If _functionKind_ is `"normal"`, let _needsConstruct_ be *true*. 1. Else, let _needsConstruct_ be *false*. 1. If _functionKind_ is `"non-constructor"`, set _functionKind_ to `"normal"`. @@ -7485,6 +7659,16 @@

GeneratorFunctionCreate ( _kind_, _ParameterList_, _Body_, _Scope_, _Strict_ + +

AsyncGeneratorFunctionCreate (_kind_, _ParameterList_, _Body_, _Scope_, _Strict_)

+

The abstract operation AsyncGeneratorFunctionCreate requires the arguments: _kind_ which is one of (~Normal~, ~Method~), a parameter list Parse Node specified by _ParameterList_, a body Parse Node specified by _Body_, a Lexical Environment specified by _Scope_, and a Boolean flag _Strict_. AsyncGeneratorFunctionCreate performs the following steps:

+ + 1. Let _functionPrototype_ be the intrinsic object %AsyncGenerator%. + 1. Let _F_ be ! FunctionAllocate(_functionPrototype_, _Strict_, `"generator"`). + 1. Return ! FunctionInitialize(_F_, _kind_, _ParameterList_, _Body_, _Scope_). + +
+

AddRestrictedFunctionProperties ( _F_, _realm_ )

@@ -7597,7 +7781,7 @@

FunctionDeclarationInstantiation ( _func_, _argumentsList_ )

1. Let _functionsToInitialize_ be a new empty List. 1. For each _d_ in _varDeclarations_, in reverse list order, do 1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then - 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|. + 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|. 1. Let _fn_ be the sole element of the BoundNames of _d_. 1. If _fn_ is not an element of _functionNames_, then 1. Insert _fn_ as the first element of _functionNames_. @@ -9401,20 +9585,20 @@

Types of Source Code

There are four types of ECMAScript code:

  • - Global code is source text that is treated as an ECMAScript |Script|. The global code of a particular |Script| does not include any source text that is parsed as part of a |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|. + Global code is source text that is treated as an ECMAScript |Script|. The global code of a particular |Script| does not include any source text that is parsed as part of a |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|.
  • Eval code is the source text supplied to the built-in `eval` function. More precisely, if the parameter to the built-in `eval` function is a String, it is treated as an ECMAScript |Script|. The eval code for a particular invocation of `eval` is the global code portion of that |Script|.
  • - Function code is source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see ) of an ECMAScript function object. The function code of a particular ECMAScript function does not include any source text that is parsed as the function code of a nested |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|. + Function code is source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see ) of an ECMAScript function object. The function code of a particular ECMAScript function does not include any source text that is parsed as the function code of a nested |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|.
  • - Module code is source text that is code that is provided as a |ModuleBody|. It is the code that is directly evaluated when a module is initialized. The module code of a particular module does not include any source text that is parsed as part of a nested |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|. + Module code is source text that is code that is provided as a |ModuleBody|. It is the code that is directly evaluated when a module is initialized. The module code of a particular module does not include any source text that is parsed as part of a nested |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |MethodDefinition|, |ArrowFunction|, |AsyncArrowFunction|, |ClassDeclaration|, or |ClassExpression|.
-

Function code is generally provided as the bodies of Function Definitions (), Arrow Function Definitions (), Method Definitions (), Generator Definitions (), Async Function Definitions (), and Async Arrow Functions (). Function code is also derived from the arguments to the `Function` constructor (), the `GeneratorFunction` constructor (), and the `AsyncFunction` constructor ().

+

Function code is generally provided as the bodies of Function Definitions (), Arrow Function Definitions (), Method Definitions (), Generator Function Definitions (), Async Function Definitions (), Async Generator Function Definitions (), and Async Arrow Functions (). Function code is also derived from the arguments to the `Function` constructor (), the `GeneratorFunction` constructor (), and the `AsyncFunction` constructor ().

@@ -9435,10 +9619,10 @@

Strict Mode Code

Eval code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive or if the call to `eval` is a direct eval that is contained in strict mode code.
  • - Function code is strict mode code if the associated |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |MethodDefinition|, |ArrowFunction|, or |AsyncArrowFunction| is contained in strict mode code or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive. + Function code is strict mode code if the associated |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |MethodDefinition|, |ArrowFunction|, or |AsyncArrowFunction| is contained in strict mode code or if the code that produces the value of the function's [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.
  • - Function code that is supplied as the arguments to the built-in `Function`, `Generator`, and `AsyncFunction` constructors is strict mode code if the last argument is a String that when processed is a |FunctionBody| that begins with a Directive Prologue that contains a Use Strict Directive. + Function code that is supplied as the arguments to the built-in `Function`, `Generator`, `AsyncFunction`, and `AsyncGenerator` constructors is strict mode code if the last argument is a String that when processed is a |FunctionBody| that begins with a Directive Prologue that contains a Use Strict Directive.
  • ECMAScript code that is not strict mode code is called non-strict code.

    @@ -11369,6 +11553,7 @@

    Syntax

    ClassExpression[?Yield, ?Await] GeneratorExpression AsyncFunctionExpression + AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral[?Yield, ?Await, ~Tagged] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] #parencover @@ -11460,6 +11645,7 @@

    Static Semantics: IsIdentifierRef

    ClassExpression GeneratorExpression AsyncFunctionExpression + AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral CoverParenthesizedExpressionAndArrowParameterList @@ -11483,6 +11669,7 @@

    Static Semantics: IsValidSimpleAssignmentTarget

    ClassExpression GeneratorExpression AsyncFunctionExpression + AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral @@ -11940,6 +12127,7 @@

    Function Defining Expressions

    See for PrimaryExpression : GeneratorExpression.

    See for PrimaryExpression : ClassExpression.

    See for PrimaryExpression : AsyncFunctionExpression.

    +

    See for PrimaryExpression : AsyncGeneratorExpression.

    @@ -14761,6 +14949,7 @@

    Syntax

    FunctionDeclaration[?Yield, ?Await, ?Default] GeneratorDeclaration[?Yield, ?Await, ?Default] AsyncFunctionDeclaration[?Yield, ?Await, ?Default] + AsyncGeneratorDeclaration[?Yield, ?Await, ?Default] BreakableStatement[Yield, Await, Return] : IterationStatement[?Yield, ?Await, ?Return] @@ -14852,6 +15041,10 @@

    Static Semantics: DeclarationPart

    1. Return |AsyncFunctionDeclaration|. + HoistableDeclaration : AsyncGeneratorDeclaration + + 1. Return |AsyncGeneratorDeclaration|. + Declaration : ClassDeclaration 1. Return |ClassDeclaration|. @@ -14932,13 +15125,10 @@

    Runtime Semantics: LabelledEvaluation

    Runtime Semantics: Evaluation

    - HoistableDeclaration : GeneratorDeclaration - - - 1. Return NormalCompletion(~empty~). - - - HoistableDeclaration : AsyncFunctionDeclaration + HoistableDeclaration : + GeneratorDeclaration + AsyncFunctionDeclaration + AsyncGeneratorDeclaration 1. Return NormalCompletion(~empty~). @@ -15312,7 +15502,7 @@

    Runtime Semantics: BlockDeclarationInstantiation( _code_, _env_ )

    1. Perform ! _envRec_.CreateImmutableBinding(_dn_, *true*). 1. Else, 1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*). - 1. If _d_ is a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|, then + 1. If _d_ is a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|, then 1. Let _fn_ be the sole element of the BoundNames of _d_. 1. Let _fo_ be the result of performing InstantiateFunctionObject for _d_ with argument _env_. 1. Perform _envRec_.InitializeBinding(_fn_, _fo_). @@ -16080,7 +16270,7 @@

    Syntax

    [lookahead <! {`{`, `function`, `async` [no |LineTerminator| here] `function`, `class`, `let [`}] Expression[+In, ?Yield, ?Await] `;` -

    An |ExpressionStatement| cannot start with a U+007B (LEFT CURLY BRACKET) because that might make it ambiguous with a |Block|. An |ExpressionStatement| cannot start with the `function` or `class` keywords because that would make it ambiguous with a |FunctionDeclaration|, a |GeneratorDeclaration|, or a |ClassDeclaration|. An |ExpressionStatement| cannot start with `async function` because that would make it ambiguous with an |AsyncFunctionDeclaration|. An |ExpressionStatement| cannot start with the two token sequence `let [` because that would make it ambiguous with a `let` |LexicalDeclaration| whose first |LexicalBinding| was an |ArrayBindingPattern|.

    +

    An |ExpressionStatement| cannot start with a U+007B (LEFT CURLY BRACKET) because that might make it ambiguous with a |Block|. An |ExpressionStatement| cannot start with the `function` or `class` keywords because that would make it ambiguous with a |FunctionDeclaration|, a |GeneratorDeclaration|, or a |ClassDeclaration|. An |ExpressionStatement| cannot start with `async function` because that would make it ambiguous with an |AsyncFunctionDeclaration| or a |AsyncGeneratorDeclaration|. An |ExpressionStatement| cannot start with the two token sequence `let [` because that would make it ambiguous with a `let` |LexicalDeclaration| whose first |LexicalBinding| was an |ArrayBindingPattern|.

    @@ -16249,6 +16439,9 @@

    Syntax

    `for` `(` [lookahead != `let` ] LeftHandSideExpression[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] `for` `(` `var` ForBinding[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] `for` `(` ForDeclaration[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] + [+Await] `for` `await` `(` [lookahead != `let` ] LeftHandSideExpression[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] + [+Await] `for` `await` `(` `var` ForBinding[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] + [+Await] `for` `await` `(` ForDeclaration[?Yield, ?Await] `of` AssignmentExpression[+In, ?Yield, ?Await] `)` Statement[?Yield, ?Await, ?Return] ForDeclaration[Yield, Await] : LetOrConst ForBinding[?Yield, ?Await] @@ -16281,6 +16474,9 @@

    Static Semantics: Early Errors

    `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement
    • @@ -16652,7 +16848,7 @@

      Runtime Semantics: CreatePerIterationEnvironment( _perIterationBindings_ ) -

      The `for`-`in` and `for`-`of` Statements

      +

      The `for`-`in`, `for`-`of`, and `for`-`await`-`of` Statements

      @@ -16661,6 +16857,7 @@

      Static Semantics: Early Errors

      IterationStatement : `for` `(` LeftHandSideExpression `in` Expression `)` Statement `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement
      • @@ -16683,6 +16880,7 @@

        Static Semantics: Early Errors

        IterationStatement : `for` `(` ForDeclaration `in` Expression `)` Statement `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement
        • @@ -16720,6 +16918,10 @@

          Static Semantics: ContainsDuplicateLabels

          `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement + 1. Return ContainsDuplicateLabels of |Statement| with argument _labelSet_. @@ -16742,6 +16944,9 @@

          Static Semantics: ContainsUndefinedBreakTarget

          `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement 1. Return ContainsUndefinedBreakTarget of |Statement| with argument _labelSet_. @@ -16764,6 +16969,9 @@

          Static Semantics: ContainsUndefinedContinueTarget

          `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement 1. Return ContainsUndefinedContinueTarget of |Statement| with arguments _iterationSet_ and « ». @@ -16812,17 +17020,29 @@

          Static Semantics: VarDeclaredNames

          1. Return the VarDeclaredNames of |Statement|. - IterationStatement : `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + 1. Return the VarDeclaredNames of |Statement|. - IterationStatement : `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + 1. Let _names_ be the BoundNames of |ForBinding|. 1. Append to _names_ the elements of the VarDeclaredNames of |Statement|. 1. Return _names_. - IterationStatement : `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement + 1. Return the VarDeclaredNames of |Statement|. @@ -16845,21 +17065,37 @@

          Static Semantics: VarScopedDeclarations

          1. Append to _declarations_ the elements of the VarScopedDeclarations of |Statement|. 1. Return _declarations_.
          - IterationStatement : `for` `(` ForDeclaration `in` Expression `)` Statement + + IterationStatement : + `for` `(` ForDeclaration `in` Expression `)` Statement + `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + 1. Return the VarScopedDeclarations of |Statement|. - IterationStatement : `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + 1. Return the VarScopedDeclarations of |Statement|. - IterationStatement : `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + 1. Let _declarations_ be a List containing |ForBinding|. 1. Append to _declarations_ the elements of the VarScopedDeclarations of |Statement|. 1. Return _declarations_. - IterationStatement : `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + + IterationStatement : + `for` `(` ForDeclaration `of` AssignmentExpression `)` Statement + `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement + 1. Return the VarScopedDeclarations of |Statement|. @@ -16933,6 +17169,27 @@

          Runtime Semantics: LabelledEvaluation

          1. Let _keyResult_ be the result of performing ? ForIn/OfHeadEvaluation(BoundNames of |ForDeclaration|, |AssignmentExpression|, ~iterate~). 1. Return ? ForIn/OfBodyEvaluation(|ForDeclaration|, |Statement|, _keyResult_, ~iterate~, ~lexicalBinding~, _labelSet_).
          + + IterationStatement : `for` `await` `(` LeftHandSideExpression `of` AssignmentExpression `)` Statement + + + 1. Let _keyResult_ be the result of performing ? ForIn/OfHeadEvaluation(« », |AssignmentExpression|, ~async-iterate~). + 1. Return ? ForIn/OfBodyEvaluation(|LeftHandSideExpression|, |Statement|, _keyResult_, ~iterate~, ~assignment~, _labelSet_, ~async~). + + + IterationStatement : `for` `await` `(` `var` ForBinding `of` AssignmentExpression `)` Statement + + + 1. Let _keyResult_ be the result of performing ? ForIn/OfHeadEvaluation(« », |AssignmentExpression|, ~async-iterate~). + 1. Return ? ForIn/OfBodyEvaluation(|ForBinding|, |Statement|, _keyResult_, ~iterate~, ~varBinding~, _labelSet_, ~async~). + + + IterationStatement : `for` `await` `(` ForDeclaration `of` AssignmentExpression `)` Statement + + + 1. Let _keyResult_ be the result of performing ? ForIn/OfHeadEvaluation(BoundNames of |ForDeclaration|, |AssignmentExpression|, ~async-iterate~). + 1. Return ? ForIn/OfBodyEvaluation(|ForDeclaration|, |Statement|, _keyResult_, ~iterate~, ~lexicalBinding~, _labelSet_, ~async~). +

          This section is extended by Annex .

          @@ -16941,7 +17198,7 @@

          Runtime Semantics: LabelledEvaluation

          Runtime Semantics: ForIn/OfHeadEvaluation ( _TDZnames_, _expr_, _iterationKind_ )

          -

          The abstract operation ForIn/OfHeadEvaluation is called with arguments _TDZnames_, _expr_, and _iterationKind_. The value of _iterationKind_ is either ~enumerate~ or ~iterate~.

          +

          The abstract operation ForIn/OfHeadEvaluation is called with arguments _TDZnames_, _expr_, and _iterationKind_. The value of _iterationKind_ is either ~enumerate~, ~iterate~, or ~async-iterate~.

          1. Let _oldEnv_ be the running execution context's LexicalEnvironment. 1. If _TDZnames_ is not an empty List, then @@ -16961,15 +17218,18 @@

          Runtime Semantics: ForIn/OfHeadEvaluation ( _TDZnames_, _expr_, _iterationKi 1. Return ? EnumerateObjectProperties(_obj_). 1. Else, 1. Assert: _iterationKind_ is ~iterate~. - 1. Return ? GetIterator(_exprValue_). + 1. If _iterationKind_ is ~async-iterate~, let _iteratorHint_ be ~async~. + 1. Else, let _iteratorHint_ be ~sync~. + 1. Return ? GetIterator(_exprValue_, _iteratorHint_). -

          Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iteratorRecord_, _iterationKind_, _lhsKind_, _labelSet_ )

          -

          The abstract operation ForIn/OfBodyEvaluation is called with arguments _lhs_, _stmt_, _iteratorRecord_, _iterationKind_, _lhsKind_, and _labelSet_. The value of _iterationKind_ is either ~enumerate~ or ~iterate~. The value of _lhsKind_ is either ~assignment~, ~varBinding~ or ~lexicalBinding~.

          +

          Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iteratorRecord_, _iterationKind_, _lhsKind_, _labelSet_ [ , _iteratorKind_ ])

          +

          The abstract operation ForIn/OfBodyEvaluation is called with arguments _lhs_, _stmt_, _iteratorRecord_, _iterationKind_, _lhsKind_, _labelSet_, and optional argument _iteratorKind_. The value of _lhsKind_ is either ~assignment~, ~varBinding~ or ~lexicalBinding~. The value of _iteratorKind_ is either ~sync~ or ~async~.

          + 1. If _iteratorKind_ is not present, set _iteratorKind_ to ~sync~. 1. Let _oldEnv_ be the running execution context's LexicalEnvironment. 1. Let _V_ be *undefined*. 1. Let _destructuring_ be IsDestructuring of _lhs_. @@ -16977,8 +17237,9 @@

          Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iteratorRecord_, 1. Assert: _lhs_ is a |LeftHandSideExpression|. 1. Let _assignmentPattern_ be the |AssignmentPattern| that is covered by _lhs_. 1. Repeat, - 1. Let _nextResult_ be ? IteratorStep(_iteratorRecord_). - 1. If _nextResult_ is *false*, return NormalCompletion(_V_). + 1. Let _nextResult_ be ? Call(_iteratorRecord_.[[NextMethod]], _iteratorRecord_.[[Iterator]], « »). + 1. If _iteratorKind_ is ~async~, then set _nextResult_ to ? Await(_nextResult_). + 1. If Type(_nextResult_) is not Object, throw a *TypeError* exception. 1. Let _nextValue_ be ? IteratorValue(_nextResult_). 1. If _lhsKind_ is either ~assignment~ or ~varBinding~, then 1. If _destructuring_ is *false*, then @@ -17012,6 +17273,7 @@

          Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iteratorRecord_, 1. Let _status_ be the result of performing BindingInitialization for _lhs_ passing _nextValue_ and _iterationEnv_ as arguments. 1. If _status_ is an abrupt completion, then 1. Set the running execution context's LexicalEnvironment to _oldEnv_. + 1. If _iteratorKind_ is ~async~, return ? AsyncIteratorClose(_iteratorRecord_, _status_). 1. If _iterationKind_ is ~enumerate~, then 1. Return _status_. 1. Else, @@ -17024,7 +17286,9 @@

          Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iteratorRecord_, 1. Return Completion(UpdateEmpty(_result_, _V_)). 1. Else, 1. Assert: _iterationKind_ is ~iterate~. - 1. Return ? IteratorClose(_iteratorRecord_, UpdateEmpty(_result_, _V_)). + 1. Set _status_ to UpdateEmpty(_result_, _V_). + 1. If _iteratorKind_ is ~async~, return ? AsyncIteratorClose(_iteratorRecord_, _status_). + 1. Return ? IteratorClose(_iteratorRecord_, _status_). 1. If _result_.[[Value]] is not ~empty~, set _V_ to _result_.[[Value]]. @@ -17206,6 +17470,7 @@

          Runtime Semantics: Evaluation

          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~}.
          @@ -19074,6 +19339,7 @@

          Syntax

          PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, ~Await] `)` `{` FunctionBody[~Yield, ~Await] `}` GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] + AsyncGeneratorMethod[?Yield, ?Await] `get` PropertyName[?Yield, ?Await] `(` `)` `{` FunctionBody[~Yield, ~Await] `}` `set` PropertyName[?Yield, ?Await] `(` PropertySetParameterList `)` `{` FunctionBody[~Yield, ~Await] `}` @@ -19180,6 +19446,7 @@

          Static Semantics: SpecialMethod

          MethodDefinition : GeneratorMethod AsyncMethod + AsyncGeneratorMethod `get` PropertyName `(` `)` `{` FunctionBody `}` `set` PropertyName `(` PropertySetParameterList `)` `{` FunctionBody `}` @@ -19542,58 +19809,333 @@

          Runtime Semantics: Evaluation

          YieldExpression : `yield` - 1. Return ? GeneratorYield(CreateIterResultObject(*undefined*, *false*)). + 1. Let _generatorKind_ be ! GetGeneratorKind(). + 1. If _generatorKind_ is ~async~, then return ? AsyncGeneratorYield(*undefined*). + 1. Otherwise, return ? GeneratorYield(CreateIterResultObject(*undefined*, *false*)). YieldExpression : `yield` AssignmentExpression + 1. Let _generatorKind_ be ! GetGeneratorKind(). 1. Let _exprRef_ be the result of evaluating |AssignmentExpression|. 1. Let _value_ be ? GetValue(_exprRef_). - 1. Return ? GeneratorYield(CreateIterResultObject(_value_, *false*)). + 1. If _generatorKind_ is ~async~, then return ? AsyncGeneratorYield(_value_). + 1. Otherwise, return ? GeneratorYield(CreateIterResultObject(_value_, *false*)). YieldExpression : `yield` `*` AssignmentExpression + 1. Let _generatorKind_ be ! GetGeneratorKind(). 1. Let _exprRef_ be the result of evaluating |AssignmentExpression|. 1. Let _value_ be ? GetValue(_exprRef_). - 1. Let _iteratorRecord_ be ? GetIterator(_value_). + 1. Let _iteratorRecord_ be ? GetIterator(_value_, _generatorKind_). 1. Let _iterator_ be _iteratorRecord_.[[Iterator]]. 1. Let _received_ be NormalCompletion(*undefined*). 1. Repeat, 1. If _received_.[[Type]] is ~normal~, then - 1. Let _innerResult_ be ? IteratorNext(_iteratorRecord_, _received_.[[Value]]). + 1. Let _innerResult_ be ? Call(_iteratorRecord_.[[NextMethod]], _iteratorRecord_.[[Iterator]], « _received_.[[Value]] »). + 1. If _generatorKind_ is ~async~, then set _innerResult_ to ? Await(_innerResult_). + 1. If Type(_innerResult_) is not Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_innerResult_). 1. If _done_ is *true*, then 1. Return ? IteratorValue(_innerResult_). - 1. Set _received_ to GeneratorYield(_innerResult_). + 1. If _generatorKind_ is ~async~, then set _received_ to AsyncGeneratorYield(? IteratorValue(_innerResult_)). + 1. Else, set _received_ to GeneratorYield(_innerResult_). 1. Else if _received_.[[Type]] is ~throw~, then 1. Let _throw_ be ? GetMethod(_iterator_, `"throw"`). 1. If _throw_ is not *undefined*, then 1. Let _innerResult_ be ? Call(_throw_, _iterator_, « _received_.[[Value]] »). + 1. If _generatorKind_ is ~async~, then set _innerResult_ to ? Await(_innerResult_). 1. NOTE: Exceptions from the inner iterator `throw` method are propagated. Normal completions from an inner `throw` method are processed similarly to an inner `next`. 1. If Type(_innerResult_) is not Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_innerResult_). 1. If _done_ is *true*, then 1. Return ? IteratorValue(_innerResult_). - 1. Set _received_ to GeneratorYield(_innerResult_). + 1. If _generatorKind_ is ~async~, then set _received_ to AsyncGeneratorYield(? IteratorValue(_innerResult_)). + 1. Else, set _received_ to GeneratorYield(_innerResult_). 1. Else, 1. NOTE: If _iterator_ does not have a `throw` method, this throw is going to terminate the `yield*` loop. But first we need to give _iterator_ a chance to clean up. - 1. Perform ? IteratorClose(_iteratorRecord_, Completion{[[Type]]: ~normal~, [[Value]]: ~empty~, [[Target]]: ~empty~}). + 1. Let _closeCompletion_ be Completion{[[Type]]: ~normal~, [[Value]]: ~empty~, [[Target]]: ~empty~}. + 1. If _generatorKind_ is ~async~, perform ? AsyncIteratorClose(_iteratorRecord_, _closeCompletion_). + 1. Else, perform ? IteratorClose(_iteratorRecord_, _closeCompletion_). 1. NOTE: The next step throws a *TypeError* to indicate that there was a `yield*` protocol violation: _iterator_ does not have a `throw` method. 1. Throw a *TypeError* exception. 1. Else, 1. Assert: _received_.[[Type]] is ~return~. 1. Let _return_ be ? GetMethod(_iterator_, `"return"`). - 1. If _return_ is *undefined*, return Completion(_received_). + 1. If _return_ is *undefined*, then + 1. If _generatorKind_ is ~async~, then set _received_.[[Value]] to ? Await(_received_.[[Value]]). + 1. Return Completion(_received_). 1. Let _innerReturnResult_ be ? Call(_return_, _iterator_, « _received_.[[Value]] »). + 1. If _generatorKind_ is ~async~, then set _innerReturnResult_ to ? Await(_innerReturnResult_). 1. If Type(_innerReturnResult_) is not Object, throw a *TypeError* exception. 1. Let _done_ be ? IteratorComplete(_innerReturnResult_). 1. If _done_ is *true*, then 1. Let _value_ be ? IteratorValue(_innerReturnResult_). 1. Return Completion{[[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~}. - 1. Set _received_ to GeneratorYield(_innerReturnResult_). + 1. If _generatorKind_ is ~async~, then set _received_ to AsyncGeneratorYield(? IteratorValue(_innerReturnResult_)). + 1. Else, set _received_ to GeneratorYield(_innerReturnResult_).
          + +

          Async Generator Function Definitions

          +

          Syntax

          + + AsyncGeneratorMethod[Yield, Await] : + `async` [no LineTerminator here] `*` PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorDeclaration[Yield, Await, Default] : + `async` [no LineTerminator here] `function` `*` BindingIdentifier[?Yield, ?Await] `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}` + [+Default] `async` [no LineTerminator here] `function` `*` `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorExpression : + `async` [no LineTerminator here] `function` `*` BindingIdentifier[+Yield, +Await]? `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorBody : + FunctionBody[+Yield, +Await] + + +

          |YieldExpression| and |AwaitExpression| cannot be used within the |FormalParameters| of an async generator function because any expressions that are part of |FormalParameters| are evaluated before the resulting async generator object is in a resumable state.

          +
          + +

          Abstract operations relating to async generator objects are defined in .

          +
          + + +

          Static Semantics: Early Errors

          + AsyncGeneratorMethod : `async` `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}` +
            +
          • It is a Syntax Error if HasDirectSuper of |AsyncGeneratorMethod| is *true*.
          • +
          • It is a Syntax Error if |UniqueFormalParameters| Contains |YieldExpression| is *true*.
          • +
          • It is a Syntax Error if |UniqueFormalParameters| Contains |AwaitExpression| is *true*.
          • +
          • It is a Syntax Error if ContainsUseStrict of |AsyncGeneratorBody| is *true* and IsSimpleParameterList of |UniqueFormalParameters| is *false*.
          • +
          • It is a Syntax Error if any element of the BoundNames of |UniqueFormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncGeneratorBody|.
          • +
          + + AsyncGeneratorDeclaration : `async` `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorDeclaration : `async` `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorExpression : `async` `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + +
            +
          • If the source code matching this production is strict mode code, the Early Error rules for UniqueFormalParameters : FormalParameters are applied.
          • +
          • If the source code matching this production is strict mode code, it is a Syntax Error if |BindingIdentifier| is the |IdentifierName| `eval` or the |IdentifierName| `arguments`.
          • +
          • It is a Syntax Error if ContainsUseStrict of |AsyncGeneratorBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*.
          • +
          • It is a Syntax Error if any element of the BoundNames of |FormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncGeneratorBody|.
          • +
          • It is a Syntax Error if |FormalParameters| Contains |YieldExpression| is *true*.
          • +
          • It is a Syntax Error if |FormalParameters| Contains |AwaitExpression| is *true*.
          • +
          • It is a Syntax Error if |FormalParameters| Contains |SuperProperty| is *true*.
          • +
          • It is a Syntax Error if |AsyncGeneratorBody| Contains |SuperProperty| is *true*.
          • +
          • It is a Syntax Error if |FormalParameters| Contains |SuperCall| is *true*.
          • +
          • It is a Syntax Error if |AsyncGeneratorBody| Contains |SuperCall| is *true*.
          • +
          +
          + + +

          Static Semantics: BoundNames

          + + AsyncGeneratorDeclaration : `async` `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return the BoundNames of |BindingIdentifier|. + + AsyncGeneratorDeclaration : `async` `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return « `"*default*"` ». + + +

          `"*default*"` is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.

          +
          +
          + + +

          Static Semantics: ComputedPropertyContains

          +

          With parameter _symbol_.

          + + AsyncGeneratorMethod : `async` `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return the result of ComputedPropertyContains for |PropertyName| with argument _symbol_. + +
          + + +

          Static Semantics: Contains

          +

          With parameter _symbol_.

          + + + AsyncGeneratorDeclaration : `async` `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorDeclaration : `async` `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorExpression : `async` `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. Return *false*. + + +

          Static semantic rules that depend upon substructure generally do not look into function definitions.

          +
          +
          + + +

          Static Semantics: HasDirectSuper

          + + AsyncGeneratorMethod : `async` `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. If |UniqueFormalParameters| Contains |SuperCall| is *true*, return *true*. + 1. Return |AsyncGeneratorBody| Contains |SuperCall|. + +
          + + +

          Static Semantics: HasName

          + + AsyncGeneratorExpression : `async` `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return *false*. + + AsyncGeneratorExpression : `async` `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return *true*. + +
          + + +

          Static Semantics: IsConstantDeclaration

          + + + AsyncGeneratorDeclaration : `async` `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + AsyncGeneratorDeclaration : `async` `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. Return *false*. + +
          + + +

          Static Semantics: IsFunctionDefinition

          + + AsyncGeneratorExpression : `async` `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return *true*. + +
          + + +

          Static Semantics: PropName

          + + AsyncGeneratorMethod : `async` `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}` + + 1. Return PropName of |PropertyName|. + +
          + + +

          Runtime Semantics: EvaluateBody

          +

          With parameters _functionObject_ and List _argumentsList_.

          + + AsyncGeneratorBody : FunctionBody + + + 1. Perform ? FunctionDeclarationInstantiation(_functionObject_, _argumentsList_). + 1. Let _generator_ be ? OrdinaryCreateFromConstructor(_functionObject_, `"%AsyncGeneratorPrototype%"`, « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »). + 1. Perform ! AsyncGeneratorStart(_generator_, |FunctionBody|). + 1. Return Completion{[[Type]]: ~return~, [[Value]]: _generator_, [[Target]]: ~empty~}. + +
          + + +

          Runtime Semantics: InstantiateFunctionObject

          +

          With parameter _scope_.

          + + AsyncGeneratorDeclaration : `async` [no LineTerminator here] `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. If the function code for |AsyncGeneratorDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*. + 1. Let _name_ be StringValue of |BindingIdentifier|. + 1. Let _F_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_). + 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform ! DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Perform ! SetFunctionName(_F_, _name_). + 1. Return _F_. + + + + AsyncGeneratorDeclaration : `async` [no LineTerminator here] `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. If the function code for |AsyncGeneratorDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*. + 1. Let _F_ be AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_). + 1. Let _prototype_ be ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Perform SetFunctionName(_F_, `"default"`). + 1. Return _F_. + + +

          An anonymous |AsyncGeneratorDeclaration| can only occur as part of an `export default` declaration.

          +
          +
          + + +

          Runtime Semantics: PropertyDefinitionEvaluation

          +

          With parameter _object_ and _enumerable_.

          + + AsyncGeneratorMethod : `async` [no LineTerminator here] `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. Let _propKey_ be the result of evaluating |PropertyName|. + 1. ReturnIfAbrupt(_propKey_). + 1. If the function code for this |AsyncGeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*. + 1. Let _scope_ be the running execution context's LexicalEnvironment. + 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_). + 1. Perform ! MakeMethod(_closure_, _object_). + 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Perform ! SetFunctionName(_closure_, _propKey_). + 1. Let _desc_ be PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}. + 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_). + +
          + + +

          Runtime Semantics: Evaluation

          + + + AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*. + 1. Let _scope_ be the LexicalEnvironment of the running execution context. + 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_). + 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Return _closure_. + + + + AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}` + + + 1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*. + 1. Let _scope_ be the running execution context's LexicalEnvironment. + 1. Let _funcEnv_ be ! NewDeclarativeEnvironment(_scope_). + 1. Let _envRec_ be _funcEnv_'s EnvironmentRecord. + 1. Let _name_ be StringValue of |BindingIdentifier|. + 1. Perform ! _envRec_.CreateImmutableBinding(_name_). + 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _funcEnv_, _strict_). + 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Perform ! SetFunctionName(_closure_, _name_). + 1. Perform ! _envRec_.InitializeBinding(_name_, _closure_). + 1. Return _closure_. + + +

          The |BindingIdentifier| in an |AsyncGeneratorExpression| can be referenced from inside the |AsyncGeneratorExpression|'s |AsyncGeneratorBody| to allow the generator code to call itself recursively. However, unlike in an |AsyncGeneratorDeclaration|, the |BindingIdentifier| in an |AsyncGeneratorExpression| cannot be referenced from and does not affect the scope enclosing the |AsyncGeneratorExpression|.

          +
          +
          +
          +

          Class Definitions

          @@ -19995,12 +20537,12 @@

          Syntax

          `await` is parsed as an |AwaitExpression| when the [Await] parameter is present. The [Await] parameter is present in the following contexts:

          • In an |AsyncFunctionBody|.
          • -
          • In the |FormalParameters| of an |AsyncFunctionDeclaration| and |AsyncFunctionExpression|. |AwaitExpression| in this position is a Syntax error via static semantics.
          • +
          • In the |FormalParameters| of an |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, or |AsyncGeneratorExpression|. |AwaitExpression| in this position is a Syntax error via static semantics.

          When |Module| is the syntactic goal symbol and the [Await] parameter is absent, `await` is parsed as a keyword and will be a Syntax error. When |Script| is the syntactic goal symbol, `await` may be parsed as an identifier when the [Await] parameter is absent. This includes the following contexts:

            -
          • Anywhere outside of an |AsyncFunctionBody| or |FormalParameters| of an |AsyncFunctionDeclaration| or |AsyncFunctionExpression|.
          • -
          • In the |BindingIdentifier| of a |FunctionExpression| or |GeneratorExpression|.
          • +
          • Anywhere outside of an |AsyncFunctionBody| or |FormalParameters| of an |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, or |AsyncGeneratorExpression|.
          • +
          • In the |BindingIdentifier| of a |FunctionExpression|, |GeneratorExpression|, or |AsyncGeneratorExpression|.
          @@ -20254,7 +20796,7 @@

          Runtime Semantics: Evaluation

          1. Let _exprRef_ be the result of evaluating |UnaryExpression|. 1. Let _value_ be ? GetValue(_exprRef_). - 1. Return ? AsyncFunctionAwait(_value_). + 1. Return ? Await(_value_).
          @@ -20523,6 +21065,7 @@

          Static Semantics: IsInTailPosition( _call_ )

          1. Let _body_ be the |FunctionBody|, |ConciseBody|, or |AsyncConciseBody| that most closely contains _call_. 1. If _body_ is the |FunctionBody| of a |GeneratorBody|, return *false*. 1. If _body_ is the |FunctionBody| of an |AsyncFunctionBody|, return *false*. + 1. If _body_ is the |FunctionBody| of an |AsyncGeneratorBody|, return *false*. 1. If _body_ is an |AsyncConciseBody|, return *false*. 1. Return the result of HasCallInTailPosition of _body_ with argument _call_.
          @@ -20753,6 +21296,7 @@

          Expression Rules

          ClassExpression GeneratorExpression AsyncFunctionExpression + AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral @@ -21082,7 +21626,7 @@

          Runtime Semantics: GlobalDeclarationInstantiation ( _script_, _env_ )

          1. Let _declaredFunctionNames_ be a new empty List. 1. For each _d_ in _varDeclarations_, in reverse list order, do 1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then - 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|. + 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|. 1. NOTE: If there are multiple function declarations for the same name, the last declaration is used. 1. Let _fn_ be the sole element of the BoundNames of _d_. 1. If _fn_ is not an element of _declaredFunctionNames_, then @@ -22367,7 +22911,7 @@

          ModuleDeclarationEnvironmentSetup( _module_ )

          1. Perform ! _envRec_.CreateImmutableBinding(_dn_, *true*). 1. Else, 1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*). - 1. If _d_ is a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|, then + 1. If _d_ is a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|, then 1. Let _fo_ be the result of performing InstantiateFunctionObject for _d_ with argument _env_. 1. Call _envRec_.InitializeBinding(_dn_, _fo_). @@ -23262,7 +23806,7 @@

          Forbidden Extensions

          An implementation must not extend this specification in the following ways:

          • - ECMAScript function objects defined using syntactic constructors in strict mode code must not be created with own properties named `"caller"` or `"arguments"`. Such own properties also must not be created for function objects defined using an |ArrowFunction|, |MethodDefinition|, |GeneratorDeclaration|, |GeneratorExpression|, |ClassDeclaration|, |ClassExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, or |AsyncArrowFunction| regardless of whether the definition is contained in strict mode code. Built-in functions, strict functions created using the `Function` constructor, generator functions created using the `Generator` constructor, async functions created using the `AsyncFunction` constructor, and functions created using the `bind` method also must not be created with such own properties. + ECMAScript function objects defined using syntactic constructors in strict mode code must not be created with own properties named `"caller"` or `"arguments"`. Such own properties also must not be created for function objects defined using an |ArrowFunction|, |MethodDefinition|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |ClassDeclaration|, |ClassExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, or |AsyncArrowFunction| regardless of whether the definition is contained in strict mode code. Built-in functions, strict functions created using the `Function` constructor, generator functions created using the `Generator` constructor, async functions created using the `AsyncFunction` constructor, and functions created using the `bind` method also must not be created with such own properties.
          • If an implementation extends any function object with an own property named `"caller"` the value of that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function object. If it is an accessor property, the function that is the value of the property's [[Get]] attribute must never return a strict function when called. @@ -23494,7 +24038,7 @@

            Runtime Semantics: EvalDeclarationInstantiation( _body_, _varEnv_, _lexEnv_, 1. Let _declaredFunctionNames_ be a new empty List. 1. For each _d_ in _varDeclarations_, in reverse list order, do 1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then - 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|. + 1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|. 1. NOTE: If there are multiple function declarations for the same name, the last declaration is used. 1. Let _fn_ be the sole element of the BoundNames of _d_. 1. If _fn_ is not an element of _declaredFunctionNames_, then @@ -24683,7 +25227,7 @@

            Function Objects

            The Function Constructor

            The Function constructor is the %Function% intrinsic object and the initial value of the `Function` property of the global object. When `Function` is called as a function rather than as a constructor, it creates and initializes a new function object. Thus the function call `Function(…)` is equivalent to the object creation expression `new Function(…)` with the same arguments.

            -

            The `Function` constructor is designed to be subclassable. It may be used as the value of an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified `Function` behaviour must include a `super` call to the `Function` constructor to create and initialize a subclass instance with the internal slots necessary for built-in function behaviour. All ECMAScript syntactic forms for defining function objects create instances of `Function`. There is no syntactic means to create instances of `Function` subclasses except for the built-in `GeneratorFunction` and `AsyncFunction` subclasses.

            +

            The `Function` constructor is designed to be subclassable. It may be used as the value of an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified `Function` behaviour must include a `super` call to the `Function` constructor to create and initialize a subclass instance with the internal slots necessary for built-in function behaviour. All ECMAScript syntactic forms for defining function objects create instances of `Function`. There is no syntactic means to create instances of `Function` subclasses except for the built-in `GeneratorFunction`, `AsyncFunction`, and `AsyncGeneratorFunction` subclasses.

            @@ -24707,7 +25251,7 @@

            Function ( _p1_, _p2_, … , _pn_, _body_ )

            Runtime Semantics: CreateDynamicFunction( _constructor_, _newTarget_, _kind_, _args_ )

            -

            The abstract operation CreateDynamicFunction is called with arguments _constructor_, _newTarget_, _kind_, and _args_. _constructor_ is the constructor function that is performing this action, _newTarget_ is the constructor that `new` was initially applied to, _kind_ is either `"normal"`, `"generator"`, or `"async"`, and _args_ is a List containing the actual argument values that were passed to _constructor_. The following steps are taken:

            +

            The abstract operation CreateDynamicFunction is called with arguments _constructor_, _newTarget_, _kind_, and _args_. _constructor_ is the constructor function that is performing this action, _newTarget_ is the constructor that `new` was initially applied to, _kind_ is either `"normal"`, `"generator"`, `"async"`, or `"async generator"`, and _args_ is a List containing the actual argument values that were passed to _constructor_. The following steps are taken:

            1. Assert: The execution context stack has at least two elements. 1. Let _callerContext_ be the second to top element of the execution context stack. @@ -24723,11 +25267,16 @@

            Runtime Semantics: CreateDynamicFunction( _constructor_, _newTarget_, _kind_ 1. Let _goal_ be the grammar symbol |GeneratorBody|. 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[+Yield, ~Await]|. 1. Let _fallbackProto_ be `"%Generator%"`. - 1. Else, + 1. Else if _kind_ is `"async"`, then 1. Assert: _kind_ is `"async"`. 1. Let _goal_ be the grammar symbol |AsyncFunctionBody|. 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, +Await]|. 1. Let _fallbackProto_ be `"%AsyncFunctionPrototype%"`. + 1. Else, + 1. Assert: _kind_ is `"async generator"`. + 1. Let _goal_ be the grammar symbol |AsyncGeneratorBody|. + 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[+Yield, +Await]|. + 1. Let _fallbackProto_ be `"%AsyncGenerator%"`. 1. Let _argCount_ be the number of elements in _args_. 1. Let _P_ be the empty String. 1. If _argCount_ = 0, let _bodyText_ be the empty String. @@ -24753,9 +25302,9 @@

            Runtime Semantics: CreateDynamicFunction( _constructor_, _newTarget_, _kind_ 1. If _parameters_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception. 1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception. 1. If _parameters_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception. - 1. If _kind_ is `"generator"`, then + 1. If _kind_ is `"generator"` or `"async generator"`, then 1. If _parameters_ Contains |YieldExpression| is *true*, throw a *SyntaxError* exception. - 1. If _kind_ is `"async"`, then + 1. If _kind_ is `"async"` or `"async generator"`, then 1. If _parameters_ Contains |AwaitExpression| is *true*, throw a *SyntaxError* exception. 1. If _strict_ is *true*, then 1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception. @@ -24767,6 +25316,9 @@

            Runtime Semantics: CreateDynamicFunction( _constructor_, _newTarget_, _kind_ 1. If _kind_ is `"generator"`, then 1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%). 1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). + 1. Else if _kind_ is `"async generator"`, then + 1. Let _prototype_ be ObjectCreate(%AsyncGeneratorPrototype%). + 1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}). 1. Else if _kind_ is `"normal"`, perform MakeConstructor(_F_). 1. NOTE: Async functions are not constructable and do not have a [[Construct]] internal method or a `"prototype"` property. 1. Perform SetFunctionName(_F_, `"anonymous"`). @@ -24903,7 +25455,7 @@

            Function.prototype.toString ( )

            `toString` Representation Requirements:

            • - The string representation must have the syntax of a |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |ClassDeclaration|, |ClassExpression|, |ArrowFunction|, |AsyncArrowFunction|, or |MethodDefinition| depending upon the actual characteristics of the object. + The string representation must have the syntax of a |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |AsyncFunctionDeclaration|, |AsyncFunctionExpression|, |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, |ClassDeclaration|, |ClassExpression|, |ArrowFunction|, |AsyncArrowFunction|, or |MethodDefinition| depending upon the actual characteristics of the object.
            • The use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent. @@ -24967,7 +25519,7 @@

              prototype

              Function instances that can be used as a constructor have a `prototype` property. Whenever such a Function instance is created another ordinary object is also created and is the initial value of the function's `prototype` property. Unless otherwise specified, the value of the `prototype` property is used to initialize the [[Prototype]] internal slot of the object created when that function is invoked as a constructor.

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

              -

              Function objects created using `Function.prototype.bind`, or by evaluating a |MethodDefinition| (that is not a |GeneratorMethod|) or an |ArrowFunction| do not have a `prototype` property.

              +

              Function objects created using `Function.prototype.bind`, or by evaluating a |MethodDefinition| (that is not a |GeneratorMethod| or |AsyncGeneratorMethod|) or an |ArrowFunction| do not have a `prototype` property.

              @@ -25143,6 +25695,12 @@

              Symbol.for ( _key_ )

              + +

              Symbol.asyncIterator

              +

              The initial value of `Symbol.asyncIterator` is the well known symbol @@asyncIterator ().

              +

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

              +
              +

              Symbol.hasInstance

              @@ -31600,7 +32158,7 @@

              Array.from ( _items_ [ , _mapfn_ [ , _thisArg_ ] ] )

              1. Let _A_ be ? Construct(_C_). 1. Else, 1. Let _A_ be ! ArrayCreate(0). - 1. Let _iteratorRecord_ be ? GetIterator(_items_, _usingIterator_). + 1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~, _usingIterator_). 1. Let _k_ be 0. 1. Repeat, 1. If _k_ ≥ 253-1, then @@ -33231,7 +33789,7 @@

              %TypedArray%.from ( _source_ [ , _mapfn_ [ , _thisArg_ ] ] )

              Runtime Semantics: IterableToList( _items_, _method_ )

              The abstract operation IterableToList performs the following steps:

              - 1. Let _iteratorRecord_ be ? GetIterator(_items_, _method_). + 1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~, _method_). 1. Let _values_ be a new empty List. 1. Let _next_ be *true*. 1. Repeat, while _next_ is not *false* @@ -36781,6 +37339,87 @@

              The Iterator Interface

              + +

              The AsyncIterable Interface

              +

              The AsyncIterable interface includes the properties described in :

              + +

    - Binding object is the global object. It contains global built-in bindings as well as |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| bindings in global code for the associated realm. + Binding object is the global object. It contains global built-in bindings as well as |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, |AsyncGeneratorDeclaration|, and |VariableDeclaration| bindings in global code for the associated realm.
    - Contains bindings for all declarations in global code for the associated realm code except for |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| _bindings_. + Contains bindings for all declarations in global code for the associated realm code except for |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, |AsyncGeneratorDeclaration|, and |VariableDeclaration| _bindings_.
    - The string names bound by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, and |VariableDeclaration| declarations in global code for the associated realm. + The string names bound by |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, |AsyncGeneratorDeclaration|, and |VariableDeclaration| declarations in global code for the associated realm.
    - Determines if the argument identifier has a binding in this Environment Record that was created using a |VariableDeclaration|, |FunctionDeclaration|, |GeneratorDeclaration|, or |AsyncFunctionDeclaration|. + Determines if the argument identifier has a binding in this Environment Record that was created using a |VariableDeclaration|, |FunctionDeclaration|, |GeneratorDeclaration|, |AsyncFunctionDeclaration|, or |AsyncGeneratorDeclaration|.
    + + + + + + + + + + + + +
    PropertyValueRequirements
    `@@asyncIterator`A function that returns an AsyncIterator object.The returned object must conform to the AsyncIterator interface.
    +
    +
    + + +

    The AsyncIterator Interface

    +

    An object that implements the AsyncIterator interface must include the properties in . Such objects may also implement the properties in .

    + + + + + + + + + + + + + + +
    PropertyValueRequirements
    `next`A function that returns a promise for an IteratorResult object. +

    The returned promise, when fulfilled, must fulfill with an object which conforms to the IteratorResult interface. If a previous call to the `next` method of an AsyncIterator has returned a promise for an IteratorResult object whose `done` property is *true*, then all subsequent calls to the `next` method of that object should also return a promise for an IteratorResult object whose `done` property is *true*. However, this requirement is not enforced.

    + +

    Additionally, the IteratorResult object that serves as a fulfillment value should have a `value` property whose value is not a promise (or "thenable"). However, this requirement is also not enforced.

    +
    +
    + +

    Arguments may be passed to the next function but their interpretation and validity is dependent upon the target AsyncIterator. The `for`-`await`-`of` statement and other common users of AsyncIterators do not pass any arguments, so AsyncIterator objects that expect to be used in such a manner must be prepared to deal with being called with no arguments.

    +
    + + + + + + + + + + + + + + + + + + + +
    PropertyValueRequirements
    `return`A function that returns a promise for an IteratorResult object. +

    The returned promise, when fulfilled, must fulfill with an object which conforms to the IteratorResult interface. Invoking this method notifies the AsyncIterator object that the caller does not intend to make any more `next` method calls to the AsyncIterator. The returned promise will fulfill with an IteratorResult object which will typically have a `done` property whose value is *true*, and a `value` property with the value passed as the argument of the `return` method. However, this requirement is not enforced.

    + +

    Additionally, the IteratorResult object that serves as a fulfillment value should have a `value` property whose value is not a promise (or "thenable"). If the argument value is used in the typical manner, then if it is a rejected promise, a promise rejected with the same reason should be returned; if it is a fulfilled promise, then its fulfillment value should be used as the `value` property of the returned promise's IteratorResult object fulfillment value. However, these requirements are also not enforced.

    +
    `throw`A function that returns a promise for an IteratorResult object. +

    The returned promise, when fulfilled, must fulfill with an object which conforms to the IteratorResult interface. Invoking this method notifies the AsyncIterator object that the caller has detected an error condition. The argument may be used to identify the error condition and typically will be an exception object. A typical response is to return a rejected promise which rejects with the value passed as the argument.

    + +

    If the returned promise is fulfilled, the IteratorResult fulfillment value will typically have a `done` property whose value is *true*. Additionally, it should have a `value` property whose value is not a promise (or "thenable"), but this requirement is not enforced.

    +
    +
    + +

    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.

    +
    +
    +

    The IteratorResult Interface

    @@ -36847,6 +37486,190 @@

    %IteratorPrototype% [ @@iterator ] ( )

    The value of the `name` property of this function is `"[Symbol.iterator]"`.

    + + +

    The %AsyncIteratorPrototype% Object

    +

    The value of the [[Prototype]] internal slot of the %AsyncIteratorPrototype% object is the intrinsic object %ObjectPrototype%. The %AsyncIteratorPrototype% object is an ordinary object. The initial value of the [[Extensible]] internal slot of the %AsyncIteratorPrototype% object is *true*.

    + +

    All objects defined in this specification that implement the AsyncIterator interface also inherit from %AsyncIteratorPrototype%. ECMAScript code may also define objects that inherit from %AsyncIteratorPrototype%.The %AsyncIteratorPrototype% object provides a place where additional methods that are applicable to all async iterator objects may be added.

    +
    + + +

    %AsyncIteratorPrototype% [ @@asyncIterator ] ( )

    +

    The following steps are taken:

    + + 1. Return the *this* value. + +

    The value of the `name` property of this function is `"[Symbol.asyncIterator]"`.

    +
    +
    + + +

    Async-from-Sync Iterator Objects

    +

    An Async-from-Sync Iterator object is an async iterator that adapts a specific synchronous iterator. There is not a named constructor for Async-from-Sync Iterator objects. Instead, Async-from-Sync iterator objects are created by the CreateAsyncFromSyncIterator abstract operation as needed.

    + + +

    CreateAsyncFromSyncIterator ( _syncIteratorRecord_ )

    +

    The abstract operation CreateAsyncFromSyncIterator is used to create an async iterator Record from a synchronous iterator Record. It performs the following steps:

    + + 1. Let _asyncIterator_ be ! ObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »). + 1. Set _asyncIterator_.[[SyncIteratorRecord]] to _syncIteratorRecord_. + 1. Return ? GetIterator(_asyncIterator_, ~async~). + +
    + + +

    The %AsyncFromSyncIteratorPrototype% Object

    +

    All Async-from-Sync Iterator Objects inherit properties from the %AsyncFromSyncIteratorPrototype% intrinsic object. The %AsyncFromSyncIteratorPrototype% object is an ordinary object and its [[Prototype]] internal slot is the %AsyncIteratorPrototype% intrinsic object. In addition, %AsyncFromSyncIteratorPrototype% has the following properties:

    + + +

    %AsyncFromSyncIteratorPrototype%.next ( _value_ )

    + + 1. Let _O_ be the *this* value. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. If Type(_O_) is not Object, or if _O_ does not have a [[SyncIteratorRecord]] internal slot, then + 1. Let _invalidIteratorError_ be a newly created *TypeError* object. + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _invalidIteratorError_ »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _syncIteratorRecord_ be _O_.[[SyncIteratorRecord]]. + 1. Let _nextResult_ be IteratorNext(_syncIteratorRecord_, _value_). + 1. IfAbruptRejectPromise(_nextResult_, _promiseCapability_). + 1. Let _nextDone_ be IteratorComplete(_nextResult_). + 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 _realm_ be the current Realm Record. + 1. Let _steps_ be the algorithm steps defined in . + 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _steps_, %FunctionPrototype%, « [[Done]] »). + 1. Set _onFulfilled_.[[Done]] to _nextDone_. + 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Return _promiseCapability_.[[Promise]]. + +
    + + +

    %AsyncFromSyncIteratorPrototype%.return ( _value_ )

    + + + 1. Let _O_ be the *this* value. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. If Type(_O_) is not Object, or if _O_ does not have a [[SyncIteratorRecord]] internal slot, then + 1. Let _invalidIteratorError_ be a newly created *TypeError* object. + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _invalidIteratorError_ »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _syncIterator_ be _O_.[[SyncIteratorRecord]].[[Iterator]]. + 1. Let _return_ be GetMethod(_syncIterator_, `"return"`). + 1. IfAbruptRejectPromise(_return_, _promiseCapability_). + 1. If _return_ is *undefined*, then + 1. Let _iterResult_ be ! CreateIterResultObject(_value_, *true*). + 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _iterResult_ »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _returnResult_ be Call(_return_, _syncIterator_, « _value_ »). + 1. IfAbruptRejectPromise(_returnResult_, _promiseCapability_). + 1. If Type(_returnResult_) is not Object, then + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _returnDone_ be IteratorComplete(_returnResult_). + 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 _realm_ be the current Realm Record. + 1. Let _steps_ be the algorithm steps defined in . + 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _steps_, %FunctionPrototype%, « [[Done]] »). + 1. Set _onFulfilled_.[[Done]] to _returnDone_. + 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Return _promiseCapability_.[[Promise]]. + +
    + + +

    %AsyncFromSyncIteratorPrototype%.throw ( _value_ )

    + + + 1. Let _O_ be the *this* value. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. If Type(_O_) is not Object, or if _O_ does not have a [[SyncIteratorRecord]] internal slot, then + 1. Let _invalidIteratorError_ be a newly created *TypeError* object. + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _invalidIteratorError_ »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _syncIterator_ be _O_.[[SyncIteratorRecord]].[[Iterator]]. + 1. Let _throw_ be GetMethod(_syncIterator_, `"throw"`). + 1. IfAbruptRejectPromise(_throw_, _promiseCapability_). + 1. If _throw_ is *undefined*, then + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _value_ »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _throwResult_ be Call(_throw_, _syncIterator_, « _value_ »). + 1. IfAbruptRejectPromise(_throwResult_, _promiseCapability_). + 1. If Type(_throwResult_) is not Object, then + 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »). + 1. Return _promiseCapability_.[[Promise]]. + 1. Let _throwDone_ be IteratorComplete(_throwResult_). + 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 _realm_ be the current Realm Record. + 1. Let _steps_ be the algorithm steps defined in . + 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _steps_, %FunctionPrototype%, « [[Done]] »). + 1. Set _onFulfilled_.[[Done]] to _throwDone_. + 1. Perform ! PerformPromiseThen(_valueWrapperCapability_.[[Promise]], _onFulfilled_, *undefined*, _promiseCapability_). + 1. Return _promiseCapability_.[[Promise]]. + +
    + + +

    %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]]). + +
    +
    + + +

    Properties of Async-from-Sync Iterator Instances

    +

    Async-from-Sync Iterator instances are ordinary objects that inherit properties from the %AsyncFromSyncIteratorPrototype% intrinsic object. Async-from-Sync Iterator instances are initially created with the internal slots listed in .

    + + + + + + + + + + + + + + +
    + Internal Slot + + Description +
    + [[SyncIteratorRecord]] + + A Record, of the type returned by GetIterator, representing the original synchronous iterator which is being adapted. +
    +
    +
    +
    @@ -36959,6 +37782,100 @@

    prototype

    + +

    AsyncGeneratorFunction Objects

    +

    AsyncGeneratorFunction objects are functions that are usually created by evaluating |AsyncGeneratorDeclaration|, |AsyncGeneratorExpression|, and |AsyncGeneratorMethod| syntactic productions. They may also be created by calling the %AsyncGeneratorFunction% intrinsic.

    + + +

    The AsyncGeneratorFunction Constructor

    +

    The `AsyncGeneratorFunction` constructor is the %AsyncGeneratorFunction% intrinsic. When `AsyncGeneratorFunction` is called as a function rather than as a constructor, it creates and initializes a new AsyncGeneratorFunction object. Thus the function call `AsyncGeneratorFunction (...)` is equivalent to the object creation expression `new AsyncGeneratorFunction (...)` with the same arguments.

    +

    `AsyncGeneratorFunction` is designed to be subclassable. It may be used as the value of an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified `AsyncGeneratorFunction` behaviour must include a `super` call to the `AsyncGeneratorFunction` constructor to create and initialize subclass instances with the internal slots necessary for built-in AsyncGeneratorFunction behaviour. All ECMAScript syntactic forms for defining async generator function objects create direct instances of `AsyncGeneratorFunction`. There is no syntactic means to create instances of `AsyncGeneratorFunction` subclasses.

    + + +

    AsyncGeneratorFunction ( _p1_, _p2_, ..., _pn_, _body_ )

    +

    The last argument specifies the body (executable code) of an async generator function; any preceding arguments specify formal parameters.

    +

    When the `AsyncGeneratorFunction` function is called with some arguments _p1_, _p2_, … , _pn_, _body_ (where _n_ might be 0, that is, there are no "_p_" arguments, and where _body_ might also not be provided), the following steps are taken:

    + + 1. Let _C_ be the active function object. + 1. Let _args_ be the _argumentsList_ that was passed to this function by [[Call]] or [[Construct]]. + 1. Return ? CreateDynamicFunction(_C_, NewTarget, `"async generator"`, _args_). + + +

    See NOTE for .

    +
    +
    +
    + + +

    Properties of the AsyncGeneratorFunction Constructor

    +

    The `AsyncGeneratorFunction` constructor is a standard built-in function object that inherits from the `Function` constructor. The value of the [[Prototype]] internal slot of the `AsyncGeneratorFunction` constructor is the intrinsic object %Function%.

    +

    The value of the [[Extensible]] internal slot of the AsyncGeneratorFunction constructor is *true*.

    +

    The value of the `name` property of the AsyncGeneratorFunction is `"AsyncGeneratorFunction"`.

    +

    The `AsyncGeneratorFunction` constructor has the following properties:

    + + +

    AsyncGeneratorFunction.length

    +

    This is a data property with a value of 1. This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.

    +
    + + +

    AsyncGeneratorFunction.prototype

    +

    The initial value of `AsyncGeneratorFunction.prototype` is the intrinsic object %AsyncGenerator%.

    +

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

    +
    +
    + + +

    Properties of the AsyncGeneratorFunction Prototype Object

    +

    The AsyncGeneratorFunction prototype object is an ordinary object. It is not a function object and does not have an [[ECMAScriptCode]] internal slot or any other of the internal slots listed in or . In addition to being the value of the prototype property of the %AsyncGeneratorFunction% intrinsic, it is the %AsyncGenerator% intrinsic.

    +

    The value of the [[Prototype]] internal slot of the AsyncGeneratorFunction prototype object is the %FunctionPrototype% intrinsic object. The initial value of the [[Extensible]] internal slot of the AsyncGeneratorFunction prototype object is *true*.

    + + +

    AsyncGeneratorFunction.prototype.constructor

    +

    The initial value of `AsyncGeneratorFunction.prototype.constructor` is the intrinsic object %AsyncGeneratorFunction%.

    +

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

    +
    + + +

    AsyncGeneratorFunction.prototype.prototype

    +

    The value of `AsyncGeneratorFunction.prototype.prototype` is the %AsyncGeneratorPrototype% intrinsic object.

    +

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

    +
    + + +

    AsyncGeneratorFunction.prototype [ @@toStringTag ]

    +

    The initial value of the @@toStringTag property is the String value `"AsyncGeneratorFunction"`.

    +

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

    +
    +
    + + +

    AsyncGeneratorFunction Instances

    +

    Every AsyncGeneratorFunction instance is an ECMAScript function object and has the internal slots listed in . The value of the [[FunctionKind]] internal slot for all such instances is `"generator"`.

    +

    Each AsyncGeneratorFunction instance has the following own properties:

    + + +

    length

    +

    The value of the `length` property is an integer that indicates the typical number of arguments expected by the AsyncGeneratorFunction. However, the language permits the function to be invoked with some other number of arguments. The behaviour of an AsyncGeneratorFunction when invoked on a number of arguments other than the number specified by its `length` property depends on the function.

    +

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

    +
    + + +

    name

    +

    The specification for the `name` property of Function instances given in also applies to AsyncGeneratorFunction instances.

    +
    + + +

    prototype

    +

    Whenever an AsyncGeneratorFunction instance is created another ordinary object is also created and is the initial value of the async generator function's `prototype` property. The value of the prototype property is used to initialize the [[Prototype]] internal slot of a newly created AsyncGenerator object when the generator function object is invoked using [[Call]].

    +

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

    + +

    Unlike function instances, the object that is the value of the an AsyncGeneratorFunction's `prototype` property does not have a `constructor` property whose value is the AsyncGeneratorFunction instance.

    +
    +
    +
    +
    +

    Generator Objects

    @@ -37145,6 +38062,17 @@

    GeneratorResumeAbrupt ( _generator_, _abruptCompletion_ )

    + +

    GetGeneratorKind ( )

    + + 1. Let _genContext_ be the running execution context. + 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 ~sync~. + +
    +

    GeneratorYield ( _iterNextObj_ )

    @@ -37154,6 +38082,7 @@

    GeneratorYield ( _iterNextObj_ )

    1. Let _genContext_ be the running execution context. 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 ~sync~. 1. Set _generator_.[[GeneratorState]] 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: @@ -37166,6 +38095,294 @@

    GeneratorYield ( _iterNextObj_ )

    + +

    AsyncGenerator Objects

    +

    An AsyncGenerator object is an instance of an async generator function and conforms to both the AsyncIterator and AsyncIterable interfaces.

    + +

    AsyncGenerator instances directly inherit properties from the object that is the value of the `prototype` property of the AsyncGenerator function that created the instance. AsyncGenerator instances indirectly inherit properties from the AsyncGenerator Prototype intrinsic, %AsyncGeneratorPrototype%.

    + + +

    Properties of AsyncGenerator Prototype

    +

    The AsyncGenerator prototype object is the %AsyncGeneratorPrototype% intrinsic. It is also the initial value of the `prototype` property of the %AsyncGenerator% intrinsic (the AsyncGeneratorFunction.prototype).

    +

    The AsyncGenerator prototype is an ordinary object. It is not an AsyncGenerator instance and does not have an [[AsyncGeneratorState]] internal slot.

    +

    The value of the [[Prototype]] internal slot of the AsyncGenerator prototype object is the intrinsic object %AsyncIteratorPrototype%. The initial value of the [[Extensible]] internal slot of the AsyncGenerator prototype object is *true*.

    +

    All AsyncGenerator instances indirectly inherit properties of the AsyncGenerator prototype object.

    + + +

    AsyncGenerator.prototype.constructor

    +

    The initial value of `AsyncGenerator.prototype.constructor` is the intrinsic object %AsyncGenerator%.

    +

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

    +
    + + +

    AsyncGenerator.prototype.next ( _value_ )

    + + 1. Let _generator_ be the *this* value. + 1. Let _completion_ be NormalCompletion(_value_). + 1. Return ! AsyncGeneratorEnqueue(_generator_, _completion_). + +
    + + +

    AsyncGenerator.prototype.return ( _value_ )

    + + 1. Let _generator_ be the *this* value. + 1. Let _completion_ be Completion{[[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~}. + 1. Return ! AsyncGeneratorEnqueue(_generator_, _completion_). + +
    + + +

    AsyncGenerator.prototype.throw ( _exception_ )

    + + 1. Let _generator_ be the *this* value. + 1. Let _completion_ be Completion{[[Type]]: ~throw~, [[Value]]: _exception_, [[Target]]: ~empty~}. + 1. Return ! AsyncGeneratorEnqueue(_generator_, _completion_). + +
    + + +

    AsyncGenerator.prototype [ @@toStringTag ]

    +

    The initial value of the @@toStringTag property is the String value `"AsyncGenerator"`.

    +

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

    +
    + +
    + + +

    Properties of AsyncGenerator Instances

    +

    AsyncGenerator instances are initially created with the internal slots described below:

    + + + + + + + + + + + + + + + + + + + + +
    Internal SlotDescription
    [[AsyncGeneratorState]]The current execution state of the async generator. The possible values are: *undefined*, `"suspendedStart"`, `"suspendedYield"`, `"executing"`, `"awaiting-return"`, and `"completed"`.
    [[AsyncGeneratorContext]]The execution context that is used when executing the code of this async generator.
    [[AsyncGeneratorQueue]]A List of AsyncGeneratorRequest records which represent requests to resume the async generator.
    +
    +
    + + +

    AsyncGenerator Abstract Operations

    + +

    AsyncGeneratorRequest Records

    +

    The AsyncGeneratorRequest is a Record value used to store information about how an async generator should be resumed and contains capabilities for fulfilling or rejecting the corresponding promise.

    +

    They have the following fields:

    + + + + + + + + + + + + + + + + + + + +
    Field NameValueMeaning
    [[Completion]]A Completion recordThe completion which should be used to resume the async generator.
    [[Capability]]A PromiseCapability recordThe promise capabilities associated with this request.
    +
    +
    + + +

    AsyncGeneratorStart ( _generator_, _generatorBody_ )

    + + 1. Assert: _generator_ is an AsyncGenerator instance. + 1. Assert: _generator_.[[AsyncGeneratorState]] is *undefined*. + 1. Let _genContext_ be the running execution context. + 1. Set the Generator component of _genContext_ to _generator_. + 1. Set the code evaluation state of _genContext_ such that when evaluation is resumed for that execution context the following steps will be performed: + 1. Let _result_ be the result of evaluating _generatorBody_. + 1. Assert: If we return here, the async generator either threw an exception or performed either an implicit or explicit return. + 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 _generator_.[[AsyncGeneratorState]] to `"completed"`. + 1. If _result_ is a normal completion, let _resultValue_ be *undefined*. + 1. Else, + 1. Let _resultValue_ be _result_.[[Value]]. + 1. If _result_.[[Type]] is not ~return~, then + 1. Return ! AsyncGeneratorReject(_generator_, _resultValue_). + 1. Return ! AsyncGeneratorResolve(_generator_, _resultValue_, *true*). + 1. Set _generator_.[[AsyncGeneratorContext]] to _genContext_. + 1. Set _generator_.[[AsyncGeneratorState]] to `"suspendedStart"`. + 1. Set _generator_.[[AsyncGeneratorQueue]] to a new empty List. + 1. Return *undefined*. + +
    + + +

    AsyncGeneratorResolve ( _generator_, _value_, _done_ )

    + + 1. Assert: _generator_ is an AsyncGenerator instance. + 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]]. + 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 _iteratorResult_ be ! CreateIterResultObject(_value_, _done_). + 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _iteratorResult_ »). + 1. Perform ! AsyncGeneratorResumeNext(_generator_). + 1. Return *undefined*. + +
    + + +

    AsyncGeneratorReject ( _generator_, _exception_ )

    + + 1. Assert: _generator_ is an AsyncGenerator instance. + 1. Let _queue_ be _generator_.[[AsyncGeneratorQueue]]. + 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. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _exception_ »). + 1. Perform ! AsyncGeneratorResumeNext(_generator_). + 1. Return *undefined*. + +
    + + +

    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_. + 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 _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _completion_.[[Value]] »). + 1. Let _realm_ be the current Realm Record. + 1. Let _stepsFulfilled_ be the algorithm steps defined in . + 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _stepsFulfilled_, %FunctionPrototype%, « [[Generator]] »). + 1. Set _onFulfilled_.[[Generator]] to _generator_. + 1. Let _stepsRejected_ be the algorithm steps defined in . + 1. Let _onRejected_ be CreateBuiltinFunction(_realm_, _stepsRejected_, %FunctionPrototype%, « [[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. 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. Let _genContext_ be _generator_.[[AsyncGeneratorContext]]. + 1. Let _callerContext_ be the running execution context. + 1. Suspend _callerContext_. + 1. Set _generator_.[[AsyncGeneratorState]] to `"executing"`. + 1. Push _genContext_ onto the execution context stack; _genContext_ is now the running execution context. + 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*. + + + +

    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.

    +
    +
    + + +

    AsyncGeneratorEnqueue ( _generator_, _completion_ )

    + + 1. Assert: _completion_ is a Completion Record. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. If Type(_generator_) is not Object, or if _generator_ does not have an [[AsyncGeneratorState]] internal slot, 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]]. + +
    + + +

    AsyncGeneratorYield ( _value_ )

    +

    The abstract operation AsyncGeneratorYield with argument _value_ performs the following steps:

    + + 1. Let _genContext_ be the running execution context. + 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. 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_. + +
    +
    +
    +

    Promise Objects

    @@ -38095,65 +39312,10 @@

    AsyncFunctionStart ( _promiseCapability_, _asyncFunctionBody_ )

    1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. 1. Resume the suspended evaluation of _asyncContext_. Let _result_ be the value returned by the resumed computation. 1. Assert: When we return here, _asyncContext_ has already been removed from the execution context stack and _runningContext_ is the currently running execution context. - 1. Assert: _result_ is a normal completion with a value of *undefined*. The possible sources of completion values are AsyncFunctionAwait or, if the async function doesn't await anything, the step 3.g above. + 1. Assert: _result_ is a normal completion with a value of *undefined*. The possible sources of completion values are Await or, if the async function doesn't await anything, the step 3.g above. 1. Return.
    - - -

    AsyncFunctionAwait ( _value_ )

    - - 1. Let _asyncContext_ be the running execution context. - 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). - 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _value_ »). - 1. Let _realm_ be the current Realm Record. - 1. Let _steps_ be the algorithm steps defined in . - 1. Let _onFulfilled_ be CreateBuiltinFunction(_realm_, _steps_, %FunctionPrototype%, « [[AsyncContext]] »). - 1. Let _steps_ be the algorithm steps defined in . - 1. Let _onRejected_ be CreateBuiltinFunction(_realm_, _steps_, %FunctionPrototype%, « [[AsyncContext]] »). - 1. Set _onFulfilled_.[[AsyncContext]] to _asyncContext_. - 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. 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 _resumptionValue_ the following steps will be performed: - 1. Return _resumptionValue_. - 1. Return. - - - The return value of this abstract operation is unused. The interesting return is that of _resumptionValue_ being returned to the |AwaitExpression| that originally called this abstract operation. -
    - - -

    AsyncFunction Awaited Fulfilled

    -

    An AsyncFunction Awaited Fulfilled function is an anonymous built-in function that has an [[AsyncContext]] internal slot. The value of the [[AsyncContext]] internal slot is the execution context that will be restored when the function is called.

    -

    When an AsyncFunction Awaited Fulfilled function _F_ is called with argument _value_, the following steps are taken:

    - - 1. Let _asyncContext_ be _F_.[[AsyncContext]]. - 1. Let _prevContext_ be the running execution context. - 1. Suspend _prevContext_. - 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. - 1. Resume the suspended evaluation of _asyncContext_ using NormalCompletion(_value_) as the result of the operation that suspended it. Let _result_ be the value returned by the resumed computation. - 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. - 1. Return Completion(_result_). - -
    - - -

    AsyncFunction Awaited Rejected

    -

    An AsyncFunction Awaited Rejected function is an anonymous built-in function that has an [[AsyncContext]] internal slot. The value of the [[AsyncContext]] internal slot is the execution context that will be restored when the function is called.

    -

    When an AsyncFunction Awaited Rejected function _F_ is called with argument _reason_, the following steps are taken:

    - - 1. Let _asyncContext_ be _F_.[[AsyncContext]]. - 1. Let _prevContext_ be the running execution context. - 1. Suspend _prevContext_. - 1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context. - 1. Resume the suspended evaluation of _asyncContext_ using Completion{[[Type]]: ~throw~, [[Value]]: _reason_, [[Target]]: ~empty~} as the result of the operation that suspended it. Let _result_ be the value returned by the resumed computation. - 1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context. - 1. Return Completion(_result_). - -