Stage 3 Draft / April 12, 2021

Class features proposal

Introduction

This document attempts to integrate the class fields, private methods and accessors, and static class features proposals into a single, coherent, orthogonal whole. This document was generated from PR #1668 using ECMA262 Compare tool.

6.1.7.2 Object Internal Methods and Internal Slots

The actual semantics of objects, in ECMAScript, are specified via algorithms called internal methods. Each object in an ECMAScript engine is associated with a set of internal methods that defines its runtime behaviour. These internal methods are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. However, each object within an implementation of ECMAScript must behave as specified by the internal methods associated with it. The exact manner in which this is accomplished is determined by the implementation.

Internal method names are polymorphic. This means that different object values may perform different algorithms when a common internal method name is invoked upon them. That actual object upon which an internal method is invoked is the “target” of the invocation. If, at runtime, the implementation of an algorithm attempts to use an internal method of an object that the object does not support, a TypeError exception is thrown.

Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific internal slot specification, such state may consist of values of any ECMAScript language type or of specific ECMAScript specification type values. Unless explicitly specified otherwise, internal slots are allocated as part of the process of creating an object and may not be dynamically added to an object. Unless specified otherwise, the initial value of an internal slot is the value undefined. Various algorithms within this specification create objects that have internal slots. However, the ECMAScript language provides no direct way to associate internal slots with an object.

All objects have an internal slot named [[PrivateFields]], which is a List of PrivateField Records. This List represents the values of the private fields for the object. Initially, it is an empty List.

All objects have an internal slot named [[PrivateBrands]], which is a List of ECMAScript values which are used for checking to see if an object supports a private method or accessor. The entries in the list correspond to the "original prototype" (or, in the case of static methods, the "original constructor") which contained the private method or accessor. Initially, it is an empty List.

Note

Although this specification uses logic of a [[PrivateBrands]] List which is held per-instance, the use of this list obeys certain invariants:

  • Nothing is removed from the list; things are only added to the end.
  • There is no way to distinguish different copies of the list.
  • The list is mutable, but there are never any references to it outside of the particular object which holds it, so additions can be thought of as replacing the internal slot with another list which contains the new element.

Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[ ]].

Table 6 summarizes the essential internal methods used by this specification that are applicable to all objects created or manipulated by ECMAScript code. Every object must have algorithms for all of the essential internal methods. However, all objects do not necessarily use the same algorithms for those methods.

An ordinary object is an object that satisfies all of the following criteria:

  • For the internal methods listed in Table 6, the object uses those defined in 10.1.
  • If the object has a [[Call]] internal method, it uses the one defined in 10.2.1.
  • If the object has a [[Construct]] internal method, it uses the one defined in 10.2.2.

An exotic object is an object that is not an ordinary object.

This specification recognizes different kinds of exotic objects by those objects' internal methods. An object that is behaviourally equivalent to a particular kind of exotic object (such as an Array exotic object or a bound function exotic object), but does not have the same collection of internal methods specified for that kind, is not recognized as that kind of exotic object.

The “Signature” column of Table 6 and other similar tables describes the invocation pattern for each internal method. The invocation pattern always includes a parenthesized list of descriptive parameter names. If a parameter name is the same as an ECMAScript type name then the name describes the required type of the parameter value. If an internal method explicitly returns a value, its parameter list is followed by the symbol “→” and the type name of the returned value. The type names used in signatures refer to the types defined in clause 6 augmented by the following additional names. “any” means the value may be any ECMAScript language type.

In addition to its parameters, an internal method always has access to the object that is the target of the method invocation.

An internal method implicitly returns a Completion Record, either a normal completion that wraps a value of the return type shown in its invocation pattern, or a throw completion.

Table 6: Essential Internal Methods
Internal Method Signature Description
[[GetPrototypeOf]] ( ) Object | Null Determine the object that provides inherited properties for this object. A null value indicates that there are no inherited properties.
[[SetPrototypeOf]] (Object | Null) Boolean Associate this object with another object that provides inherited properties. Passing null indicates that there are no inherited properties. Returns true indicating that the operation was completed successfully or false indicating that the operation was not successful.
[[IsExtensible]] ( ) Boolean Determine whether it is permitted to add additional properties to this object.
[[PreventExtensions]] ( ) Boolean Control whether new properties may be added to this object. Returns true if the operation was successful or false if the operation was unsuccessful.
[[GetOwnProperty]] (propertyKey) Undefined | Property Descriptor Return a Property Descriptor for the own property of this object whose key is propertyKey, or undefined if no such property exists.
[[DefineOwnProperty]] (propertyKey, PropertyDescriptor) Boolean Create or alter the own property, whose key is propertyKey, to have the state described by PropertyDescriptor. Return true if that property was successfully created/updated or false if the property could not be created or updated.
[[HasProperty]] (propertyKey) Boolean Return a Boolean value indicating whether this object already has either an own or inherited property whose key is propertyKey.
[[Get]] (propertyKey, Receiver) any Return the value of the property whose key is propertyKey from this object. If any ECMAScript code must be executed to retrieve the property value, Receiver is used as the this value when evaluating the code.
[[Set]] (propertyKey, value, Receiver) Boolean Set the value of the property whose key is propertyKey to value. If any ECMAScript code must be executed to set the property value, Receiver is used as the this value when evaluating the code. Returns true if the property value was set or false if it could not be set.
[[Delete]] (propertyKey) Boolean Remove the own property whose key is propertyKey from this object. Return false if the property was not deleted and is still present. Return true if the property was deleted or is not present.
[[OwnPropertyKeys]] ( ) List of propertyKey Return a List whose elements are all of the own property keys for the object.

Table 7 summarizes additional essential internal methods that are supported by objects that may be called as functions. A function object is an object that supports the [[Call]] internal method. A constructor is an object that supports the [[Construct]] internal method. Every object that supports [[Construct]] must support [[Call]]; that is, every constructor must be a function object. Therefore, a constructor may also be referred to as a constructor function or constructor function object.

Table 7: Additional Essential Internal Methods of Function Objects
Internal Method Signature Description
[[Call]] (any, a List of any) any Executes code associated with this object. Invoked via a function call expression. The arguments to the internal method are a this value and a List whose elements are the arguments passed to the function by a call expression. Objects that implement this internal method are callable.
[[Construct]] (a List of any, Object) Object Creates an object. Invoked via the new operator or a super call. The first argument to the internal method is a List whose elements are the arguments of the constructor invocation or the super call. The second argument is the object to which the new operator was initially applied. Objects that implement this internal method are called constructors. A function object is not necessarily a constructor and such non-constructor function objects do not have a [[Construct]] internal method.

The semantics of the essential internal methods for ordinary objects and standard exotic objects are specified in clause 10. If any specified use of an internal method of an exotic object is not supported by an implementation, that usage must throw a TypeError exception when attempted.

6.2 ECMAScript Specification Types

A specification type corresponds to meta-values that are used within algorithms to describe the semantics of ECMAScript language constructs and ECMAScript language types. The specification types include Reference, List, Completion, Property Descriptor, Environment Record, Abstract Closure, and Data Block. Specification type values are specification artefacts that do not necessarily correspond to any specific entity within an ECMAScript implementation. Specification type values may be used to describe intermediate results of ECMAScript expression evaluation but such values cannot be stored as properties of objects or values of ECMAScript language variables.

6.2.4 The Reference Record Specification Type

The Reference Record type is used to explain the behaviour of such operators as delete, typeof, the assignment operators, the super keyword and other language features. For example, the left-hand operand of an assignment is expected to produce a Reference Record.

A Reference Record is a resolved name or property binding; its fields are defined by Table 10.

Table 10: Reference Record Fields
Field NameValueMeaning
[[Base]] One of: The value or Environment Record which holds the binding. A [[Base]] of unresolvable indicates that the binding could not be resolved.
[[ReferencedName]]String or String, Symbol, or Private NameThe name of the binding. Always a String if [[Base]] value is an Environment Record.
[[Strict]]Booleantrue if the Reference Record originated in strict mode code, false otherwise.
[[ThisValue]]any ECMAScript language value or emptyIf not empty, the Reference Record represents a property binding that was expressed using the super keyword; it is called a Super Reference Record and its [[Base]] value will never be an Environment Record. In that case, the [[ThisValue]] field holds the this value at the time the Reference Record was created.

The following abstract operations are used in this specification to operate upon ReferencesReference Records:

6.2.4.4 IsPrivateReference ( V )

  1. 1. Assert: V is a Reference Record.
  2. 2. If V.[[ReferencedName]] is a Private Name, return true; otherwise return false.

6.2.4.46.2.4.5 GetValue ( V )

The abstract operation GetValue takes argument V. It performs the following steps when called:

  1. 1. ReturnIfAbrupt(V).
  2. 2. If V is not a Reference Record, return V.
  3. 3. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
  4. 4. If IsPropertyReference(V) is true, then
    1. a. Let baseObj be ! ToObject(V.[[Base]]).
    2. b. If IsPrivateReference(V) is true, then
      1. i. Return ? PrivateFieldGet(V.[[ReferencedName]], baseObj).
    3. bc. Return ? baseObj.[[Get]](V.[[ReferencedName]], GetThisValue(V)).
  5. 5. Else,
    1. a. Let base be V.[[Base]].
    2. b. Assert: base is an Environment Record.
    3. c. Return ? base.GetBindingValue(V.[[ReferencedName]], V.[[Strict]]) (see 9.1).
Note

The object that may be created in step 4.a is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might choose to avoid the actual creation of the object.

6.2.4.56.2.4.6 PutValue ( V, W )

The abstract operation PutValue takes arguments V and W. It performs the following steps when called:

  1. 1. ReturnIfAbrupt(V).
  2. 2. ReturnIfAbrupt(W).
  3. 3. If V is not a Reference Record, throw a ReferenceError exception.
  4. 4. If IsUnresolvableReference(V) is true, then
    1. a. If V.[[Strict]] is true, throw a ReferenceError exception.
    2. b. Let globalObj be GetGlobalObject().
    3. c. Return ? Set(globalObj, V.[[ReferencedName]], W, false).
  5. 5. If IsPropertyReference(V) is true, then
    1. a. Let baseObj be ! ToObject(V.[[Base]]).
    2. b. If IsPrivateReference(V) is true, then
      1. i. Return ? PrivateFieldSet(V.[[ReferencedName]], baseObj, W).
    3. bc. Let succeeded be ? baseObj.[[Set]](V.[[ReferencedName]], W, GetThisValue(V)).
    4. cd. If succeeded is false and V.[[Strict]] is true, throw a TypeError exception.
    5. de. Return.
  6. 6. Else,
    1. a. Let base be V.[[Base]].
    2. b. Assert: base is an Environment Record.
    3. c. Return ? base.SetMutableBinding(V.[[ReferencedName]], W, V.[[Strict]]) (see 9.1).
Note

The object that may be created in step 5.a is not accessible outside of the above abstract operation and the ordinary object [[Set]] internal method. An implementation might choose to avoid the actual creation of that object.

6.2.4.76.2.4.8 InitializeReferencedBinding ( V, W )

The abstract operation InitializeReferencedBinding takes arguments V and W. It performs the following steps when called:

  1. 1. ReturnIfAbrupt(V).
  2. 2. ReturnIfAbrupt(W).
  3. 3. Assert: V is a Reference Record.
  4. 4. Assert: IsUnresolvableReference(V) is false.
  5. 5. Let base be V.[[Base]].
  6. 6. Assert: base is an Environment Record.
  7. 7. Return base.InitializeBinding(V.[[ReferencedName]], W).

6.2.4.9 MakePrivateReference ( baseValue, privateIdentifier )

  1. 1. Let env be the running execution context's PrivateEnvironment.
  2. 2. Let privateNameBinding be ! ResolveBinding(privateIdentifier, env).
  3. 3. Let privateName be ? GetValue(privateNameBinding).
  4. 4. Assert: privateIdentifier is a Private Name.
  5. 5. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: privateName, [[Strict]]: true, [[ThisValue]]: empty }.

6.2.8 Data Blocks

The Data Block specification type is used to describe a distinct and mutable sequence of byte-sized (8 bit) numeric values. A byte value is an integer value in the range 0 through 255, inclusive. A Data Block value is created with a fixed number of bytes that each have the initial value 0.

For notational convenience within this specification, an array-like syntax can be used to access the individual bytes of a Data Block value. This notation presents a Data Block value as a 0-origined integer-indexed sequence of bytes. For example, if db is a 5 byte Data Block value then db[2] can be used to access its 3rd byte.

A data block that resides in memory that can be referenced from multiple agents concurrently is designated a Shared Data Block. A Shared Data Block has an identity (for the purposes of equality testing Shared Data Block values) that is address-free: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.

The semantics of Shared Data Blocks is defined using Shared Data Block events by the memory model. Abstract operations below introduce Shared Data Block events and act as the interface between evaluation semantics and the event semantics of the memory model. The events form a candidate execution, on which the memory model acts as a filter. Please consult the memory model for full semantics.

Shared Data Block events are modeled by Records, defined in the memory model.

The following abstract operations are used in this specification to operate upon Data Block values:

6.2.9 The PrivateField Record Specification Type

The PrivateField type is a Record used in the specification of private class fields.

Values of the PrivateField type are Record values whose fields are defined as by Table 11. Such values are referred to as PrivateField Records.

Table 11: PrivateField Record Fields
Field Name Value Meaning
[[PrivateFieldName]] a Private Name The name of the field.
[[PrivateFieldValue]] any ECMAScript language value The value of the field.

6.2.10 The ClassFieldDefinition Record Specification Type

The ClassFieldDefinition type is a Record used in the specification of class fields.

Values of the ClassFieldDefinition type are Record values whose fields are defined as by Table 12. Such values are referred to as ClassFieldDefinition Records.

Table 12: ClassFieldDefinition Record Fields
Field Name Value Meaning
[[Name]] a Private Name, a String value, or a Symbol value. The name of the field.
[[Initializer]] an ECMAScript function object, or empty The initializer of the field, if any.
[[IsAnonymousFunctionDefinition]] Boolean true if there is an Initializer and it is a function definition that does not bind a name, false otherwise.

6.2.11 Private Names

The Private Name specification type is used to describe a globally unique record which represents a private class element (field, method, or accessor). A Private Name may be installed on any ECMAScript object with PrivateFieldAdd, and then read or written using PrivateFieldGet and PrivateFieldSet.

Each Private Name holds the following information:

Table 13: Fields of the Private Name
Field Type Values of the [[Kind]] field for which it is present Description
[[Description]] String All The string value passed to NewPrivateName when creating this Private Name.
[[Kind]] field, method, or accessor All Indicates what the private name is used for.
[[Brand]] Object method or accessor The "original" class of the private method or accessor; checked for in the [[PrivateBrands]] internal slot of instances before access is provided.
[[Value]] Function method The value of the private method.
[[Get]] Function accessor The getter for a private accessor.
[[Set]] Function accessor The setter for a private accessor.

7.3 Operations on Objects

7.3.25 CopyDataProperties ( target, source, excludedItems )

The abstract operation CopyDataProperties takes arguments target, source, and excludedItems. It performs the following steps when called:

  1. 1. Assert: Type(target) is Object.
  2. 2. Assert: excludedItems is a List of property keys.
  3. 3. If source is undefined or null, return target.
  4. 4. Let from be ! ToObject(source).
  5. 5. Let keys be ? from.[[OwnPropertyKeys]]().
  6. 6. For each element nextKey of keys, do
    1. a. Let excluded be false.
    2. b. For each element e of excludedItems, do
      1. i. If SameValue(e, nextKey) is true, then
        1. 1. Set excluded to true.
    3. c. If excluded is false, then
      1. i. Let desc be ? from.[[GetOwnProperty]](nextKey).
      2. ii. If desc is not undefined and desc.[[Enumerable]] is true, then
        1. 1. Let propValue be ? Get(from, nextKey).
        2. 2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
  7. 7. Return target.
Note

The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.

7.3.26 NewPrivateName ( description )

  1. 1. Assert: Type(description) is String.
  2. 2. Return a new unique Private Name whose [[Description]] value is description.

7.3.27 PrivateFieldFind ( P, O )

  1. 1. Assert: P is a Private Name.
  2. 2. Assert: Type(O) is Object.
  3. 3. For each element entry of O.[[PrivateFields]], do
    1. a. If entry.[[PrivateFieldName]] is P, return entry.
  4. 4. Return empty.

7.3.28 PrivateFieldAdd ( P, O, value )

  1. 1. Assert: P is a Private Name.
  2. 2. Assert: Type(O) is Object.
  3. 3. Let entry be ! PrivateFieldFind(P, O).
  4. 4. If entry is not empty, throw a TypeError exception.
  5. 5. Append PrivateField { [[PrivateFieldName]]: P, [[PrivateFieldValue]]: value } to O.[[PrivateFields]].

7.3.29 PrivateFieldGet ( P, O )

  1. 1. Assert: P is a Private Name.
  2. 2. Assert: Type(O) is Object.
  3. 3. If P.[[Kind]] is field, then
    1. a. Let entry be ! PrivateFieldFind(P, O).
    2. b. If entry is empty, throw a TypeError exception.
    3. c. Return entry.[[PrivateFieldValue]].
  4. 4. Perform ? PrivateBrandCheck(O, P).
  5. 5. If P.[[Kind]] is method, then
    1. a. Return P.[[Value]].
  6. 6. Assert: P.[[Kind]] is accessor.
  7. 7. If P does not have a [[Get]] field, throw a TypeError exception.
  8. 8. Let getter be P.[[Get]].
  9. 9. Return ? Call(getter, O).

7.3.30 PrivateFieldSet ( P, O, value )

  1. 1. Assert: P is a Private Name.
  2. 2. Assert: Type(O) is Object.
  3. 3. If P.[[Kind]] is field, then
    1. a. Let entry be ! PrivateFieldFind(P, O).
    2. b. If entry is empty, throw a TypeError exception.
    3. c. Set entry.[[PrivateFieldValue]] to value.
    4. d. Return.
  4. 4. If P.[[Kind]] is method, throw a TypeError exception.
  5. 5. Assert: P.[[Kind]] is accessor.
  6. 6. Perform ? PrivateBrandCheck(O, P).
  7. 7. If P does not have a [[Set]] field, throw a TypeError exception.
  8. 8. Let setter be P.[[Set]].
  9. 9. Perform ? Call(setter, O, « value »).

7.3.31 DefineField ( receiver, fieldRecord )

  1. 1. Assert: Type(receiver) is Object.
  2. 2. Assert: fieldRecord is a ClassFieldDefinition Record.
  3. 3. Let fieldName be fieldRecord.[[Name]].
  4. 4. Let initializer be fieldRecord.[[Initializer]].
  5. 5. If initializer is not empty, then
    1. a. Let initValue be ? Call(initializer, receiver).
  6. 6. Else, let initValue be undefined.
  7. 7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
    1. a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
    2. b. If hasNameProperty is false, perform ! SetFunctionName(initValue, fieldName).
  8. 8. If fieldName is a Private Name, then
    1. a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
  9. 9. Else,
    1. a. Assert: ! IsPropertyKey(fieldName) is true.
    2. b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).

7.3.32 InitializeInstanceElements ( O, constructor )

  1. 1. Assert: Type(O) is Object.
  2. 2. Assert: constructor is an ECMAScript function object.
  3. 3. If constructor.[[PrivateBrand]] is not undefined, then
    1. a. Perform ? PrivateBrandAdd(O, constructor.[[PrivateBrand]]).
  4. 4. Let fields be the value of constructor.[[Fields]].
  5. 5. For each element fieldRecord of fields, do
    1. a. Perform ? DefineField(O, fieldRecord).

7.3.33 PrivateBrandCheck ( O, P )

  1. 1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, then
    1. a. Throw a TypeError exception.

7.3.34 PrivateBrandAdd ( O, brand )

  1. 1. If O.[[PrivateBrands]] contains an entry e such that SameValue(e, brand) is true, then
    1. a. Throw a TypeError exception.
  2. 2. Append brand to O.[[PrivateBrands]].

8.3.2 Static Semantics: IsFunctionDefinition

PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 1. Let expr be the ParenthesizedExpression that is covered by CoverParenthesizedExpressionAndArrowParameterList.
  2. 2. Return IsFunctionDefinition of expr.
PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral RegularExpressionLiteral TemplateLiteral MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression AwaitExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression LogicalANDExpression : LogicalANDExpression && BitwiseORExpression LogicalORExpression : LogicalORExpression || LogicalANDExpression CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression AssignmentExpression : YieldExpression LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression Expression : Expression , AssignmentExpression
  1. 1. Return false.
AssignmentExpression : ArrowFunction AsyncArrowFunction FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody } ClassExpression : class BindingIdentifieropt ClassTail
  1. 1. Return true.

8.3.4 Static Semantics: IsIdentifierRef

PrimaryExpression : IdentifierReference
  1. 1. Return true.
PrimaryExpression : this Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral CoverParenthesizedExpressionAndArrowParameterList MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression
  1. 1. Return false.

8.4.2 Static Semantics: ComputedPropertyContains

With parameter symbol.

PropertyName : LiteralPropertyName
  1. 1. Return false.
PropertyName : ComputedPropertyName
  1. 1. Return the result of ComputedPropertyName Contains symbol.
MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody } MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Return the result of ComputedPropertyContains for PropertyNameClassElementName with argument symbol.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. Return the result of ComputedPropertyContains for PropertyNameClassElementName with argument symbol.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. Return the result of ComputedPropertyContains for PropertyNameClassElementName with argument symbol.
ClassElementList : ClassElementList ClassElement
  1. 1. Let inList be ComputedPropertyContains of ClassElementList with argument symbol.
  2. 2. If inList is true, return true.
  3. 3. Return the result of ComputedPropertyContains for ClassElement with argument symbol.
ClassElement : ;
  1. 1. Return false.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. Return the result of ComputedPropertyContains for PropertyNameClassElementName with argument symbol.
FieldDefinition : ClassElementName Initializeropt
  1. 1. Return the result of ComputedPropertyContains for ClassElementName with argument symbol.

8.5.1 Runtime Semantics: InstantiateFunctionObject

With parameter parameters scope and privateScope.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody }
  1. 1. Return ? InstantiateOrdinaryFunctionObject of FunctionDeclaration with argument arguments scope and privateScope.
GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody }
  1. 1. Return ? InstantiateGeneratorFunctionObject of GeneratorDeclaration with argument arguments scope and privateScope.
AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 1. Return ? InstantiateAsyncGeneratorFunctionObject of AsyncGeneratorDeclaration with argument arguments scope and privateScope.
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody }
  1. 1. Return ? InstantiateAsyncFunctionObject of AsyncFunctionDeclaration with argument arguments scope and privateScope.

8.5.4 Static Semantics: AssignmentTargetType

IdentifierReference : Identifier
  1. 1. If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return invalid.
  2. 2. Return simple.
IdentifierReference : yield await CallExpression : CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MemberExpression . PrivateIdentifier
  1. 1. Return simple.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 1. Let expr be the ParenthesizedExpression that is covered by CoverParenthesizedExpressionAndArrowParameterList.
  2. 2. Return AssignmentTargetType of expr.
PrimaryExpression : this Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral CallExpression : CoverCallExpressionAndAsyncArrowHead SuperCall ImportCall CallExpression Arguments CallExpression TemplateLiteral NewExpression : new NewExpression MemberExpression : MemberExpression TemplateLiteral new MemberExpression Arguments NewTarget : new . target ImportMeta : import . meta LeftHandSideExpression : OptionalExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression AwaitExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression LogicalANDExpression : LogicalANDExpression && BitwiseORExpression LogicalORExpression : LogicalORExpression || LogicalANDExpression CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression Expression : Expression , AssignmentExpression
  1. 1. Return invalid.

8.5.5 Static Semantics: PropName

PropertyDefinition : IdentifierReference
  1. 1. Return StringValue of IdentifierReference.
PropertyDefinition : ... AssignmentExpression
  1. 1. Return empty.
PropertyDefinition : PropertyName : AssignmentExpression
  1. 1. Return PropName of PropertyName.
LiteralPropertyName : IdentifierName
  1. 1. Return StringValue of IdentifierName.
LiteralPropertyName : StringLiteral
  1. 1. Return the SV of StringLiteral.
LiteralPropertyName : NumericLiteral
  1. 1. Let nbr be the NumericValue of NumericLiteral.
  2. 2. Return ! ToString(nbr).
ComputedPropertyName : [ AssignmentExpression ]
  1. 1. Return empty.
MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody } MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Return PropName of PropertyNameClassElementName.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. Return PropName of PropertyNameClassElementName.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. Return PropName of PropertyNameClassElementName.
ClassElement : ;
  1. 1. Return empty.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. Return PropName of PropertyNameClassElementName.
FieldDefinition : ClassElementName Initializeropt
  1. 1. Return PropName of ClassElementName.
ClassElementName : PrivateIdentifier
  1. 1. Return empty.

9.1.2.2 NewDeclarativeEnvironment ( E )

The abstract operation NewDeclarativeEnvironment takes argument E (an Environment Record or null). It performs the following steps when called:

  1. 1. Let env be a new declarative Environment Record containing no bindings.
  2. 2. Set env.[[OuterEnv]] to E.
  3. 3. Return env.

9.3 Execution Contexts

An execution context is a specification device that is used to track the runtime evaluation of code by an ECMAScript implementation. At any point in time, there is at most one execution context per agent that is actually executing code. This is known as the agent's running execution context. All references to the running execution context in this specification denote the running execution context of the surrounding agent.

The execution context stack is used to track execution contexts. The running execution context is always the top element of this stack. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.

An execution context contains whatever implementation specific state is necessary to track the execution progress of its associated code. Each execution context has at least the state components listed in Table 25Table 28.

Table 25Table 28: State Components for All Execution Contexts
Component Purpose
code evaluation state Any state needed to perform, suspend, and resume evaluation of the code associated with this execution context.
Function If this execution context is evaluating the code of a function object, then the value of this component is that function object. If the context is evaluating the code of a Script or Module, the value is null.
Realm The Realm Record from which associated code accesses ECMAScript resources.
ScriptOrModule The Module Record or Script Record from which associated code originates. If there is no originating script or module, as is the case for the original execution context created in InitializeHostDefinedRealm, the value is null.

Evaluation of code by the running execution context may be suspended at various points defined within this specification. Once the running execution context has been suspended a different execution context may become the running execution context and commence evaluating its code. At some later time a suspended execution context may again become the running execution context and continue evaluating its code at the point where it had previously been suspended. Transition of the running execution context status among execution contexts usually occurs in stack-like last-in/first-out manner. However, some ECMAScript features require non-LIFO transitions of the running execution context.

The value of the Realm component of the running execution context is also called the current Realm Record. The value of the Function component of the running execution context is also called the active function object.

Execution contexts for ECMAScript code have the additional state components listed in Table 26Table 29.

Table 26Table 29: Additional State Components for ECMAScript Code Execution Contexts
Component Purpose
LexicalEnvironment Identifies the Environment Record used to resolve identifier references made by code within this execution context.
VariableEnvironment Identifies the Environment Record that holds bindings created by VariableStatements within this execution context.
PrivateEnvironment Identifies the Environment Record that holds Private Names created by ClassElements.

The LexicalEnvironment and VariableEnvironment components of an execution context are always Environment Records.

Execution contexts representing the evaluation of generator objects have the additional state components listed in Table 27Table 30.

Note
The PrivateEnvironment Lexical Context is always a chain of Declaration Contexts. Each name begins with "#".
Table 27Table 30: Additional State Components for Generator Execution Contexts
Component Purpose
Generator The generator object that this execution context is evaluating.

In most situations only the running execution context (the top of the execution context stack) is directly manipulated by algorithms within this specification. Hence when the terms “LexicalEnvironment”, and “VariableEnvironment” are used without qualification they are in reference to those components of the running execution context.

An execution context is purely a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation. It is impossible for ECMAScript code to directly access or observe an execution context.

10.2 ECMAScript Function Objects

ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript function object is an ordinary object and has the same internal slots and the same internal methods as other ordinary objects. The code of an ECMAScript function object may be either strict mode code (11.2.2) or non-strict code. An ECMAScript function object whose code is strict mode code is called a strict function. One whose code is not strict mode code is called a non-strict function.

In addition to [[Extensible]] and [[Prototype]], ECMAScript function objects also have the internal slots listed in Table 30Table 33.

Table 30Table 33: Internal Slots of ECMAScript Function Objects
Internal Slot Type Description
[[Environment]] Environment Record The Environment Record that the function was closed over. Used as the outer environment when evaluating the code of the function.
[[PrivateEnvironment]] Environment Record The Environment Record for Private Names that the function was closed over. Used as the outer environment for Private Names when evaluating the code of the function.
[[FormalParameters]] Parse Node The root parse node of the source text that defines the function's formal parameter list.
[[ECMAScriptCode]] Parse Node The root parse node of the source text that defines the function's body.
[[ConstructorKind]] base | derived Whether or not the function is a derived class constructor.
[[Realm]] Realm Record The realm in which the function was created and which provides any intrinsic objects that are accessed when evaluating the function.
[[ScriptOrModule]] Script Record or Module Record The script or module in which the function was created.
[[ThisMode]] lexical | strict | global Defines how this references are interpreted within the formal parameters and code body of the function. lexical means that this refers to the this value of a lexically enclosing function. strict means that the this value is used exactly as provided by an invocation of the function. global means that a this value of undefined or null is interpreted as a reference to the global object, and any other this value is first passed to ToObject.
[[Strict]] Boolean true if this is a strict function, false if this is a non-strict function.
[[HomeObject]] Object If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
[[SourceText]] sequence of Unicode code points The source text that defines the function.
[[Fields]] List of ClassFieldDefinition Records If the function is a class with instance field declarations, this is a list of records representing those fields and their initializers.
[[IsClassConstructor]] Boolean Indicates whether the function is a class constructor. (If true, invoking the function's [[Call]] will immediately throw a TypeError exception.)
[[ClassFieldInitializer]] Boolean true if this is a class field initializer, false otherwise.
[[PrivateBrand]] Object | undefined If the function is a class with private methods or accessors, this is the brand to be installed on objects that are being initialized by the constructor of this class. The brand is the class' prototype, or undefined if no private method or acessor is present in the class. This brand is used to check if an object can access class' private methods and acessors.

All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.

10.2.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of an ECMAScript function object F takes arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor). It performs the following steps when called:

  1. 1. Assert: F is an ECMAScript function object.
  2. 2. Assert: Type(newTarget) is Object.
  3. 3. Let callerContext be the running execution context.
  4. 4. Let kind be F.[[ConstructorKind]].
  5. 5. If kind is base, then
    1. a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%Object.prototype%").
  6. 6. Let calleeContext be PrepareForOrdinaryCall(F, newTarget).
  7. 7. Assert: calleeContext is now the running execution context.
  8. 8. If kind is base, perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
  9. 8. If kind is base, then
    1. a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
    2. b. Let result be InitializeInstanceElements(thisArgument, F).
    3. c. If result is an abrupt completion, then
      1. i. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
      2. ii. Return Completion(result).
  10. 9. Let constructorEnv be the LexicalEnvironment of calleeContext.
  11. 10. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
  12. 11. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
  13. 12. If result.[[Type]] is return, then
    1. a. If Type(result.[[Value]]) is Object, return NormalCompletion(result.[[Value]]).
    2. b. If kind is base, return NormalCompletion(thisArgument).
    3. c. If result.[[Value]] is not undefined, throw a TypeError exception.
  14. 13. Else, ReturnIfAbrupt(result).
  15. 14. Return ? constructorEnv.GetThisBinding().

10.2.3 OrdinaryFunctionCreate ( functionPrototype, sourceText, ParameterList, Body, thisMode, Scope, PrivateScope )

The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), ParameterList (a Parse Node), Body (a Parse Node), thisMode (either lexical-this or non-lexical-this), and Scope (an Environment Record), and PrivateScope (an Environment Record). sourceText is the source text of the syntactic definition of the function to be created. It performs the following steps when called:

  1. 1. Assert: Type(functionPrototype) is Object.
  2. 2. Let internalSlotsList be the internal slots listed in Table 30Table 33.
  3. 3. Let F be ! OrdinaryObjectCreate(functionPrototype, internalSlotsList).
  4. 4. Set F.[[Call]] to the definition specified in 10.2.1.
  5. 5. Set F.[[SourceText]] to sourceText.
  6. 6. Set F.[[FormalParameters]] to ParameterList.
  7. 7. Set F.[[ECMAScriptCode]] to Body.
  8. 8. If the source text matching Body is strict mode code, let Strict be true; else let Strict be false.
  9. 9. Set F.[[Strict]] to Strict.
  10. 10. If thisMode is lexical-this, set F.[[ThisMode]] to lexical.
  11. 11. Else if Strict is true, set F.[[ThisMode]] to strict.
  12. 12. Else, set F.[[ThisMode]] to global.
  13. 13. Set F.[[IsClassConstructor]] to false.
  14. 14. Set F.[[Environment]] to Scope.
  15. 15. Set F.[[PrivateEnvironment]] to PrivateScope.
  16. 1516. Set F.[[ScriptOrModule]] to GetActiveScriptOrModule().
  17. 1617. Set F.[[Realm]] to the current Realm Record.
  18. 1718. Set F.[[HomeObject]] to undefined.
  19. 19. Set F.[[ClassFieldInitializer]] to false.
  20. 1820. Let len be the ExpectedArgumentCount of ParameterList.
  21. 1921. Perform ! SetFunctionLength(F, len).
  22. 2022. Return F.

10.2.8 DefineMethodProperty ( key, homeObject, closure, enumerable )

  1. 1. Perform SetFunctionName(closure, key).
  2. 2. If key is a Private Name, then
    1. a. Assert: key does not have a [[Kind]] field.
    2. b. Set key.[[Kind]] to method.
    3. c. Set key.[[Value]] to closure.
    4. d. Set key.[[Brand]] to homeObject.
  3. 3. Else,
    1. a. Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
    2. b. Perform ? DefinePropertyOrThrow(homeObject, key, desc).

10.2.810.2.9 SetFunctionName ( F, name [ , prefix ] )

The abstract operation SetFunctionName takes arguments F (a function object) and name (a property keykey or Private Name) and optional argument prefix (a String). It adds a "name" property to F. It performs the following steps when called:

  1. 1. Assert: F is an extensible object that does not have a "name" own property.
  2. 2. Assert: Type(name) is either Symbol or Symbol, String, or Private Name.
  3. 3. Assert: If prefix is present, then Type(prefix) is String.
  4. 4. If Type(name) is Symbol, then
    1. a. Let description be name's [[Description]] value.
    2. b. If description is undefined, set name to the empty String.
    3. c. Else, set name to the string-concatenation of "[", description, and "]".
  5. 5. Else if name is a Private Name, then
    1. a. Set name to name.[[Description]].
  6. 56. If F has an [[InitialName]] internal slot, then
    1. a. Set F.[[InitialName]] to name.
  7. 67. If prefix is present, then
    1. a. Set name to the string-concatenation of prefix, the code unit 0x0020 (SPACE), and name.
    2. b. If F has an [[InitialName]] internal slot, then
      1. i. Optionally, set F.[[InitialName]] to name.
  8. 78. Return ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).

10.2.1010.2.11 FunctionDeclarationInstantiation ( func, argumentsList )

Note 1

When an execution context is established for evaluating an ECMAScript function a new function Environment Record is created and bindings for each formal parameter are instantiated in that Environment Record. Each declaration in the function body is also instantiated. If the function's formal parameters do not include any default value initializers then the body declarations are instantiated in the same Environment Record as the parameters. If default value parameter initializers exist, a second Environment Record is created for the body declarations. Formal parameters and functions are initialized as part of FunctionDeclarationInstantiation. All other bindings are initialized during evaluation of the function body.

The abstract operation FunctionDeclarationInstantiation takes arguments func (a function object) and argumentsList. func is the function object for which the execution context is being established. It performs the following steps when called:

  1. 1. Let calleeContext be the running execution context.
  2. 2. Let code be func.[[ECMAScriptCode]].
  3. 3. Let strict be func.[[Strict]].
  4. 4. Let formals be func.[[FormalParameters]].
  5. 5. Let parameterNames be the BoundNames of formals.
  6. 6. If parameterNames has any duplicate entries, let hasDuplicates be true. Otherwise, let hasDuplicates be false.
  7. 7. Let simpleParameterList be IsSimpleParameterList of formals.
  8. 8. Let hasParameterExpressions be ContainsExpression of formals.
  9. 9. Let varNames be the VarDeclaredNames of code.
  10. 10. Let varDeclarations be the VarScopedDeclarations of code.
  11. 11. Let lexicalNames be the LexicallyDeclaredNames of code.
  12. 12. Let functionNames be a new empty List.
  13. 13. Let functionsToInitialize be a new empty List.
  14. 14. For each element d of varDeclarations, in reverse List order, do
    1. a. If d is neither a VariableDeclaration nor a ForBinding nor a BindingIdentifier, then
      1. i. Assert: d is either a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration.
      2. ii. Let fn be the sole element of the BoundNames of d.
      3. iii. If fn is not an element of functionNames, then
        1. 1. Insert fn as the first element of functionNames.
        2. 2. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
        3. 3. Insert d as the first element of functionsToInitialize.
  15. 15. Let argumentsObjectNeeded be true.
  16. 16. If func.[[ThisMode]] is lexical, then
    1. a. NOTE: Arrow functions never have an arguments objects.
    2. b. Set argumentsObjectNeeded to false.
  17. 17. Else if "arguments" is an element of parameterNames, then
    1. a. Set argumentsObjectNeeded to false.
  18. 18. Else if hasParameterExpressions is false, then
    1. a. If "arguments" is an element of functionNames or if "arguments" is an element of lexicalNames, then
      1. i. Set argumentsObjectNeeded to false.
  19. 19. If strict is true or if hasParameterExpressions is false, then
    1. a. NOTE: Only a single Environment Record is needed for the parameters and top-level vars.
    2. b. Let env be the LexicalEnvironment of calleeContext.
  20. 20. Else,
    1. a. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared.
    2. b. Let calleeEnv be the LexicalEnvironment of calleeContext.
    3. c. Let env be NewDeclarativeEnvironment(calleeEnv).
    4. d. Assert: The VariableEnvironment of calleeContext is calleeEnv.
    5. e. Set the LexicalEnvironment of calleeContext to env.
  21. 21. For each String paramName of parameterNames, do
    1. a. Let alreadyDeclared be env.HasBinding(paramName).
    2. b. NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have parameter default values or rest parameters.
    3. c. If alreadyDeclared is false, then
      1. i. Perform ! env.CreateMutableBinding(paramName, false).
      2. ii. If hasDuplicates is true, then
        1. 1. Perform ! env.InitializeBinding(paramName, undefined).
  22. 22. If argumentsObjectNeeded is true, then
    1. a. If strict is true or if simpleParameterList is false, then
      1. i. Let ao be CreateUnmappedArgumentsObject(argumentsList).
    2. b. Else,
      1. i. NOTE: A mapped argument object is only provided for non-strict functions that don't have a rest parameter, any parameter default value initializers, or any destructured parameters.
      2. ii. Let ao be CreateMappedArgumentsObject(func, formals, argumentsList, env).
    3. c. If strict is true, then
      1. i. Perform ! env.CreateImmutableBinding("arguments", false).
    4. d. Else,
      1. i. Perform ! env.CreateMutableBinding("arguments", false).
    5. e. Call env.InitializeBinding("arguments", ao).
    6. f. Let parameterBindings be a List whose elements are the elements of parameterNames, followed by "arguments".
  23. 23. Else,
    1. a. Let parameterBindings be parameterNames.
  24. 24. Let iteratorRecord be CreateListIteratorRecord(argumentsList).
  25. 25. If hasDuplicates is true, then
    1. a. Perform ? IteratorBindingInitialization for formals with iteratorRecord and undefined as arguments.
  26. 26. Else,
    1. a. Perform ? IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
  27. 27. If hasParameterExpressions is false, then
    1. a. NOTE: Only a single Environment Record is needed for the parameters and top-level vars.
    2. b. Let instantiatedVarNames be a copy of the List parameterBindings.
    3. c. For each element n of varNames, do
      1. i. If n is not an element of instantiatedVarNames, then
        1. 1. Append n to instantiatedVarNames.
        2. 2. Perform ! env.CreateMutableBinding(n, false).
        3. 3. Call env.InitializeBinding(n, undefined).
    4. d. Let varEnv be env.
  28. 28. Else,
    1. a. NOTE: A separate Environment Record is needed to ensure that closures created by expressions in the formal parameter list do not have visibility of declarations in the function body.
    2. b. Let varEnv be NewDeclarativeEnvironment(env).
    3. c. Set the VariableEnvironment of calleeContext to varEnv.
    4. d. Let instantiatedVarNames be a new empty List.
    5. e. For each element n of varNames, do
      1. i. If n is not an element of instantiatedVarNames, then
        1. 1. Append n to instantiatedVarNames.
        2. 2. Perform ! varEnv.CreateMutableBinding(n, false).
        3. 3. If n is not an element of parameterBindings or if n is an element of functionNames, let initialValue be undefined.
        4. 4. Else,
          1. a. Let initialValue be ! env.GetBindingValue(n, false).
        5. 5. Call varEnv.InitializeBinding(n, initialValue).
        6. 6. NOTE: A var with the same name as a formal parameter initially has the same value as the corresponding initialized parameter.
  29. 29. NOTE: Annex B.3.3.1 adds additional steps at this point.
  30. 30. If strict is false, then
    1. a. Let lexEnv be NewDeclarativeEnvironment(varEnv).
    2. b. NOTE: Non-strict functions use a separate Environment Record for top-level lexical declarations so that a direct eval can determine whether any var scoped declarations introduced by the eval code conflict with pre-existing top-level lexically scoped declarations. This is not needed for strict functions because a strict direct eval always places all declarations into a new Environment Record.
  31. 31. Else, let lexEnv be varEnv.
  32. 32. Set the LexicalEnvironment of calleeContext to lexEnv.
  33. 33. Let lexDeclarations be the LexicallyScopedDeclarations of code.
  34. 34. For each element d of lexDeclarations, do
    1. a. NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a var name. Lexically declared names are only instantiated here but not initialized.
    2. b. For each element dn of the BoundNames of d, do
      1. i. If IsConstantDeclaration of d is true, then
        1. 1. Perform ! lexEnv.CreateImmutableBinding(dn, true).
      2. ii. Else,
        1. 1. Perform ! lexEnv.CreateMutableBinding(dn, false).
  35. 35. Let privateEnv be the PrivateEnvironment of calleeContext.
  36. 3536. For each Parse Node f of functionsToInitialize, do
    1. a. Let fn be the sole element of the BoundNames of f.
    2. b. Let fo be InstantiateFunctionObject of f with argument arguments lexEnv and privateEnv.
    3. c. Perform ! varEnv.SetMutableBinding(fn, fo, false).
  37. 3637. Return NormalCompletion(empty).
Note 2

B.3.3 provides an extension to the above algorithm that is necessary for backwards compatibility with web browser implementations of ECMAScript that predate ECMAScript 2015.

Note 3

Parameter Initializers may contain direct eval expressions. Any top level declarations of such evals are only visible to the eval code (11.2). The creation of the environment for such declarations is described in 8.5.3.

10.2.1.1 PrepareForOrdinaryCall ( F, newTarget )

The abstract operation PrepareForOrdinaryCall takes arguments F (a function object) and newTarget (an ECMAScript language value). It performs the following steps when called:

  1. 1. Assert: Type(newTarget) is Undefined or Object.
  2. 2. Let callerContext be the running execution context.
  3. 3. Let calleeContext be a new ECMAScript code execution context.
  4. 4. Set the Function of calleeContext to F.
  5. 5. Let calleeRealm be F.[[Realm]].
  6. 6. Set the Realm of calleeContext to calleeRealm.
  7. 7. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
  8. 8. Let localEnv be NewFunctionEnvironment(F, newTarget).
  9. 9. Set the LexicalEnvironment of calleeContext to localEnv.
  10. 10. Set the VariableEnvironment of calleeContext to localEnv.
  11. 11. Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
  12. 1112. If callerContext is not already suspended, suspend callerContext.
  13. 1213. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
  14. 1314. NOTE: Any exception objects produced after this point are associated with calleeRealm.
  15. 1415. Return calleeContext.

10.2.1.3 Runtime Semantics: EvaluateBody

With parameters functionObject and argumentsList (a List).

FunctionBody : FunctionStatementList
  1. 1. Return ? EvaluateFunctionBody of FunctionBody with arguments functionObject and argumentsList.
ConciseBody : ExpressionBody
  1. 1. Return ? EvaluateConciseBody of ConciseBody with arguments functionObject and argumentsList.
GeneratorBody : FunctionBody
  1. 1. Return ? EvaluateGeneratorBody of GeneratorBody with arguments functionObject and argumentsList.
AsyncGeneratorBody : FunctionBody
  1. 1. Return ? EvaluateAsyncGeneratorBody of AsyncGeneratorBody with arguments functionObject and argumentsList.
AsyncFunctionBody : FunctionBody
  1. 1. Return ? EvaluateAsyncFunctionBody of AsyncFunctionBody with arguments functionObject and argumentsList.
AsyncConciseBody : ExpressionBody
  1. 1. Return ? EvaluateAsyncConciseBody of AsyncConciseBody with arguments functionObject and argumentsList.
Initializer : = AssignmentExpression
  1. 1. Assert: argumentsList is empty.
  2. 2. Let exprRef be the result of evaluating AssignmentExpression.
  3. 3. Let exprValue be ? GetValue(exprRef).
  4. 4. Return Completion { [[Type]]: return, [[Value]]: exprValue, [[Target]]: empty }.
Note
FunctionDeclarationInstantiation would not have any observable behaviour here, so its call is omitted.

12.5 Tokens

Syntax

CommonToken :: IdentifierName PrivateIdentifier Punctuator NumericLiteral StringLiteral Template Note

The DivPunctuator, RegularExpressionLiteral, RightBracePunctuator, and TemplateSubstitutionTail productions derive additional tokens that are not included in the CommonToken production.

12.6 Names and Keywords

IdentifierName and ReservedWord are tokens that are interpreted according to the Default Identifier Syntax given in Unicode Standard Annex #31, Identifier and Pattern Syntax, with some small modifications. ReservedWord is an enumerated subset of IdentifierName. The syntactic grammar defines Identifier as an IdentifierName that is not a ReservedWord. The Unicode identifier grammar is based on character properties specified by the Unicode Standard. The Unicode code points in the specified categories in the latest version of the Unicode standard must be treated as in those categories by all conforming ECMAScript implementations. ECMAScript implementations may recognize identifier code points defined in later editions of the Unicode Standard.

Note 1

This standard specifies specific code point additions: U+0024 (DOLLAR SIGN) and U+005F (LOW LINE) are permitted anywhere in an IdentifierName, and the code points U+200C (ZERO WIDTH NON-JOINER) and U+200D (ZERO WIDTH JOINER) are permitted anywhere after the first code point of an IdentifierName.

Unicode escape sequences are permitted in an IdentifierName, where they contribute a single Unicode code point to the IdentifierName. The code point is expressed by the CodePoint of the UnicodeEscapeSequence (see 12.8.4). The \ preceding the UnicodeEscapeSequence and the u and { } code units, if they appear, do not contribute code points to the IdentifierName. A UnicodeEscapeSequence cannot be used to put a code point into an IdentifierName that would otherwise be illegal. In other words, if a \ UnicodeEscapeSequence sequence were replaced by the SourceCharacter it contributes, the result must still be a valid IdentifierName that has the exact same sequence of SourceCharacter elements as the original IdentifierName. All interpretations of IdentifierName within this specification are based upon their actual code points regardless of whether or not an escape sequence was used to contribute any particular code point.

Two IdentifierNames that are canonically equivalent according to the Unicode standard are not equal unless, after replacement of each UnicodeEscapeSequence, they are represented by the exact same sequence of code points.

Syntax

PrivateIdentifier :: # IdentifierName IdentifierName :: IdentifierStart IdentifierName IdentifierPart IdentifierStart :: UnicodeIDStart $ _ \ UnicodeEscapeSequence IdentifierPart :: UnicodeIDContinue $ \ UnicodeEscapeSequence <ZWNJ> <ZWJ> UnicodeIDStart :: any Unicode code point with the Unicode property “ID_Start” UnicodeIDContinue :: any Unicode code point with the Unicode property “ID_Continue”

The definitions of the nonterminal UnicodeEscapeSequence is given in 12.8.4.

Note 2

The nonterminal IdentifierPart derives _ via UnicodeIDContinue.

Note 3

The sets of code points with Unicode properties “ID_Start” and “ID_Continue” include, respectively, the code points with Unicode properties “Other_ID_Start” and “Other_ID_Continue”.

13.1.2 Static Semantics: StringValue

IdentifierName :: IdentifierStart IdentifierName IdentifierPart
  1. 1. Let idText be the source text matched by IdentifierName.
  2. 2. Let idTextUnescaped be the result of replacing any occurrences of \ UnicodeEscapeSequence in idText with the code point represented by the UnicodeEscapeSequence.
  3. 3. Return ! CodePointsToString(idTextUnescaped).
IdentifierReference : yield BindingIdentifier : yield LabelIdentifier : yield
  1. 1. Return "yield".
IdentifierReference : await BindingIdentifier : await LabelIdentifier : await
  1. 1. Return "await".
Identifier : IdentifierName but not ReservedWord
  1. 1. Return the StringValue of IdentifierName.
PrivateIdentifier :: # IdentifierName
  1. 1. Return the string-concatenation of 0x0023 (NUMBER SIGN) and the StringValue of IdentifierName.

13.2.5 Object Initializer

Note 1

An object initializer is an expression describing the initialization of an Object, written in a form resembling a literal. It is a list of zero or more pairs of property keys and associated values, enclosed in curly brackets. The values need not be literals; they are evaluated each time the object initializer is evaluated.

Syntax

ObjectLiteral[Yield, Await] : { } { PropertyDefinitionList[?Yield, ?Await] } { PropertyDefinitionList[?Yield, ?Await] , } PropertyDefinitionList[Yield, Await] : PropertyDefinition[?Yield, ?Await] PropertyDefinitionList[?Yield, ?Await] , PropertyDefinition[?Yield, ?Await] PropertyDefinition[Yield, Await] : IdentifierReference[?Yield, ?Await] CoverInitializedName[?Yield, ?Await] PropertyName[?Yield, ?Await] : AssignmentExpression[+In, ?Yield, ?Await] MethodDefinition[?Yield, ?Await] ... AssignmentExpression[+In, ?Yield, ?Await] PropertyName[Yield, Await] : LiteralPropertyName ComputedPropertyName[?Yield, ?Await] LiteralPropertyName : IdentifierName StringLiteral NumericLiteral ComputedPropertyName[Yield, Await] : [ AssignmentExpression[+In, ?Yield, ?Await] ] CoverInitializedName[Yield, Await] : IdentifierReference[?Yield, ?Await] Initializer[+In, ?Yield, ?Await] Initializer[In, Yield, Await] : = AssignmentExpression[?In, ?Yield, ?Await] = AssignmentExpression[?In, ?Yield, ?Await] Note 2

MethodDefinition is defined in 15.4.

Note 3

In certain contexts, ObjectLiteral is used as a cover grammar for a more restricted secondary grammar. The CoverInitializedName production is necessary to fully cover these secondary grammars. However, use of this production results in an early Syntax Error in normal contexts where an actual ObjectLiteral is expected.

13.2.5.1 Static Semantics: Early Errors

PropertyDefinition : MethodDefinition

In addition to describing an actual object initializer the ObjectLiteral productions are also used as a cover grammar for ObjectAssignmentPattern and may be recognized as part of a CoverParenthesizedExpressionAndArrowParameterList. When ObjectLiteral appears in a context where ObjectAssignmentPattern is required the following Early Error rules are not applied. In addition, they are not applied when initially parsing a CoverParenthesizedExpressionAndArrowParameterList or CoverCallExpressionAndAsyncArrowHead.

PropertyDefinition : CoverInitializedName
  • Always throw a Syntax Error if code matches this production.
Note

This production exists so that ObjectLiteral can serve as a cover grammar for ObjectAssignmentPattern. It cannot occur in an actual object initializer.

13.2.5.5 Runtime Semantics: PropertyDefinitionEvaluation

With parameters object and enumerable.

PropertyDefinitionList : PropertyDefinitionList , PropertyDefinition
  1. 1. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with arguments object and enumerable.
  2. 2. Return the result of performing PropertyDefinitionEvaluation of PropertyDefinition with arguments object and enumerable.
PropertyDefinition : ... AssignmentExpression
  1. 1. Let exprValue be the result of evaluating AssignmentExpression.
  2. 2. Let fromValue be ? GetValue(exprValue).
  3. 3. Let excludedNames be a new empty List.
  4. 4. Return ? CopyDataProperties(object, fromValue, excludedNames).
PropertyDefinition : IdentifierReference
  1. 1. Let propName be StringValue of IdentifierReference.
  2. 2. Let exprValue be the result of evaluating IdentifierReference.
  3. 3. Let propValue be ? GetValue(exprValue).
  4. 4. Assert: enumerable is true.
  5. 5. Assert: object is an ordinary, extensible object with no non-configurable properties.
  6. 6. Return ! CreateDataPropertyOrThrow(object, propName, propValue).
PropertyDefinition : PropertyName : AssignmentExpression
  1. 1. Let propKey be the result of evaluating PropertyName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then
    1. a. Let propValue be ? NamedEvaluation of AssignmentExpression with argument propKey.
  4. 4. Else,
    1. a. Let exprValueRef be the result of evaluating AssignmentExpression.
    2. b. Let propValue be ? GetValue(exprValueRef).
  5. 5. Assert: enumerable is true.
  6. 6. Assert: object is an ordinary, extensible object with no non-configurable properties.
  7. 7. Return ! CreateDataPropertyOrThrow(object, propKey, propValue).
Note

An alternative semantics for this production is given in B.3.1.

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody } MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Return ? MethodDefinitionEvaluation of MethodDefinition with arguments object and enumerable.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. Return ? MethodDefinitionEvaluation of GeneratorMethod with arguments object and enumerable.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. Return ? MethodDefinitionEvaluation of AsyncGeneratorMethod with arguments object and enumerable.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. Return ? MethodDefinitionEvaluation of AsyncMethod with arguments object and enumerable.

13.3 Left-Hand-Side Expressions

Syntax

MemberExpression[Yield, Await] : PrimaryExpression[?Yield, ?Await] MemberExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] MemberExpression[?Yield, ?Await] . IdentifierName MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] SuperProperty[?Yield, ?Await] MetaProperty new MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await] MemberExpression[?Yield, ?Await] . PrivateIdentifier SuperProperty[Yield, Await] : super [ Expression[+In, ?Yield, ?Await] ] super . IdentifierName MetaProperty : NewTarget ImportMeta NewTarget : new . target ImportMeta : import . meta NewExpression[Yield, Await] : MemberExpression[?Yield, ?Await] new NewExpression[?Yield, ?Await] CallExpression[Yield, Await] : CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] SuperCall[?Yield, ?Await] ImportCall[?Yield, ?Await] CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await] CallExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] CallExpression[?Yield, ?Await] . IdentifierName CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] CallExpression[?Yield, ?Await] . PrivateIdentifier SuperCall[Yield, Await] : super Arguments[?Yield, ?Await] ImportCall[Yield, Await] : import ( AssignmentExpression[+In, ?Yield, ?Await] ) Arguments[Yield, Await] : ( ) ( ArgumentList[?Yield, ?Await] ) ( ArgumentList[?Yield, ?Await] , ) ArgumentList[Yield, Await] : AssignmentExpression[+In, ?Yield, ?Await] ... AssignmentExpression[+In, ?Yield, ?Await] ArgumentList[?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ArgumentList[?Yield, ?Await] , ... AssignmentExpression[+In, ?Yield, ?Await] OptionalExpression[Yield, Await] : MemberExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] CallExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] OptionalExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] OptionalChain[Yield, Await] : ?. Arguments[?Yield, ?Await] ?. [ Expression[+In, ?Yield, ?Await] ] ?. IdentifierName ?. TemplateLiteral[?Yield, ?Await, +Tagged] ?. PrivateIdentifier OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await] OptionalChain[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] OptionalChain[?Yield, ?Await] . IdentifierName OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] OptionalChain[?Yield, ?Await] . PrivateIdentifier LeftHandSideExpression[Yield, Await] : NewExpression[?Yield, ?Await] CallExpression[?Yield, ?Await] OptionalExpression[?Yield, ?Await]

Supplemental Syntax

When processing an instance of the production
CallExpression : CoverCallExpressionAndAsyncArrowHead
the interpretation of CoverCallExpressionAndAsyncArrowHead is refined using the following grammar:

CallMemberExpression[Yield, Await] : MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

13.3.2.1 Runtime Semantics: Evaluation

MemberExpression : MemberExpression [ Expression ]
  1. 1. Let baseReference be the result of evaluating MemberExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. If the code matched by this MemberExpression is strict mode code, let strict be true; else let strict be false.
  4. 4. Return ? EvaluatePropertyAccessWithExpressionKey(baseValue, Expression, strict).
MemberExpression : MemberExpression . IdentifierName
  1. 1. Let baseReference be the result of evaluating MemberExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. If the code matched by this MemberExpression is strict mode code, let strict be true; else let strict be false.
  4. 4. Return ? EvaluatePropertyAccessWithIdentifierKey(baseValue, IdentifierName, strict).
MemberExpression : MemberExpression . PrivateIdentifier
  1. 1. Let baseReference be the result of evaluating MemberExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. Let bv be ? RequireObjectCoercible(baseValue).
  4. 4. Let fieldNameString be the StringValue of PrivateIdentifier.
  5. 5. Return ? MakePrivateReference(bv, fieldNameString).
CallExpression : CallExpression [ Expression ]
  1. 1. Let baseReference be the result of evaluating CallExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. If the code matched by this CallExpression is strict mode code, let strict be true; else let strict be false.
  4. 4. Return ? EvaluatePropertyAccessWithExpressionKey(baseValue, Expression, strict).
CallExpression : CallExpression . IdentifierName
  1. 1. Let baseReference be the result of evaluating CallExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. If the code matched by this CallExpression is strict mode code, let strict be true; else let strict be false.
  4. 4. Return ? EvaluatePropertyAccessWithIdentifierKey(baseValue, IdentifierName, strict).
CallExpression : CallExpression . PrivateIdentifier
  1. 1. Let baseReference be the result of evaluating CallExpression.
  2. 2. Let baseValue be ? GetValue(baseReference).
  3. 3. Let bv be ? RequireObjectCoercible(baseValue).
  4. 4. Let fieldNameString be the StringValue of PrivateIdentifier.
  5. 5. Return ? MakePrivateReference(bv, fieldNameString).

13.3.7.1 Runtime Semantics: Evaluation

SuperProperty : super [ Expression ]
  1. 1. Let env be GetThisEnvironment().
  2. 2. Let actualThis be ? env.GetThisBinding().
  3. 3. Let propertyNameReference be the result of evaluating Expression.
  4. 4. Let propertyNameValue be ? GetValue(propertyNameReference).
  5. 5. Let propertyKey be ? ToPropertyKey(propertyNameValue).
  6. 6. If the code matched by this SuperProperty is strict mode code, let strict be true; else let strict be false.
  7. 7. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict).
SuperProperty : super . IdentifierName
  1. 1. Let env be GetThisEnvironment().
  2. 2. Let actualThis be ? env.GetThisBinding().
  3. 3. Let propertyKey be StringValue of IdentifierName.
  4. 4. If the code matched by this SuperProperty is strict mode code, let strict be true; else let strict be false.
  5. 5. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict).
SuperCall : super Arguments
  1. 1. Let newTarget be GetNewTarget().
  2. 2. Assert: Type(newTarget) is Object.
  3. 3. Let func be ! GetSuperConstructor().
  4. 4. Let argList be ? ArgumentListEvaluation of Arguments.
  5. 5. If IsConstructor(func) is false, throw a TypeError exception.
  6. 6. Let result be ? Construct(func, argList, newTarget).
  7. 7. Let thisER be GetThisEnvironment().
  8. 8. Return Perform ? thisER.BindThisValue(result).
  9. 9. Let F be thisER.[[FunctionObject]].
  10. 10. Assert: F is an ECMAScript function object.
  11. 11. Perform ? InitializeInstanceElements(result, F).
  12. 12. Return result.

13.3.9.2 Runtime Semantics: ChainEvaluation

With parameters baseValue and baseReference.

OptionalChain : ?. Arguments
  1. 1. Let thisChain be this OptionalChain.
  2. 2. Let tailCall be IsInTailPosition(thisChain).
  3. 3. Return ? EvaluateCall(baseValue, baseReference, Arguments, tailCall).
OptionalChain : ?. [ Expression ]
  1. 1. If the code matched by this OptionalChain is strict mode code, let strict be true; else let strict be false.
  2. 2. Return ? EvaluatePropertyAccessWithExpressionKey(baseValue, Expression, strict).
OptionalChain : ?. IdentifierName
  1. 1. If the code matched by this OptionalChain is strict mode code, let strict be true; else let strict be false.
  2. 2. Return ? EvaluatePropertyAccessWithIdentifierKey(baseValue, IdentifierName, strict).
OptionalChain : ?. PrivateIdentifier
  1. 1. Let bv be ? RequireObjectCoercible(baseValue).
  2. 2. Let fieldNameString be the StringValue of PrivateIdentifier.
  3. 3. Return MakePrivateReference(bv, fieldNameString).
OptionalChain : OptionalChain Arguments
  1. 1. Let optionalChain be OptionalChain.
  2. 2. Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
  3. 3. Let newValue be ? GetValue(newReference).
  4. 4. Let thisChain be this OptionalChain.
  5. 5. Let tailCall be IsInTailPosition(thisChain).
  6. 6. Return ? EvaluateCall(newValue, newReference, Arguments, tailCall).
OptionalChain : OptionalChain [ Expression ]
  1. 1. Let optionalChain be OptionalChain.
  2. 2. Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
  3. 3. Let newValue be ? GetValue(newReference).
  4. 4. If the code matched by this OptionalChain is strict mode code, let strict be true; else let strict be false.
  5. 5. Return ? EvaluatePropertyAccessWithExpressionKey(newValue, Expression, strict).
OptionalChain : OptionalChain . IdentifierName
  1. 1. Let optionalChain be OptionalChain.
  2. 2. Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
  3. 3. Let newValue be ? GetValue(newReference).
  4. 4. If the code matched by this OptionalChain is strict mode code, let strict be true; else let strict be false.
  5. 5. Return ? EvaluatePropertyAccessWithIdentifierKey(newValue, IdentifierName, strict).
OptionalChain : OptionalChain . PrivateIdentifier
  1. 1. Let optionalChain be OptionalChain.
  2. 2. Let newReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
  3. 3. Let newValue be ? GetValue(newReference).
  4. 4. Let nv be ? RequireObjectCoercible(newValue).
  5. 5. Let fieldNameString be the StringValue of PrivateIdentifier.
  6. 6. Return MakePrivateReference(nv, fieldNameString).

13.5.1.1 Static Semantics: Early Errors

UnaryExpression : delete UnaryExpression Note

The last rule means that expressions such as delete (((foo))) produce early errors because of recursive application of the first rule.

13.5.1.2 Runtime Semantics: Evaluation

UnaryExpression : delete UnaryExpression
  1. 1. Let ref be the result of evaluating UnaryExpression.
  2. 2. ReturnIfAbrupt(ref).
  3. 3. If ref is not a Reference Record, return true.
  4. 4. If IsUnresolvableReference(ref) is true, then
    1. a. Assert: ref.[[Strict]] is false.
    2. b. Return true.
  5. 5. If IsPropertyReference(ref) is true, then
    1. a. Assert: ! IsPrivateReference(ref) is false.
    2. ab. If IsSuperReference(ref) is true, throw a ReferenceError exception.
    3. bc. Let baseObj be ! ToObject(ref.[[Base]]).
    4. cd. Let deleteStatus be ? baseObj.[[Delete]](ref.[[ReferencedName]]).
    5. de. If deleteStatus is false and ref.[[Strict]] is true, throw a TypeError exception.
    6. ef. Return deleteStatus.
  6. 6. Else,
    1. a. Let base be ref.[[Base]].
    2. b. Assert: base is an Environment Record.
    3. c. Return ? base.DeleteBinding(ref.[[ReferencedName]]).
Note 1

When a delete operator occurs within strict mode code, a SyntaxError exception is thrown if its UnaryExpression is a direct reference to a variable, function argument, or function name. In addition, if a delete operator occurs within strict mode code and the property to be deleted has the attribute { [[Configurable]]: false } (or otherwise cannot be deleted), a TypeError exception is thrown.

Note 2

The object that may be created in step 5.bc is not accessible outside of the above abstract operation and the ordinary object [[Delete]] internal method. An implementation might choose to avoid the actual creation of that object.

14.2.3 BlockDeclarationInstantiation ( code, env )

Note

When a Block or CaseBlock is evaluated a new declarative Environment Record is created and bindings for each block scoped variable, constant, function, or class declared in the block are instantiated in the Environment Record.

The abstract operation BlockDeclarationInstantiation takes arguments code (a Parse Node) and env (an Environment Record). code is the Parse Node corresponding to the body of the block. env is the Environment Record in which bindings are to be created. It performs the following steps when called:

  1. 1. Assert: env is a declarative Environment Record.
  2. 2. Let declarations be the LexicallyScopedDeclarations of code.
  3. 3. Let privateEnv be the running execution context's PrivateEnvironment.
  4. 34. For each element d of declarations, do
    1. a. For each element dn of the BoundNames of d, do
      1. i. If IsConstantDeclaration of d is true, then
        1. 1. Perform ! env.CreateImmutableBinding(dn, true).
      2. ii. Else,
        1. 1. Perform ! env.CreateMutableBinding(dn, false). NOTE: This step is replaced in section B.3.3.6.
    2. b. If d is a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration, then
      1. i. Let fn be the sole element of the BoundNames of d.
      2. ii. Let fo be InstantiateFunctionObject of d with argument arguments env and privateEnv.
      3. iii. Perform env.InitializeBinding(fn, fo). NOTE: This step is replaced in section B.3.3.6.

14.7.5.2 Static Semantics: IsDestructuring

MemberExpression : PrimaryExpression
  1. 1. If PrimaryExpression is either an ObjectLiteral or an ArrayLiteral, return true.
  2. 2. Return false.
MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression
  1. 1. Return false.
ForDeclaration : LetOrConst ForBinding
  1. 1. Return IsDestructuring of ForBinding.
ForBinding : BindingIdentifier
  1. 1. Return false.
ForBinding : BindingPattern
  1. 1. Return true.
Note

This section is extended by Annex B.3.6.

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

With parameter parameters scope and privateScope.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. 1. Let name be StringValue of BindingIdentifier.
  2. 2. Let sourceText be the source text matched by FunctionDeclaration.
  3. 3. Let F be OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, scope, privateScope).
  4. 4. Perform SetFunctionName(F, name).
  5. 5. Perform MakeConstructor(F).
  6. 6. Return F.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. 1. Let sourceText be the source text matched by FunctionDeclaration.
  2. 2. Let F be OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, scope, privateScope).
  3. 3. Perform SetFunctionName(F, "default").
  4. 4. Perform MakeConstructor(F).
  5. 5. Return F.
Note

An anonymous FunctionDeclaration can only occur as part of an export default declaration, and its function code is therefore always strict mode code.

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

With optional parameter name.

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by FunctionExpression.
  5. 45. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, scope, privateScope).
  6. 56. Perform SetFunctionName(closure, name).
  7. 67. Perform MakeConstructor(closure).
  8. 78. Return closure.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. 1. Assert: name is not present.
  2. 2. Set name to StringValue of BindingIdentifier.
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let funcEnv be NewDeclarativeEnvironment(scope).
  5. 5. Perform funcEnv.CreateImmutableBinding(name, false).
  6. 6. Let privateScope be the running execution context's PrivateEnvironment.
  7. 67. Let sourceText be the source text matched by FunctionExpression.
  8. 78. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, funcEnv, privateScope).
  9. 89. Perform SetFunctionName(closure, name).
  10. 910. Perform MakeConstructor(closure).
  11. 1011. Perform funcEnv.InitializeBinding(name, closure).
  12. 1112. Return closure.
Note

The BindingIdentifier in a FunctionExpression can be referenced from inside the FunctionExpression's FunctionBody to allow the function to call itself recursively. However, unlike in a FunctionDeclaration, the BindingIdentifier in a FunctionExpression cannot be referenced from and does not affect the scope enclosing the FunctionExpression.

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

With optional parameter name.

ArrowFunction : ArrowParameters => ConciseBody
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by ArrowFunction.
  5. 45. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, scope, privateScope).
  6. 56. Perform SetFunctionName(closure, name).
  7. 67. Return closure.
Note

An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, this, or new.target within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an ArrowFunction may contain references to super, the function object created in step #step-arrowfunction-evaluation-functioncreate is not made into a method by performing MakeMethod. An ArrowFunction that references super is always contained within a non-ArrowFunction and the necessary state to implement super is accessible via the scope that is captured by the function object of the ArrowFunction.

15.4 Method Definitions

Syntax

MethodDefinition[Yield, Await] : PropertyName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] AsyncGeneratorMethod[?Yield, ?Await] get PropertyName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } get ClassElementName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } set ClassElementName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } PropertySetParameterList : FormalParameter[~Yield, ~Await]

15.4.1 Static Semantics: Early Errors

MethodDefinition : PropertyNameClassElementName ( UniqueFormalParameters ) { FunctionBody } MethodDefinition : set PropertyNameClassElementName ( PropertySetParameterList ) { FunctionBody }

15.4.2 Static Semantics: HasDirectSuper

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. 1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. 2. Return FunctionBody Contains SuperCall.
MethodDefinition : get PropertyName ( ) { FunctionBody } get ClassElementName ( ) { FunctionBody }
  1. 1. Return FunctionBody Contains SuperCall.
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. If PropertySetParameterList Contains SuperCall is true, return true.
  2. 2. Return FunctionBody Contains SuperCall.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. 2. Return GeneratorBody Contains SuperCall.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. 2. Return AsyncGeneratorBody Contains SuperCall.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. If UniqueFormalParameters Contains SuperCall is true, return true.
  2. 2. Return AsyncFunctionBody Contains SuperCall.

15.4.3 Static Semantics: SpecialMethod

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. 1. Return false.
MethodDefinition : GeneratorMethod AsyncMethod AsyncGeneratorMethod get PropertyName ( ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Return true.

15.4.4 Runtime Semantics: DefineMethod

With parameter object and optional parameter functionPrototype.

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. If functionPrototype is present, then
    1. a. Let prototype be functionPrototype.
  6. 56. Else,
    1. a. Let prototype be %Function.prototype%.
  7. 67. Let sourceText be the source text matched by MethodDefinition.
  8. 78. Let closure be OrdinaryFunctionCreate(prototype, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, scope, privateScope).
  9. 89. Perform MakeMethod(closure, object).
  10. 910. Return the Record { [[Key]]: propKey, [[Closure]]: closure }.

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

With parameters object and enumerable.

MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. 1. Let methodDef be ? DefineMethod of MethodDefinition with argument object.
  2. 2. Perform SetFunctionNameDefineMethodProperty(methodDef.[[ClosureKey]], object, methodDef.[[KeyClosure]], enumerable).
  3. 3. Let desc be the PropertyDescriptor { [[Value]]: methodDef.[[Closure]], [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  4. 4. Return ? DefinePropertyOrThrow(object, methodDef.[[Key]], desc).
MethodDefinition : get PropertyName ( ) { FunctionBody } get ClassElementName ( ) { FunctionBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. Let sourceText be the source text matched by MethodDefinition.
  6. 56. Let formalParameterList be an instance of the production FormalParameters : [empty] .
  7. 67. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, FunctionBody, non-lexical-this, scope, privateScope).
  8. 78. Perform MakeMethod(closure, object).
  9. 89. Perform SetFunctionName(closure, propKey, "get").
  10. 9. Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  11. 10. Return ? DefinePropertyOrThrow(object, propKey, desc).
  12. 10. If propKey is a Private Name, then
    1. a. If propKey has a [[Kind]] field, then
      1. i. Assert: propKey.[[Kind]] is accessor.
      2. ii. Assert: propKey.[[Brand]] is object.
      3. iii. Assert: propKey does not have a [[Get]] field.
      4. iv. Set propKey.[[Get]] to closure.
    2. b. Else,
      1. i. Set propKey.[[Kind]] to accessor.
      2. ii. Set propKey.[[Brand]] to object.
      3. iii. Set propKey.[[Get]] to closure.
  13. 11. Else,
    1. a. Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
    2. b. Return ? DefinePropertyOrThrow(object, propKey, desc).
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. Let sourceText be the source text matched by MethodDefinition.
  6. 56. Let closure be OrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, scope, privateScope).
  7. 67. Perform MakeMethod(closure, object).
  8. 78. Perform SetFunctionName(closure, propKey, "set").
  9. 8. Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  10. 9. Return ? DefinePropertyOrThrow(object, propKey, desc).
  11. 9. If propKey is a Private Name, then
    1. a. If propKey has a [[Kind]] field, then
      1. i. Assert: propKey.[[Kind]] is accessor.
      2. ii. Assert: propKey.[[Brand]] is object.
      3. iii. Assert: propKey does not have a [[Set]] field.
      4. iv. Set propKey.[[Set]] to closure.
    2. b. Else,
      1. i. Set propKey.[[Kind]] to accessor.
      2. ii. Set propKey.[[Brand]] to object.
      3. iii. Set propKey.[[Set]] to closure.
  12. 10. Else,
    1. a. Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
    2. b. Return ? DefinePropertyOrThrow(object, propKey, desc).
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody } * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. Let sourceText be the source text matched by GeneratorMethod.
  6. 56. Let closure be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, scope, privateScope).
  7. 67. Perform MakeMethod(closure, object).
  8. 78. Perform SetFunctionName(closure, propKey).
  9. 89. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  10. 910. Perform DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  11. 1011. Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  12. 1112. Return ? DefinePropertyOrThrow(object, propKey, desc).
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. Let sourceText be the source text matched by AsyncGeneratorMethod.
  6. 56. Let closure be ! OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, scope, privateScope).
  7. 67. Perform ! MakeMethod(closure, object).
  8. 78. Perform ! SetFunctionName(closure, propKey).
  9. 89. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  10. 910. Perform ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  11. 1011. Let desc be PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  12. 1112. Return ? DefinePropertyOrThrow(object, propKey, desc).
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. Let propKey be the result of evaluating PropertyNameClassElementName.
  2. 2. ReturnIfAbrupt(propKey).
  3. 3. Let scope be the LexicalEnvironment of the running execution context.
  4. 4. Let privateScope be the running execution context's PrivateEnvironment.
  5. 45. Let sourceText be the source text matched by AsyncMethod.
  6. 56. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, scope, privateScope).
  7. 67. Perform ! MakeMethod(closure, object).
  8. 78. Perform !? SetFunctionNameDefineMethodProperty(propKey, object, closure, propKeyenumerable).
  9. 8. Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  10. 9. Return ? DefinePropertyOrThrow(object, propKey, desc).

15.5 Generator Function Definitions

Syntax

GeneratorMethod[Yield, Await] : * PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody } * ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorDeclaration[Yield, Await, Default] : function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } [+Default] function * ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorExpression : function * BindingIdentifier[+Yield, ~Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorBody : FunctionBody[+Yield, ~Await] YieldExpression[In, Await] : yield yield [no LineTerminator here] AssignmentExpression[?In, +Yield, ?Await] yield [no LineTerminator here] * AssignmentExpression[?In, +Yield, ?Await] Note 1

The syntactic context immediately following yield requires use of the InputElementRegExpOrTemplateTail lexical goal.

Note 2

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

Note 3

Abstract operations relating to generator objects are defined in 27.5.3.

15.5.1 Static Semantics: Early Errors

GeneratorMethod : * PropertyNameClassElementName ( UniqueFormalParameters ) { GeneratorBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

With parameter parameters scope and privateScope.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. 1. Let name be StringValue of BindingIdentifier.
  2. 2. Let sourceText be the source text matched by GeneratorDeclaration.
  3. 3. Let F be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, scope, privateScope).
  4. 4. Perform SetFunctionName(F, name).
  5. 5. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  6. 6. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  7. 7. Return F.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. 1. Let sourceText be the source text matched by GeneratorDeclaration.
  2. 2. Let F be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, scope, privateScope).
  3. 3. Perform SetFunctionName(F, "default").
  4. 4. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  5. 5. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  6. 6. Return F.
Note

An anonymous GeneratorDeclaration can only occur as part of an export default declaration, and its function code is therefore always strict mode code.

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

With optional parameter name.

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by GeneratorExpression.
  5. 45. Let closure be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, scope, privateScope).
  6. 56. Perform SetFunctionName(closure, name).
  7. 67. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  8. 78. Perform DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  9. 89. Return closure.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. 1. Assert: name is not present.
  2. 2. Set name to StringValue of BindingIdentifier.
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let funcEnv be NewDeclarativeEnvironment(scope).
  5. 5. Perform funcEnv.CreateImmutableBinding(name, false).
  6. 6. Let privateScope be the running execution context's PrivateEnvironment.
  7. 67. Let sourceText be the source text matched by GeneratorExpression.
  8. 78. Let closure be OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateScope).
  9. 89. Perform SetFunctionName(closure, name).
  10. 910. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
  11. 1011. Perform DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  12. 1112. Perform funcEnv.InitializeBinding(name, closure).
  13. 1213. Return closure.
Note

The BindingIdentifier in a GeneratorExpression can be referenced from inside the GeneratorExpression's FunctionBody to allow the generator code to call itself recursively. However, unlike in a GeneratorDeclaration, the BindingIdentifier in a GeneratorExpression cannot be referenced from and does not affect the scope enclosing the GeneratorExpression.

15.6 Async Generator Function Definitions

Syntax

AsyncGeneratorMethod[Yield, Await] : async [no LineTerminator here] * PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } async [no LineTerminator here] * ClassElementName[?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]opt ( FormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } AsyncGeneratorBody : FunctionBody[+Yield, +Await] Note 1

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.

Note 2

Abstract operations relating to async generator objects are defined in 27.6.3.

15.6.1 Static Semantics: Early Errors

AsyncGeneratorMethod : async * PropertyNameClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

With parameter parameters scope and privateScope.

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. 1. Let name be StringValue of BindingIdentifier.
  2. 2. Let sourceText be the source text matched by AsyncGeneratorDeclaration.
  3. 3. Let F be ! OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, scope, privateScope).
  4. 4. Perform ! SetFunctionName(F, name).
  5. 5. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  6. 6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  7. 7. Return F.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 1. Let sourceText be the source text matched by AsyncGeneratorDeclaration.
  2. 2. Let F be OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, scope, privateScope).
  3. 3. Perform SetFunctionName(F, "default").
  4. 4. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  5. 5. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  6. 6. Return F.
Note

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

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

With optional parameter name.

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by AsyncGeneratorExpression.
  5. 45. Let closure be ! OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, scope, privateScope).
  6. 56. Perform SetFunctionName(closure, name).
  7. 67. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  8. 78. Perform ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  9. 89. Return closure.
AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. 1. Assert: name is not present.
  2. 2. Set name to StringValue of BindingIdentifier.
  3. 3. Let scope be the running execution context's LexicalEnvironment.
  4. 4. Let funcEnv be ! NewDeclarativeEnvironment(scope).
  5. 5. Perform ! funcEnv.CreateImmutableBinding(name, false).
  6. 6. Let privateScope be the running execution context's PrivateEnvironment.
  7. 67. Let sourceText be the source text matched by AsyncGeneratorExpression.
  8. 78. Let closure be ! OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateScope).
  9. 89. Perform ! SetFunctionName(closure, name).
  10. 910. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
  11. 1011. Perform ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  12. 1112. Perform ! funcEnv.InitializeBinding(name, closure).
  13. 1213. Return closure.
Note

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.

15.7 Class Definitions

Syntax

ClassDeclaration[Yield, Await, Default] : class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await] [+Default] class ClassTail[?Yield, ?Await] ClassExpression[Yield, Await] : class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await] ClassTail[Yield, Await] : ClassHeritage[?Yield, ?Await]opt { ClassBody[?Yield, ?Await]opt } ClassHeritage[Yield, Await] : extends LeftHandSideExpression[?Yield, ?Await] ClassBody[Yield, Await] : ClassElementList[?Yield, ?Await]ClassElementList[?Yield, ?Await] ClassElementList[Yield, Await] : ClassElement[?Yield, ?Await] ClassElementList[?Yield, ?Await] ClassElement[?Yield, ?Await] ClassElement[Yield, Await] : MethodDefinition[?Yield, ?Await] static MethodDefinition[?Yield, ?Await] FieldDefinition[?Yield, ?Await] ; static FieldDefinition[?Yield, ?Await] ; ; FieldDefinition[Yield, Await] : ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt ClassElementName[Yield, Await] : PropertyName[?Yield, ?Await] PrivateIdentifier Note

A class definition is always strict mode code.

15.7.1 Static Semantics: Early Errors

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ; FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier

15.7.2 Static Semantics: ClassElementKind

ClassElement : MethodDefinition
  1. 1. If PropName of MethodDefinition is "constructor", return ConstructorMethod.
  2. 2. Return NonConstructorMethod.
ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  1. 1. Return NonConstructorMethod.
ClassElement : ;
  1. 1. Return empty.

15.7.4 Static Semantics: IsStatic

ClassElement : MethodDefinition
  1. 1. Return false.
ClassElement : static MethodDefinition
  1. 1. Return true.
ClassElement : FieldDefinition ;
  1. 1. Return false.
ClassElement : static FieldDefinition ;
  1. 1. Return true.
ClassElement : ; ;
  1. 1. Return false.

15.7.7 Static Semantics: AllPrivateIdentifiersValid

With parameter names.

MemberExpression : MemberExpression . PrivateIdentifier
  1. 1. If StringValue of PrivateIdentifier is in names, return true.
  2. 2. Return false.
CallExpression : CallExpression . PrivateIdentifier
  1. 1. If StringValue of PrivateIdentifier is in names, return true.
  2. 2. Return false.
OptionalChain[Yield, Await] : ?. PrivateIdentifier
  1. 1. If StringValue of PrivateIdentifier is in names, return true.
  2. 2. Return false.
OptionalChain[Yield, Await] : OptionalChain[?Yield, ?Await] . PrivateIdentifier
  1. 1. If StringValue of PrivateIdentifier is in names, return true.
  2. 2. Return false.
ClassBody : ClassElementList
  1. 1. Let newNames be a copy of names.
  2. 2. Append to newNames the elements of PrivateBoundIdentifiers of ClassBody.
  3. 3. Return AllPrivateIdentifiersValid of ClassElementList with argument newNames.

For all other grammatical productions, recurse on subexpressions/substatements, passing in the names of the caller. If all pieces return true, then return true. If any returns false, return false.

15.7.8 Static Semantics: PrivateBoundIdentifiers

FieldDefinition : ClassElementName Initializeropt
  1. 1. Return PrivateBoundIdentifiers of ClassElementName.
ClassElementName : PrivateIdentifier
  1. 1. Return a List whose sole element is the StringValue of PrivateIdentifier.
ClassElementName : PropertyName ClassElement : ;
  1. 1. Return a new empty List.
ClassElementList : ClassElementList ClassElement
  1. 1. Let names be PrivateBoundIdentifiers of ClassElementList.
  2. 2. Append to names the elements of PrivateBoundIdentifiers of ClassElement.
  3. 3. Return names.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 1. Return PrivateBoundIdentifiers of ClassElementName.

15.7.9 Static Semantics: ContainsArguments

IdentifierReference : Identifier
  1. 1. If the StringValue of Identifier is "arguments", return true.
  2. 2. Else, return false.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } FunctionDeclaration : function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
  1. 1. Return false.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 1. Return the result of ContainsArguments of ClassElementName.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 1. Return the result of ContainsArguments of ClassElementName.
GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. 1. Return false.
ClassBody : ClassElementList
  1. 1. Return false.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 1. Return the result of ContainsArguments of ClassElementName.
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 1. Return false.

For all other grammatical productions, recurse on all nonterminals. If any piece returns true, then return true. Otherwise return false.

15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation

With parameter homeObject.

FieldDefinition : ClassElementName Initializeropt
  1. 1. Let name be the result of evaluating ClassElementName.
  2. 2. ReturnIfAbrupt(name).
  3. 3. If Initializeropt is present, then
    1. a. Let lex be the LexicalEnvironment of the running execution context.
    2. b. Let formalParameterList be an instance of the production FormalParameters : [empty] .
    3. c. Let privateScope be the running execution context's PrivateEnvironment.
    4. d. Let initializer be ! OrdinaryFunctionCreate(Method, formalParameterList, Initializer, lex, privateScope).
    5. e. Perform MakeMethod(initializer, homeObject).
    6. f. Set initializer.[[ClassFieldInitializer]] to true.
    7. g. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
  4. 4. Else,
    1. a. Let initializer be empty.
    2. b. Let isAnonymousFunctionDefinition be false.
  5. 5. Return the ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.

15.7.11 Runtime Semantics: ClassElementEvaluation

With parameters object and enumerable.

ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  1. 1. Return ClassFieldDefinitionEvaluation of FieldDefinition with argument object.
ClassElement : MethodDefinition ClassElement : static MethodDefinition
  1. 1. Return PropertyDefinitionEvaluation of MethodDefinition with arguments object and enumerable.
ClassElement : ;
  1. 1. Return.

15.7.715.7.12 Runtime Semantics: ClassDefinitionEvaluation

With parameters classBinding and className.

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. 1. Let env be the LexicalEnvironment of the running execution context.
  2. 2. Let classScope be NewDeclarativeEnvironment(env).
  3. 3. If classBinding is not undefined, then
    1. a. Perform classScope.CreateImmutableBinding(classBinding, true).
  4. 4. Let outerPrivateEnvironment be the running execution context's PrivateEnvironment.
  5. 5. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
  6. 6. If ClassBodyopt is present, then
    1. a. For each element dn of the PrivateBoundIdentifiers of ClassBodyopt, do
      1. i. Perform classPrivateEnvironment.CreateImmutableBinding(dn, true).
  7. 47. If ClassHeritageopt is not present, then
    1. a. Let protoParent be %Object.prototype%.
    2. b. Let constructorParent be %Function.prototype%.
  8. 58. Else,
    1. a. Set the running execution context's LexicalEnvironment to classScope.
    2. b. NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage.
    3. bc. Let superclassRef be the result of evaluating ClassHeritage.
    4. cd. Set the running execution context's LexicalEnvironment to env.
    5. de. Let superclass be ? GetValue(superclassRef).
    6. ef. If superclass is null, then
      1. i. Let protoParent be null.
      2. ii. Let constructorParent be %Function.prototype%.
    7. fg. Else if IsConstructor(superclass) is false, throw a TypeError exception.
    8. gh. Else,
      1. i. Let protoParent be ? Get(superclass, "prototype").
      2. ii. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
      3. iii. Let constructorParent be superclass.
  9. 69. Let proto be ! OrdinaryObjectCreate(protoParent).
  10. 710. If ClassBodyopt is not present, let constructor be empty.
  11. 811. Else, let constructor be ConstructorMethod of ClassBody.
  12. 912. Set the running execution context's LexicalEnvironment to classScope.
  13. 13. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
  14. 1014. If constructor is empty, then
    1. a. Let steps be the algorithm steps defined in Default Constructor Functions.
    2. b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent).
  15. 1115. Else,
    1. a. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent.
    2. b. Let F be constructorInfo.[[Closure]].
    3. c. Perform ! MakeClassConstructor(F).
    4. d. Perform ! SetFunctionName(F, className).
  16. 1216. Perform ! MakeConstructor(F, false, proto).
  17. 1317. If ClassHeritageopt is present, set F.[[ConstructorKind]] to derived.
  18. 1418. Perform ! CreateMethodProperty(proto, "constructor", F).
  19. 1519. If ClassBodyopt is not present, let methodselements be a new empty List.
  20. 1620. Else, let methodselements be NonConstructorMethodDefinitions of ClassBody.
  21. 21. Let instanceFields be a new empty List.
  22. 22. Let staticFields be a new empty List.
  23. 1723. For each ClassElement me of methodselements, do
    1. a. If IsStatic of me is false, then
      1. i. Let statusfield be PropertyDefinitionEvaluationClassElementEvaluation of me with arguments proto and false.
    2. b. Else,
      1. i. Let statusfield be PropertyDefinitionEvaluationClassElementEvaluation of me with arguments F and false.
    3. c. If statusfield is an abrupt completion, then
      1. i. Set the running execution context's LexicalEnvironment to env.
      2. ii. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
      3. iiiii. Return Completion(statusfield).
    4. d. If field is a ClassFieldDefinition Record, then
      1. i. If IsStatic of e is false, append field to instanceFields.
      2. ii. Else, append field to staticFields.
  24. 1824. Set the running execution context's LexicalEnvironment to env.
  25. 1925. If classBinding is not undefined, then
    1. a. Perform classScope.InitializeBinding(classBinding, F).
  26. 26. Set F.[[Fields]] to instanceFields.
  27. 27. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P.[[Kind]] is either method or accessor and P.[[Brand]] is proto, then
    1. a. Set F.[[PrivateBrand]] to proto.
  28. 28. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P.[[Kind]] is either method or accessor and P.[[Brand]] is F, then
    1. a. Let result be PrivateBrandAdd(F, F).
    2. b. If result is an abrupt completion, then
      1. i. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
      2. ii. Return result.
  29. 29. For each element fieldRecord of staticFields, do
    1. a. Let result be DefineField(F, fieldRecord).
    2. b. If result is an abrupt completion, then
      1. i. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
      2. ii. Return result.
  30. 30. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
  31. 2031. Return F.

15.7.915.7.14 Runtime Semantics: Evaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. 1. Perform ? BindingClassDeclarationEvaluation of this ClassDeclaration.
  2. 2. Return NormalCompletion(empty).
Note

ClassDeclaration : class ClassTail only occurs as part of an ExportDeclaration and is never directly evaluated.

ClassExpression : class ClassTail
  1. 1. Let value be ? ClassDefinitionEvaluation of ClassTail with arguments undefined and "".
  2. 2. Set value.[[SourceText]] to the source text matched by ClassExpression.
  3. 3. Return value.
ClassExpression : class BindingIdentifier ClassTail
  1. 1. Let className be StringValue of BindingIdentifier.
  2. 2. Let value be ? ClassDefinitionEvaluation of ClassTail with arguments className and className.
  3. 3. Set value.[[SourceText]] to the source text matched by ClassExpression.
  4. 4. Return value.
ClassElementName : PropertyName
  1. 1. Return the result of evaluating PropertyName.
ClassElementName : PrivateIdentifier
  1. 1. Let privateIdentifier be StringValue of PrivateIdentifier.
  2. 2. Let privateEnvRec be the running execution context's PrivateEnvironment.
  3. 3. Assert: privateEnvRec has a binding for privateIdentifier.
  4. 4. If the binding for privateIdentifier in privateEnvRec is an uninitialized binding, then
    1. a. Let privateName be NewPrivateName(privateIdentifier).
    2. b. Perform ! privateEnvRec.InitializeBinding(privateIdentifier, privateName).
  5. 5. Else,
    1. a. Let privateName be ! privateEnvRec.GetBindingValue(privateIdentifier, true).
    2. b. NOTE: The only case where this may occur is in getter/setter pairs; other duplicates are prohibited as a Syntax Error.
    3. c. Assert: privateName is a Private Name.
  6. 6. Assert: privateName.[[Description]] is privateIdentifier.
  7. 7. Return privateName.

15.8 Async Function Definitions

Syntax

AsyncFunctionDeclaration[Yield, Await, Default] : async [no LineTerminator here] function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } [+Default] async [no LineTerminator here] function ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionExpression : async [no LineTerminator here] function BindingIdentifier[~Yield, +Await]opt ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncMethod[Yield, Await] : async [no LineTerminator here] PropertyName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncMethod[Yield, Await] : async [no LineTerminator here] ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionBody : FunctionBody[~Yield, +Await] AwaitExpression[Yield] : await UnaryExpression[?Yield, +Await] Note 1

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

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:

Note 2

Unlike YieldExpression, it is a Syntax Error to omit the operand of an AwaitExpression. You must await something.

15.8.1 Static Semantics: Early Errors

AsyncMethod : async PropertyNameClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }

15.8.2 Runtime Semantics: InstantiateAsyncFunctionObject

With parameter parameters scope and privateScope.

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 1. Let name be StringValue of BindingIdentifier.
  2. 2. Let sourceText be the source text matched by AsyncFunctionDeclaration.
  3. 3. Let F be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, scope, privateScope).
  4. 4. Perform ! SetFunctionName(F, name).
  5. 5. Return F.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. 1. Let sourceText be the source text matched by AsyncFunctionDeclaration.
  2. 2. Let F be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, scope, privateScope).
  3. 3. Perform ! SetFunctionName(F, "default").
  4. 4. Return F.

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

With optional parameter name.

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by AsyncFunctionExpression.
  5. 45. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, scope, privateScope).
  6. 56. Perform SetFunctionName(closure, name).
  7. 67. Return closure.
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 1. Assert: name is not present.
  2. 2. Set name to StringValue of BindingIdentifier.
  3. 3. Let scope be the LexicalEnvironment of the running execution context.
  4. 4. Let funcEnv be ! NewDeclarativeEnvironment(scope).
  5. 5. Perform ! funcEnv.CreateImmutableBinding(name, false).
  6. 6. Let privateScope be the running execution context's PrivateEnvironment.
  7. 67. Let sourceText be the source text matched by AsyncFunctionExpression.
  8. 78. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateScope).
  9. 89. Perform ! SetFunctionName(closure, name).
  10. 910. Perform ! funcEnv.InitializeBinding(name, closure).
  11. 1011. Return closure.
Note

The BindingIdentifier in an AsyncFunctionExpression can be referenced from inside the AsyncFunctionExpression's AsyncFunctionBody to allow the function to call itself recursively. However, unlike in a FunctionDeclaration, the BindingIdentifier in a AsyncFunctionExpression cannot be referenced from and does not affect the scope enclosing the AsyncFunctionExpression.

15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression

With optional parameter name.

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by AsyncArrowFunction.
  5. 45. Let parameters be AsyncArrowBindingIdentifier.
  6. 56. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, scope, privateScope).
  7. 67. Perform SetFunctionName(closure, name).
  8. 78. Return closure.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. 1. If name is not present, set name to "".
  2. 2. Let scope be the LexicalEnvironment of the running execution context.
  3. 3. Let privateScope be the running execution context's PrivateEnvironment.
  4. 34. Let sourceText be the source text matched by AsyncArrowFunction.
  5. 45. Let head be the AsyncArrowHead that is covered by CoverCallExpressionAndAsyncArrowHead.
  6. 56. Let parameters be the ArrowFormalParameters of head.
  7. 67. Let closure be ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, scope, privateScope).
  8. 78. Perform SetFunctionName(closure, name).
  9. 89. Return closure.

15.10.2.2 Expression Rules

Note

A potential tail position call that is immediately followed by return GetValue of the call result is also a possible tail position call. A function call cannot return a Reference Record, so such a GetValue operation will always return the same value as the actual function call result.

AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression AwaitExpression CallExpression : SuperCall CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier NewExpression : new NewExpression MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral
  1. 1. Return false.
Expression : AssignmentExpression Expression , AssignmentExpression
  1. 1. Return HasCallInTailPosition of AssignmentExpression with argument call.
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. 1. Let has be HasCallInTailPosition of the first AssignmentExpression with argument call.
  2. 2. If has is true, return true.
  3. 3. Return HasCallInTailPosition of the second AssignmentExpression with argument call.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. 1. Return HasCallInTailPosition of BitwiseORExpression with argument call.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. 1. Return HasCallInTailPosition of LogicalANDExpression with argument call.
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. 1. Return HasCallInTailPosition of BitwiseORExpression with argument call.
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. 1. If this CallExpression is call, return true.
  2. 2. Return false.
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. 1. Return HasCallInTailPosition of OptionalChain with argument call.
OptionalChain : ?. [ Expression ] ?. IdentifierName OptionalChain [ Expression ] OptionalChain . IdentifierName
  1. 1. Return false.
OptionalChain : ?. Arguments OptionalChain Arguments
  1. 1. If this OptionalChain is call, return true.
  2. 2. Return false.
MemberExpression : MemberExpression TemplateLiteral
  1. 1. If this MemberExpression is call, return true.
  2. 2. Return false.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 1. Let expr be the ParenthesizedExpression that is covered by CoverParenthesizedExpressionAndArrowParameterList.
  2. 2. Return HasCallInTailPosition of expr with argument call.
ParenthesizedExpression : ( Expression )
  1. 1. Return HasCallInTailPosition of Expression with argument call.

16.1.1 Static Semantics: Early Errors

Script : ScriptBody ScriptBody : StatementList

16.1.6 ScriptEvaluation ( scriptRecord )

The abstract operation ScriptEvaluation takes argument scriptRecord. It performs the following steps when called:

  1. 1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]].
  2. 2. Let scriptContext be a new ECMAScript code execution context.
  3. 3. Set the Function of scriptContext to null.
  4. 4. Set the Realm of scriptContext to scriptRecord.[[Realm]].
  5. 5. Set the ScriptOrModule of scriptContext to scriptRecord.
  6. 6. Set the VariableEnvironment of scriptContext to globalEnv.
  7. 7. Set the LexicalEnvironment of scriptContext to globalEnv.
  8. 8. Let privateEnv be NewDeclarativeEnvironment(null).
  9. 9. Set the PrivateEnvironment of scriptContext to privateEnv.
  10. 810. Suspend the currently running execution context.
  11. 911. Push scriptContext onto the execution context stack; scriptContext is now the running execution context.
  12. 1012. Let scriptBody be scriptRecord.[[ECMAScriptCode]].
  13. 1113. Let result be GlobalDeclarationInstantiation(scriptBody, globalEnv).
  14. 1214. If result.[[Type]] is normal, then
    1. a. Set result to the result of evaluating scriptBody.
  15. 1315. If result.[[Type]] is normal and result.[[Value]] is empty, then
    1. a. Set result to NormalCompletion(undefined).
  16. 1416. Suspend scriptContext and remove it from the execution context stack.
  17. 1517. Assert: The execution context stack is not empty.
  18. 1618. Resume the context that is now on the top of the execution context stack as the running execution context.
  19. 1719. Return Completion(result).

16.1.7 GlobalDeclarationInstantiation ( script, env )

Note 1

When an execution context is established for evaluating scripts, declarations are instantiated in the current global environment. Each global binding declared in the code is instantiated.

The abstract operation GlobalDeclarationInstantiation takes arguments script (a Parse Node for ScriptBody) and env (an Environment Record). script is the ScriptBody for which the execution context is being established. env is the global environment in which bindings are to be created. It performs the following steps when called:

  1. 1. Assert: env is a global Environment Record.
  2. 2. Let lexNames be the LexicallyDeclaredNames of script.
  3. 3. Let varNames be the VarDeclaredNames of script.
  4. 4. For each element name of lexNames, do
    1. a. If env.HasVarDeclaration(name) is true, throw a SyntaxError exception.
    2. b. If env.HasLexicalDeclaration(name) is true, throw a SyntaxError exception.
    3. c. Let hasRestrictedGlobal be ? env.HasRestrictedGlobalProperty(name).
    4. d. If hasRestrictedGlobal is true, throw a SyntaxError exception.
  5. 5. For each element name of varNames, do
    1. a. If env.HasLexicalDeclaration(name) is true, throw a SyntaxError exception.
  6. 6. Let varDeclarations be the VarScopedDeclarations of script.
  7. 7. Let functionsToInitialize be a new empty List.
  8. 8. Let declaredFunctionNames be a new empty List.
  9. 9. For each element d of varDeclarations, in reverse List order, do
    1. a. If d is neither a VariableDeclaration nor a ForBinding nor a BindingIdentifier, then
      1. i. Assert: d is either a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration.
      2. ii. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
      3. iii. Let fn be the sole element of the BoundNames of d.
      4. iv. If fn is not an element of declaredFunctionNames, then
        1. 1. Let fnDefinable be ? env.CanDeclareGlobalFunction(fn).
        2. 2. If fnDefinable is false, throw a TypeError exception.
        3. 3. Append fn to declaredFunctionNames.
        4. 4. Insert d as the first element of functionsToInitialize.
  10. 10. Let declaredVarNames be a new empty List.
  11. 11. For each element d of varDeclarations, do
    1. a. If d is a VariableDeclaration, a ForBinding, or a BindingIdentifier, then
      1. i. For each String vn of the BoundNames of d, do
        1. 1. If vn is not an element of declaredFunctionNames, then
          1. a. Let vnDefinable be ? env.CanDeclareGlobalVar(vn).
          2. b. If vnDefinable is false, throw a TypeError exception.
          3. c. If vn is not an element of declaredVarNames, then
            1. i. Append vn to declaredVarNames.
  12. 12. NOTE: No abnormal terminations occur after this algorithm step if the global object is an ordinary object. However, if the global object is a Proxy exotic object it may exhibit behaviours that cause abnormal terminations in some of the following steps.
  13. 13. NOTE: Annex B.3.3.2 adds additional steps at this point.
  14. 14. Let lexDeclarations be the LexicallyScopedDeclarations of script.
  15. 15. Let privateEnv be NewDeclarativeEnvironment(null).
  16. 1516. For each element d of lexDeclarations, do
    1. a. NOTE: Lexically declared names are only instantiated here but not initialized.
    2. b. For each element dn of the BoundNames of d, do
      1. i. If IsConstantDeclaration of d is true, then
        1. 1. Perform ? env.CreateImmutableBinding(dn, true).
      2. ii. Else,
        1. 1. Perform ? env.CreateMutableBinding(dn, false).
  17. 1617. For each Parse Node f of functionsToInitialize, do
    1. a. Let fn be the sole element of the BoundNames of f.
    2. b. Let fo be InstantiateFunctionObject of f with argument arguments env and privateEnv.
    3. c. Perform ? env.CreateGlobalFunctionBinding(fn, fo, false).
  18. 1718. For each String vn of declaredVarNames, do
    1. a. Perform ? env.CreateGlobalVarBinding(vn, false).
  19. 1819. Return NormalCompletion(empty).
Note 2

Early errors specified in 16.1.1 prevent name conflicts between function/var declarations and let/const/class declarations as well as redeclaration of let/const/class bindings for declaration contained within a single Script. However, such conflicts and redeclarations that span more than one Script are detected as runtime errors during GlobalDeclarationInstantiation. If any such errors are detected, no bindings are instantiated for the script. However, if the global object is defined using Proxy exotic objects then the runtime tests for conflicting declarations may be unreliable resulting in an abrupt completion and some global declarations not being instantiated. If this occurs, the code for the Script is not evaluated.

Unlike explicit var or function declarations, properties that are directly created on the global object result in global bindings that may be shadowed by let/const/class declarations.

16.2.1.1 Static Semantics: Early Errors

ModuleBody : ModuleItemList Note

The duplicate ExportedNames rule implies that multiple export default ExportDeclaration items within a ModuleBody is a Syntax Error. Additional error conditions relating to conflicting or duplicate declarations are checked during module linking prior to evaluation of a Module. If any such errors are detected the Module is not evaluated.

16.2.1.6.4 InitializeEnvironment ( ) Concrete Method

The InitializeEnvironment concrete method of a Source Text Module Record module takes no arguments. It performs the following steps when called:

  1. 1. For each ExportEntry Record e of module.[[IndirectExportEntries]], do
    1. a. Let resolution be ? module.ResolveExport(e.[[ExportName]]).
    2. b. If resolution is null or "ambiguous", throw a SyntaxError exception.
    3. c. Assert: resolution is a ResolvedBinding Record.
  2. 2. Assert: All named exports from module are resolvable.
  3. 3. Let realm be module.[[Realm]].
  4. 4. Assert: realm is not undefined.
  5. 5. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]).
  6. 6. Set module.[[Environment]] to env.
  7. 7. For each ImportEntry Record in of module.[[ImportEntries]], do
    1. a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]).
    2. b. NOTE: The above call cannot fail because imported module requests are a subset of module.[[RequestedModules]], and these have been resolved earlier in this algorithm.
    3. c. If in.[[ImportName]] is "*", then
      1. i. Let namespace be ? GetModuleNamespace(importedModule).
      2. ii. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true).
      3. iii. Call env.InitializeBinding(in.[[LocalName]], namespace).
    4. d. Else,
      1. i. Let resolution be ? importedModule.ResolveExport(in.[[ImportName]]).
      2. ii. If resolution is null or "ambiguous", throw a SyntaxError exception.
      3. iii. If resolution.[[BindingName]] is "*namespace*", then
        1. 1. Let namespace be ? GetModuleNamespace(resolution.[[Module]]).
        2. 2. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true).
        3. 3. Call env.InitializeBinding(in.[[LocalName]], namespace).
      4. iv. Else,
        1. 1. Call env.CreateImportBinding(in.[[LocalName]], resolution.[[Module]], resolution.[[BindingName]]).
  8. 8. Let moduleContext be a new ECMAScript code execution context.
  9. 9. Set the Function of moduleContext to null.
  10. 10. Assert: module.[[Realm]] is not undefined.
  11. 11. Set the Realm of moduleContext to module.[[Realm]].
  12. 12. Set the ScriptOrModule of moduleContext to module.
  13. 13. Set the VariableEnvironment of moduleContext to module.[[Environment]].
  14. 14. Set the LexicalEnvironment of moduleContext to module.[[Environment]].
  15. 15. Set module.[[Context]] to moduleContext.
  16. 16. Push moduleContext onto the execution context stack; moduleContext is now the running execution context.
  17. 17. Let code be module.[[ECMAScriptCode]].
  18. 18. Let varDeclarations be the VarScopedDeclarations of code.
  19. 19. Let declaredVarNames be a new empty List.
  20. 20. For each element d of varDeclarations, do
    1. a. For each element dn of the BoundNames of d, do
      1. i. If dn is not an element of declaredVarNames, then
        1. 1. Perform ! env.CreateMutableBinding(dn, false).
        2. 2. Call env.InitializeBinding(dn, undefined).
        3. 3. Append dn to declaredVarNames.
  21. 21. Let lexDeclarations be the LexicallyScopedDeclarations of code.
  22. 22. Let privateEnv be NewDeclarativeEnvironment(null).
  23. 2223. For each element d of lexDeclarations, do
    1. a. For each element dn of the BoundNames of d, do
      1. i. If IsConstantDeclaration of d is true, then
        1. 1. Perform ! env.CreateImmutableBinding(dn, true).
      2. ii. Else,
        1. 1. Perform ! env.CreateMutableBinding(dn, false).
      3. iii. If d is a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration, then
        1. 1. Let fo be InstantiateFunctionObject of d with argument arguments env and privateEnv.
        2. 2. Call env.InitializeBinding(dn, fo).
  24. 2324. Remove moduleContext from the execution context stack.
  25. 2425. Return NormalCompletion(empty).

19.2.1 eval ( x )

The eval function is the %eval% intrinsic object. When the eval function is called with one argument x, the following steps are taken:

  1. 1. Assert: The execution context stack has at least two elements.
  2. 2. Let callerContext be the second to top element of the execution context stack.
  3. 3. Let callerRealm be callerContext's Realm.
  4. 4. Return ? PerformEval(x, callerRealm, false, false).

19.2.1.1 PerformEval ( x, callerRealm, strictCaller, direct )

The abstract operation PerformEval takes arguments x, callerRealm, strictCaller, and direct. It performs the following steps when called:

  1. 1. Assert: If direct is false, then strictCaller is also false.
  2. 2. If Type(x) is not String, return x.
  3. 3. Let evalRealm be the current Realm Record.
  4. 4. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
  5. 5. Let inFunction be false.
  6. 6. Let inMethod be false.
  7. 7. Let inDerivedConstructor be false.
  8. 8. Let inClassFieldInitializer be false.
  9. 89. If direct is true, then
    1. a. Let thisEnvRec be ! GetThisEnvironment().
    2. b. If thisEnvRec is a function Environment Record, then
      1. i. Let F be thisEnvRec.[[FunctionObject]].
      2. ii. Set inFunction to true.
      3. iii. Set inMethod to thisEnvRec.HasSuperBinding().
      4. iv. If F.[[ConstructorKind]] is derived, set inDerivedConstructor to true.
      5. v. Set inClassFieldInitializer to F.[[ClassFieldInitializer]].
  10. 910. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection:
    1. a. Let script be ParseText(! StringToCodePoints(x), Script).
    2. b. If script is a List of errors, throw a SyntaxError exception.
    3. c. If script Contains ScriptBody is false, return undefined.
    4. d. Let body be the ScriptBody of script.
    5. e. If inFunction is false, and body Contains NewTarget, throw a SyntaxError exception.
    6. f. If inMethod is false, and body Contains SuperProperty, throw a SyntaxError exception.
    7. g. If inDerivedConstructor is false, and body Contains SuperCall, throw a SyntaxError exception.
    8. h. If inClassFieldInitializer is true, and ContainsArguments of body is true, throw a SyntaxError exception.
  11. 1011. If strictCaller is true, let strictEval be true.
  12. 1112. Else, let strictEval be IsStrict of script.
  13. 1213. Let runningContext be the running execution context.
  14. 1314. NOTE: If direct is true, runningContext will be the execution context that performed the direct eval. If direct is false, runningContext will be the execution context for the invocation of the eval function.
  15. 1415. If direct is true, then
    1. a. Let lexEnv be NewDeclarativeEnvironment(runningContext's LexicalEnvironment).
    2. b. Let varEnv be runningContext's VariableEnvironment.
    3. c. Let privateEnv be runningContext's PrivateEnvironment.
  16. 1516. Else,
    1. a. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]).
    2. b. Let varEnv be evalRealm.[[GlobalEnv]].
    3. c. Let privateEnv be NewDeclarativeEnvironment(null).
  17. 1617. If strictEval is true, set varEnv to lexEnv.
  18. 1718. If runningContext is not already suspended, suspend runningContext.
  19. 1819. Let evalContext be a new ECMAScript code execution context.
  20. 1920. Set evalContext's Function to null.
  21. 2021. Set evalContext's Realm to evalRealm.
  22. 2122. Set evalContext's ScriptOrModule to runningContext's ScriptOrModule.
  23. 2223. Set evalContext's VariableEnvironment to varEnv.
  24. 2324. Set evalContext's LexicalEnvironment to lexEnv.
  25. 25. Set evalContext's PrivateEnvironment to privateEnv.
  26. 2426. Push evalContext onto the execution context stack; evalContext is now the running execution context.
  27. 2527. Let result be EvalDeclarationInstantiation(body, varEnv, lexEnv, privateEnv, strictEval).
  28. 2628. If result.[[Type]] is normal, then
    1. a. Set result to the result of evaluating body.
  29. 2729. If result.[[Type]] is normal and result.[[Value]] is empty, then
    1. a. Set result to NormalCompletion(undefined).
  30. 2830. Suspend evalContext and remove it from the execution context stack.
  31. 2931. Resume the context that is now on the top of the execution context stack as the running execution context.
  32. 3032. Return Completion(result).
Note

The eval code cannot instantiate variable or function bindings in the variable environment of the calling context that invoked the eval if the calling context is evaluating formal parameter initializers or if either the code of the calling context or the eval code is strict mode code. Instead such bindings are instantiated in a new VariableEnvironment that is only accessible to the eval code. Bindings introduced by let, const, or class declarations are always instantiated in a new LexicalEnvironment.

19.2.1.3 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict )

The abstract operation EvalDeclarationInstantiation takes arguments body, varEnv, lexEnv, privateEnv, and strict. It performs the following steps when called:

  1. 1. Let varNames be the VarDeclaredNames of body.
  2. 2. Let varDeclarations be the VarScopedDeclarations of body.
  3. 3. If strict is false, then
    1. a. If varEnv is a global Environment Record, then
      1. i. For each element name of varNames, do
        1. 1. If varEnv.HasLexicalDeclaration(name) is true, throw a SyntaxError exception.
        2. 2. NOTE: eval will not create a global var declaration that would be shadowed by a global lexical declaration.
    2. b. Let thisEnv be lexEnv.
    3. c. Assert: The following loop will terminate.
    4. d. Repeat, while thisEnv is not the same as varEnv,
      1. i. If thisEnv is not an object Environment Record, then
        1. 1. NOTE: The environment of with statements cannot contain any lexical declaration so it doesn't need to be checked for var/let hoisting conflicts.
        2. 2. For each element name of varNames, do
          1. a. If thisEnv.HasBinding(name) is true, then
            1. i. Throw a SyntaxError exception.
            2. ii. NOTE: Annex B.3.5 defines alternate semantics for the above step.
          2. b. NOTE: A direct eval will not hoist var declaration over a like-named lexical declaration.
      2. ii. Set thisEnv to thisEnv.[[OuterEnv]].
  4. 4. Let privateIdentifiers be a new empty List.
  5. 5. Let privEnv be privateEnv.
  6. 6. Repeat, while privEnv is not null,
    1. a. For each binding named N in privEnv, do
      1. i. If privateIdentifiers does not contain N, append N to privateIdentifiers.
    2. b. Set privEnv to privEnv.[[OuterEnv]].
  7. 7. If AllPrivateIdentifiersValid of body with argument privateIdentifiers is false, throw a SyntaxError exception.
  8. 48. Let functionsToInitialize be a new empty List.
  9. 59. Let declaredFunctionNames be a new empty List.
  10. 610. For each element d of varDeclarations, in reverse List order, do
    1. a. If d is neither a VariableDeclaration nor a ForBinding nor a BindingIdentifier, then
      1. i. Assert: d is either a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration.
      2. ii. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
      3. iii. Let fn be the sole element of the BoundNames of d.
      4. iv. If fn is not an element of declaredFunctionNames, then
        1. 1. If varEnv is a global Environment Record, then
          1. a. Let fnDefinable be ? varEnv.CanDeclareGlobalFunction(fn).
          2. b. If fnDefinable is false, throw a TypeError exception.
        2. 2. Append fn to declaredFunctionNames.
        3. 3. Insert d as the first element of functionsToInitialize.
  11. 711. NOTE: Annex B.3.3.3 adds additional steps at this point.
  12. 812. Let declaredVarNames be a new empty List.
  13. 913. For each element d of varDeclarations, do
    1. a. If d is a VariableDeclaration, a ForBinding, or a BindingIdentifier, then
      1. i. For each String vn of the BoundNames of d, do
        1. 1. If vn is not an element of declaredFunctionNames, then
          1. a. If varEnv is a global Environment Record, then
            1. i. Let vnDefinable be ? varEnv.CanDeclareGlobalVar(vn).
            2. ii. If vnDefinable is false, throw a TypeError exception.
          2. b. If vn is not an element of declaredVarNames, then
            1. i. Append vn to declaredVarNames.
  14. 1014. NOTE: No abnormal terminations occur after this algorithm step unless varEnv is a global Environment Record and the global object is a Proxy exotic object.
  15. 1115. Let lexDeclarations be the LexicallyScopedDeclarations of body.
  16. 1216. For each element d of lexDeclarations, do
    1. a. NOTE: Lexically declared names are only instantiated here but not initialized.
    2. b. For each element dn of the BoundNames of d, do
      1. i. If IsConstantDeclaration of d is true, then
        1. 1. Perform ? lexEnv.CreateImmutableBinding(dn, true).
      2. ii. Else,
        1. 1. Perform ? lexEnv.CreateMutableBinding(dn, false).
  17. 1317. For each Parse Node f of functionsToInitialize, do
    1. a. Let fn be the sole element of the BoundNames of f.
    2. b. Let fo be InstantiateFunctionObject of f with argument arguments lexEnv and privateEnv.
    3. c. If varEnv is a global Environment Record, then
      1. i. Perform ? varEnv.CreateGlobalFunctionBinding(fn, fo, true).
    4. d. Else,
      1. i. Let bindingExists be varEnv.HasBinding(fn).
      2. ii. If bindingExists is false, then
        1. 1. Let status be ! varEnv.CreateMutableBinding(fn, true).
        2. 2. Assert: status is not an abrupt completion because of validation preceding step #step-evaldeclarationinstantiation-post-validation.
        3. 3. Perform ! varEnv.InitializeBinding(fn, fo).
      3. iii. Else,
        1. 1. Perform ! varEnv.SetMutableBinding(fn, fo, false).
  18. 1418. For each String vn of declaredVarNames, do
    1. a. If varEnv is a global Environment Record, then
      1. i. Perform ? varEnv.CreateGlobalVarBinding(vn, true).
    2. b. Else,
      1. i. Let bindingExists be varEnv.HasBinding(vn).
      2. ii. If bindingExists is false, then
        1. 1. Let status be ! varEnv.CreateMutableBinding(vn, true).
        2. 2. Assert: status is not an abrupt completion because of validation preceding step #step-evaldeclarationinstantiation-post-validation.
        3. 3. Perform ! varEnv.InitializeBinding(vn, undefined).
  19. 1519. Return NormalCompletion(empty).
Note

An alternative version of this algorithm is described in B.3.5.

20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, args )

The abstract operation CreateDynamicFunction takes arguments constructor (a constructor), newTarget (a constructor), kind (either normal, generator, async, or asyncGenerator), and args (a List of ECMAScript language values). constructor is the constructor function that is performing this action. newTarget is the constructor that new was initially applied to. args is the argument values that were passed to constructor. It performs the following steps when called:

  1. 1. Assert: The execution context stack has at least two elements.
  2. 2. Let callerContext be the second to top element of the execution context stack.
  3. 3. Let callerRealm be callerContext's Realm.
  4. 4. Let calleeRealm be the current Realm Record.
  5. 5. Perform ? HostEnsureCanCompileStrings(callerRealm, calleeRealm).
  6. 6. If newTarget is undefined, set newTarget to constructor.
  7. 7. If kind is normal, then
    1. a. Let goal be the grammar symbol FunctionBody[~Yield, ~Await].
    2. b. Let parameterGoal be the grammar symbol FormalParameters[~Yield, ~Await].
    3. c. Let fallbackProto be "%Function.prototype%".
  8. 8. Else if kind is generator, then
    1. a. Let goal be the grammar symbol GeneratorBody.
    2. b. Let parameterGoal be the grammar symbol FormalParameters[+Yield, ~Await].
    3. c. Let fallbackProto be "%GeneratorFunction.prototype%".
  9. 9. Else if kind is async, then
    1. a. Let goal be the grammar symbol AsyncFunctionBody.
    2. b. Let parameterGoal be the grammar symbol FormalParameters[~Yield, +Await].
    3. c. Let fallbackProto be "%AsyncFunction.prototype%".
  10. 10. Else,
    1. a. Assert: kind is asyncGenerator.
    2. b. Let goal be the grammar symbol AsyncGeneratorBody.
    3. c. Let parameterGoal be the grammar symbol FormalParameters[+Yield, +Await].
    4. d. Let fallbackProto be "%AsyncGeneratorFunction.prototype%".
  11. 11. Let argCount be the number of elements in args.
  12. 12. Let P be the empty String.
  13. 13. If argCount = 0, let bodyArg be the empty String.
  14. 14. Else if argCount = 1, let bodyArg be args[0].
  15. 15. Else,
    1. a. Assert: argCount > 1.
    2. b. Let firstArg be args[0].
    3. c. Set P to ? ToString(firstArg).
    4. d. Let k be 1.
    5. e. Repeat, while k < argCount - 1,
      1. i. Let nextArg be args[k].
      2. ii. Let nextArgString be ? ToString(nextArg).
      3. iii. Set P to the string-concatenation of P, "," (a comma), and nextArgString.
      4. iv. Set k to k + 1.
    6. f. Let bodyArg be args[k].
  16. 16. Let bodyString be the string-concatenation of 0x000A (LINE FEED), ? ToString(bodyArg), and 0x000A (LINE FEED).
  17. 17. Let prefix be the prefix associated with kind in Table 51Table 54.
  18. 18. Let sourceString be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), ") {", bodyString, and "}".
  19. 19. Let sourceText be ! StringToCodePoints(sourceString).
  20. 20. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection:
    1. a. Let parameters be ParseText(! StringToCodePoints(P), parameterGoal).
    2. b. If parameters is a List of errors, throw a SyntaxError exception.
    3. c. Let body be ParseText(! StringToCodePoints(bodyString), goal).
    4. d. If body is a List of errors, throw a SyntaxError exception.
    5. e. Let strict be FunctionBodyContainsUseStrict of body.
    6. f. If strict is true, apply the early error rules for UniqueFormalParameters : FormalParameters to parameters.
    7. g. If strict is true and IsSimpleParameterList of parameters is false, throw a SyntaxError exception.
    8. h. If any element of the BoundNames of parameters also occurs in the LexicallyDeclaredNames of body, throw a SyntaxError exception.
    9. i. If body Contains SuperCall is true, throw a SyntaxError exception.
    10. j. If parameters Contains SuperCall is true, throw a SyntaxError exception.
    11. k. If body Contains SuperProperty is true, throw a SyntaxError exception.
    12. l. If parameters Contains SuperProperty is true, throw a SyntaxError exception.
    13. m. If kind is generator or asyncGenerator, then
      1. i. If parameters Contains YieldExpression is true, throw a SyntaxError exception.
    14. n. If kind is async or asyncGenerator, then
      1. i. If parameters Contains AwaitExpression is true, throw a SyntaxError exception.
    15. o. If strict is true, then
      1. i. If BoundNames of parameters contains any duplicate elements, throw a SyntaxError exception.
    16. p. If AllPrivateIdentifiersValid of body with argument « » is false, throw a SyntaxError exception.
    17. q. If AllPrivateIdentifiersValid of parameters with argument « » is false, throw a SyntaxError exception.
  21. 21. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
  22. 22. Let realmF be the current Realm Record.
  23. 23. Let scope be realmF.[[GlobalEnv]].
  24. 24. Let privateScope be NewDeclarativeEnvironment(null).
  25. 2425. Let F be ! OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, scope, privateScope).
  26. 2526. Perform SetFunctionName(F, "anonymous").
  27. 2627. If kind is generator, then
    1. a. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
    2. b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  28. 2728. Else if kind is asyncGenerator, then
    1. a. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
    2. b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  29. 2829. Else if kind is normal, perform MakeConstructor(F).
  30. 2930. NOTE: Functions whose kind is async are not constructible and do not have a [[Construct]] internal method or a "prototype" property.
  31. 3031. Return F.
Note

CreateDynamicFunction defines a "prototype" property on any function it creates whose kind is not async to provide for the possibility that the function will be used as a constructor.

Table 51Table 54: Dynamic Function SourceText Prefixes
KindPrefix
normal"function"
generator"function*"
async"async function"
asyncGenerator"async function*"

A.1 Lexical Grammar

SourceCharacter :: any Unicode code point InputElementDiv :: WhiteSpace LineTerminator Comment CommonToken DivPunctuator RightBracePunctuator InputElementRegExp :: WhiteSpace LineTerminator Comment CommonToken RightBracePunctuator RegularExpressionLiteral InputElementRegExpOrTemplateTail :: WhiteSpace LineTerminator Comment CommonToken RegularExpressionLiteral TemplateSubstitutionTail InputElementTemplateTail :: WhiteSpace LineTerminator Comment CommonToken DivPunctuator TemplateSubstitutionTail WhiteSpace :: <TAB> <VT> <FF> <SP> <NBSP> <ZWNBSP> <USP> LineTerminator :: <LF> <CR> <LS> <PS> LineTerminatorSequence :: <LF> <CR> [lookahead ≠ <LF>] <LS> <PS> <CR> <LF> Comment :: MultiLineComment SingleLineComment MultiLineComment :: /* MultiLineCommentCharsopt */ MultiLineCommentChars :: MultiLineNotAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt PostAsteriskCommentChars :: MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt MultiLineNotAsteriskChar :: SourceCharacter but not * MultiLineNotForwardSlashOrAsteriskChar :: SourceCharacter but not one of / or * SingleLineComment :: // SingleLineCommentCharsopt SingleLineCommentChars :: SingleLineCommentChar SingleLineCommentCharsopt SingleLineCommentChar :: SourceCharacter but not LineTerminator CommonToken :: IdentifierName PrivateIdentifier Punctuator NumericLiteral StringLiteral Template PrivateIdentifier :: # IdentifierName IdentifierName :: IdentifierStart IdentifierName IdentifierPart IdentifierStart :: UnicodeIDStart $ _ \ UnicodeEscapeSequence IdentifierPart :: UnicodeIDContinue $ \ UnicodeEscapeSequence <ZWNJ> <ZWJ> UnicodeIDStart :: any Unicode code point with the Unicode property “ID_Start” UnicodeIDContinue :: any Unicode code point with the Unicode property “ID_Continue” ReservedWord :: one of await break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield Punctuator :: OptionalChainingPunctuator OtherPunctuator OptionalChainingPunctuator :: ?. [lookahead ∉ DecimalDigit] OtherPunctuator :: one of { ( ) [ ] . ... ; , < > <= >= == != === !== + - * % ** ++ -- << >> >>> & | ^ ! ~ && || ?? ? : = += -= *= %= **= <<= >>= >>>= &= |= ^= &&= ||= ??= => DivPunctuator :: / /= RightBracePunctuator :: } NullLiteral :: null BooleanLiteral :: true false NumericLiteralSeparator :: _ NumericLiteral :: DecimalLiteral DecimalBigIntegerLiteral NonDecimalIntegerLiteral[+Sep] NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix DecimalBigIntegerLiteral :: 0 BigIntLiteralSuffix NonZeroDigit DecimalDigits[+Sep]opt BigIntLiteralSuffix NonZeroDigit NumericLiteralSeparator DecimalDigits[+Sep] BigIntLiteralSuffix NonDecimalIntegerLiteral[Sep] :: BinaryIntegerLiteral[?Sep] OctalIntegerLiteral[?Sep] HexIntegerLiteral[?Sep] BigIntLiteralSuffix :: n DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits[+Sep]opt ExponentPart[+Sep]opt . DecimalDigits[+Sep] ExponentPart[+Sep]opt DecimalIntegerLiteral ExponentPart[+Sep]opt DecimalIntegerLiteral :: 0 NonZeroDigit NonZeroDigit NumericLiteralSeparatoropt DecimalDigits[+Sep] DecimalDigits[Sep] :: DecimalDigit DecimalDigits[?Sep] DecimalDigit [+Sep] DecimalDigits[+Sep] NumericLiteralSeparator DecimalDigit DecimalDigit :: one of 0 1 2 3 4 5 6 7 8 9 NonZeroDigit :: one of 1 2 3 4 5 6 7 8 9 ExponentPart[Sep] :: ExponentIndicator SignedInteger[?Sep] ExponentIndicator :: one of e E SignedInteger[Sep] :: DecimalDigits[?Sep] + DecimalDigits[?Sep] - DecimalDigits[?Sep] BinaryIntegerLiteral[Sep] :: 0b BinaryDigits[?Sep] 0B BinaryDigits[?Sep] BinaryDigits[Sep] :: BinaryDigit BinaryDigits[?Sep] BinaryDigit [+Sep] BinaryDigits[+Sep] NumericLiteralSeparator BinaryDigit BinaryDigit :: one of 0 1 OctalIntegerLiteral[Sep] :: 0o OctalDigits[?Sep] 0O OctalDigits[?Sep] OctalDigits[Sep] :: OctalDigit OctalDigits[?Sep] OctalDigit [+Sep] OctalDigits[+Sep] NumericLiteralSeparator OctalDigit OctalDigit :: one of 0 1 2 3 4 5 6 7 HexIntegerLiteral[Sep] :: 0x HexDigits[?Sep] 0X HexDigits[?Sep] HexDigits[Sep] :: HexDigit HexDigits[?Sep] HexDigit [+Sep] HexDigits[+Sep] NumericLiteralSeparator HexDigit HexDigit :: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F StringLiteral :: " DoubleStringCharactersopt " ' SingleStringCharactersopt ' DoubleStringCharacters :: DoubleStringCharacter DoubleStringCharactersopt SingleStringCharacters :: SingleStringCharacter SingleStringCharactersopt DoubleStringCharacter :: SourceCharacter but not one of " or \ or LineTerminator <LS> <PS> \ EscapeSequence LineContinuation SingleStringCharacter :: SourceCharacter but not one of ' or \ or LineTerminator <LS> <PS> \ EscapeSequence LineContinuation LineContinuation :: \ LineTerminatorSequence EscapeSequence :: CharacterEscapeSequence 0 [lookahead ∉ DecimalDigit] HexEscapeSequence UnicodeEscapeSequence CharacterEscapeSequence :: SingleEscapeCharacter NonEscapeCharacter SingleEscapeCharacter :: one of ' " \ b f n r t v NonEscapeCharacter :: SourceCharacter but not one of EscapeCharacter or LineTerminator EscapeCharacter :: SingleEscapeCharacter DecimalDigit x u HexEscapeSequence :: x HexDigit HexDigit UnicodeEscapeSequence :: u Hex4Digits u{ CodePoint } Hex4Digits :: HexDigit HexDigit HexDigit HexDigit RegularExpressionLiteral :: / RegularExpressionBody / RegularExpressionFlags RegularExpressionBody :: RegularExpressionFirstChar RegularExpressionChars RegularExpressionChars :: [empty] RegularExpressionChars RegularExpressionChar RegularExpressionFirstChar :: RegularExpressionNonTerminator but not one of * or \ or / or [ RegularExpressionBackslashSequence RegularExpressionClass RegularExpressionChar :: RegularExpressionNonTerminator but not one of \ or / or [ RegularExpressionBackslashSequence RegularExpressionClass RegularExpressionBackslashSequence :: \ RegularExpressionNonTerminator RegularExpressionNonTerminator :: SourceCharacter but not LineTerminator RegularExpressionClass :: [ RegularExpressionClassChars ] RegularExpressionClassChars :: [empty] RegularExpressionClassChars RegularExpressionClassChar RegularExpressionClassChar :: RegularExpressionNonTerminator but not one of ] or \ RegularExpressionBackslashSequence RegularExpressionFlags :: [empty] RegularExpressionFlags IdentifierPart Template :: NoSubstitutionTemplate TemplateHead NoSubstitutionTemplate :: ` TemplateCharactersopt ` TemplateHead :: ` TemplateCharactersopt ${ TemplateSubstitutionTail :: TemplateMiddle TemplateTail TemplateMiddle :: } TemplateCharactersopt ${ TemplateTail :: } TemplateCharactersopt ` TemplateCharacters :: TemplateCharacter TemplateCharactersopt TemplateCharacter :: $ [lookahead ≠ {] \ EscapeSequence \ NotEscapeSequence LineContinuation LineTerminatorSequence SourceCharacter but not one of ` or \ or $ or LineTerminator NotEscapeSequence :: 0 DecimalDigit DecimalDigit but not 0 x [lookahead ∉ HexDigit] x HexDigit [lookahead ∉ HexDigit] u [lookahead ∉ HexDigit] [lookahead ≠ {] u HexDigit [lookahead ∉ HexDigit] u HexDigit HexDigit [lookahead ∉ HexDigit] u HexDigit HexDigit HexDigit [lookahead ∉ HexDigit] u { [lookahead ∉ HexDigit] u { NotCodePoint [lookahead ∉ HexDigit] u { CodePoint [lookahead ∉ HexDigit] [lookahead ≠ }] NotCodePoint :: HexDigits[~Sep] but only if MV of HexDigits > 0x10FFFF CodePoint :: HexDigits[~Sep] but only if MV of HexDigits ≤ 0x10FFFF

A.2 Expressions

IdentifierReference[Yield, Await] : Identifier [~Yield]yield [~Await]await BindingIdentifier[Yield, Await] : Identifier yield await LabelIdentifier[Yield, Await] : Identifier [~Yield]yield [~Await]await Identifier : IdentifierName but not ReservedWord PrimaryExpression[Yield, Await] : this IdentifierReference[?Yield, ?Await] Literal ArrayLiteral[?Yield, ?Await] ObjectLiteral[?Yield, ?Await] FunctionExpression ClassExpression[?Yield, ?Await] GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral[?Yield, ?Await, ~Tagged] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] CoverParenthesizedExpressionAndArrowParameterList[Yield, Await] : ( Expression[+In, ?Yield, ?Await] ) ( Expression[+In, ?Yield, ?Await] , ) ( ) ( ... BindingIdentifier[?Yield, ?Await] ) ( ... BindingPattern[?Yield, ?Await] ) ( Expression[+In, ?Yield, ?Await] , ... BindingIdentifier[?Yield, ?Await] ) ( Expression[+In, ?Yield, ?Await] , ... BindingPattern[?Yield, ?Await] )

When processing an instance of the production
PrimaryExpression[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
the interpretation of CoverParenthesizedExpressionAndArrowParameterList is refined using the following grammar:

ParenthesizedExpression[Yield, Await] : ( Expression[+In, ?Yield, ?Await] )

 

Literal : NullLiteral BooleanLiteral NumericLiteral StringLiteral ArrayLiteral[Yield, Await] : [ Elisionopt ] [ ElementList[?Yield, ?Await] ] [ ElementList[?Yield, ?Await] , Elisionopt ] ElementList[Yield, Await] : Elisionopt AssignmentExpression[+In, ?Yield, ?Await] Elisionopt SpreadElement[?Yield, ?Await] ElementList[?Yield, ?Await] , Elisionopt AssignmentExpression[+In, ?Yield, ?Await] ElementList[?Yield, ?Await] , Elisionopt SpreadElement[?Yield, ?Await] Elision : , Elision , SpreadElement[Yield, Await] : ... AssignmentExpression[+In, ?Yield, ?Await] ObjectLiteral[Yield, Await] : { } { PropertyDefinitionList[?Yield, ?Await] } { PropertyDefinitionList[?Yield, ?Await] , } PropertyDefinitionList[Yield, Await] : PropertyDefinition[?Yield, ?Await] PropertyDefinitionList[?Yield, ?Await] , PropertyDefinition[?Yield, ?Await] PropertyDefinition[Yield, Await] : IdentifierReference[?Yield, ?Await] CoverInitializedName[?Yield, ?Await] PropertyName[?Yield, ?Await] : AssignmentExpression[+In, ?Yield, ?Await] MethodDefinition[?Yield, ?Await] ... AssignmentExpression[+In, ?Yield, ?Await] PropertyName[Yield, Await] : LiteralPropertyName ComputedPropertyName[?Yield, ?Await] LiteralPropertyName : IdentifierName StringLiteral NumericLiteral ComputedPropertyName[Yield, Await] : [ AssignmentExpression[+In, ?Yield, ?Await] ] CoverInitializedName[Yield, Await] : IdentifierReference[?Yield, ?Await] Initializer[+In, ?Yield, ?Await] Initializer[In, Yield, Await] : = AssignmentExpression[?In, ?Yield, ?Await] = AssignmentExpression[?In, ?Yield, ?Await] TemplateLiteral[Yield, Await, Tagged] : NoSubstitutionTemplate SubstitutionTemplate[?Yield, ?Await, ?Tagged] SubstitutionTemplate[Yield, Await, Tagged] : TemplateHead Expression[+In, ?Yield, ?Await] TemplateSpans[?Yield, ?Await, ?Tagged] TemplateSpans[Yield, Await, Tagged] : TemplateTail TemplateMiddleList[?Yield, ?Await, ?Tagged] TemplateTail TemplateMiddleList[Yield, Await, Tagged] : TemplateMiddle Expression[+In, ?Yield, ?Await] TemplateMiddleList[?Yield, ?Await, ?Tagged] TemplateMiddle Expression[+In, ?Yield, ?Await] MemberExpression[Yield, Await] : PrimaryExpression[?Yield, ?Await] MemberExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] MemberExpression[?Yield, ?Await] . IdentifierName MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] SuperProperty[?Yield, ?Await] MetaProperty new MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await] MemberExpression[?Yield, ?Await] . PrivateIdentifier SuperProperty[Yield, Await] : super [ Expression[+In, ?Yield, ?Await] ] super . IdentifierName MetaProperty : NewTarget ImportMeta NewTarget : new . target ImportMeta : import . meta NewExpression[Yield, Await] : MemberExpression[?Yield, ?Await] new NewExpression[?Yield, ?Await] CallExpression[Yield, Await] : CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] SuperCall[?Yield, ?Await] ImportCall[?Yield, ?Await] CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await] CallExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] CallExpression[?Yield, ?Await] . IdentifierName CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] CallExpression[?Yield, ?Await] . PrivateIdentifier

When processing an instance of the production
CallExpression[Yield, Await] : CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
the interpretation of CoverCallExpressionAndAsyncArrowHead is refined using the following grammar:

CallMemberExpression[Yield, Await] : MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

 

SuperCall[Yield, Await] : super Arguments[?Yield, ?Await] ImportCall[Yield, Await] : import ( AssignmentExpression[+In, ?Yield, ?Await] ) Arguments[Yield, Await] : ( ) ( ArgumentList[?Yield, ?Await] ) ( ArgumentList[?Yield, ?Await] , ) ArgumentList[Yield, Await] : AssignmentExpression[+In, ?Yield, ?Await] ... AssignmentExpression[+In, ?Yield, ?Await] ArgumentList[?Yield, ?Await] , AssignmentExpression[+In, ?Yield, ?Await] ArgumentList[?Yield, ?Await] , ... AssignmentExpression[+In, ?Yield, ?Await] OptionalExpression[Yield, Await] : MemberExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] CallExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] OptionalExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await] OptionalChain[Yield, Await] : ?. Arguments[?Yield, ?Await] ?. [ Expression[+In, ?Yield, ?Await] ] ?. IdentifierName ?. TemplateLiteral[?Yield, ?Await, +Tagged] ?. PrivateIdentifier OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await] OptionalChain[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ] OptionalChain[?Yield, ?Await] . IdentifierName OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] OptionalChain[?Yield, ?Await] . PrivateIdentifier LeftHandSideExpression[Yield, Await] : NewExpression[?Yield, ?Await] CallExpression[?Yield, ?Await] OptionalExpression[?Yield, ?Await] UpdateExpression[Yield, Await] : LeftHandSideExpression[?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] [no LineTerminator here] ++ LeftHandSideExpression[?Yield, ?Await] [no LineTerminator here] -- ++ UnaryExpression[?Yield, ?Await] -- UnaryExpression[?Yield, ?Await] UnaryExpression[Yield, Await] : UpdateExpression[?Yield, ?Await] delete UnaryExpression[?Yield, ?Await] void UnaryExpression[?Yield, ?Await] typeof UnaryExpression[?Yield, ?Await] + UnaryExpression[?Yield, ?Await] - UnaryExpression[?Yield, ?Await] ~ UnaryExpression[?Yield, ?Await] ! UnaryExpression[?Yield, ?Await] [+Await]AwaitExpression[?Yield] ExponentiationExpression[Yield, Await] : UnaryExpression[?Yield, ?Await] UpdateExpression[?Yield, ?Await] ** ExponentiationExpression[?Yield, ?Await] MultiplicativeExpression[Yield, Await] : ExponentiationExpression[?Yield, ?Await] MultiplicativeExpression[?Yield, ?Await] MultiplicativeOperator ExponentiationExpression[?Yield, ?Await] MultiplicativeOperator : one of * / % AdditiveExpression[Yield, Await] : MultiplicativeExpression[?Yield, ?Await] AdditiveExpression[?Yield, ?Await] + MultiplicativeExpression[?Yield, ?Await] AdditiveExpression[?Yield, ?Await] - MultiplicativeExpression[?Yield, ?Await] ShiftExpression[Yield, Await] : AdditiveExpression[?Yield, ?Await] ShiftExpression[?Yield, ?Await] << AdditiveExpression[?Yield, ?Await] ShiftExpression[?Yield, ?Await] >> AdditiveExpression[?Yield, ?Await] ShiftExpression[?Yield, ?Await] >>> AdditiveExpression[?Yield, ?Await] RelationalExpression[In, Yield, Await] : ShiftExpression[?Yield, ?Await] RelationalExpression[?In, ?Yield, ?Await] < ShiftExpression[?Yield, ?Await] RelationalExpression[?In, ?Yield, ?Await] > ShiftExpression[?Yield, ?Await] RelationalExpression[?In, ?Yield, ?Await] <= ShiftExpression[?Yield, ?Await] RelationalExpression[?In, ?Yield, ?Await] >= ShiftExpression[?Yield, ?Await] RelationalExpression[?In, ?Yield, ?Await] instanceof ShiftExpression[?Yield, ?Await] [+In] RelationalExpression[+In, ?Yield, ?Await] in ShiftExpression[?Yield, ?Await] EqualityExpression[In, Yield, Await] : RelationalExpression[?In, ?Yield, ?Await] EqualityExpression[?In, ?Yield, ?Await] == RelationalExpression[?In, ?Yield, ?Await] EqualityExpression[?In, ?Yield, ?Await] != RelationalExpression[?In, ?Yield, ?Await] EqualityExpression[?In, ?Yield, ?Await] === RelationalExpression[?In, ?Yield, ?Await] EqualityExpression[?In, ?Yield, ?Await] !== RelationalExpression[?In, ?Yield, ?Await] BitwiseANDExpression[In, Yield, Await] : EqualityExpression[?In, ?Yield, ?Await] BitwiseANDExpression[?In, ?Yield, ?Await] & EqualityExpression[?In, ?Yield, ?Await] BitwiseXORExpression[In, Yield, Await] : BitwiseANDExpression[?In, ?Yield, ?Await] BitwiseXORExpression[?In, ?Yield, ?Await] ^ BitwiseANDExpression[?In, ?Yield, ?Await] BitwiseORExpression[In, Yield, Await] : BitwiseXORExpression[?In, ?Yield, ?Await] BitwiseORExpression[?In, ?Yield, ?Await] | BitwiseXORExpression[?In, ?Yield, ?Await] LogicalANDExpression[In, Yield, Await] : BitwiseORExpression[?In, ?Yield, ?Await] LogicalANDExpression[?In, ?Yield, ?Await] && BitwiseORExpression[?In, ?Yield, ?Await] LogicalORExpression[In, Yield, Await] : LogicalANDExpression[?In, ?Yield, ?Await] LogicalORExpression[?In, ?Yield, ?Await] || LogicalANDExpression[?In, ?Yield, ?Await] CoalesceExpression[In, Yield, Await] : CoalesceExpressionHead[?In, ?Yield, ?Await] ?? BitwiseORExpression[?In, ?Yield, ?Await] CoalesceExpressionHead[In, Yield, Await] : CoalesceExpression[?In, ?Yield, ?Await] BitwiseORExpression[?In, ?Yield, ?Await] ShortCircuitExpression[In, Yield, Await] : LogicalORExpression[?In, ?Yield, ?Await] CoalesceExpression[?In, ?Yield, ?Await] ConditionalExpression[In, Yield, Await] : ShortCircuitExpression[?In, ?Yield, ?Await] ShortCircuitExpression[?In, ?Yield, ?Await] ? AssignmentExpression[+In, ?Yield, ?Await] : AssignmentExpression[?In, ?Yield, ?Await] AssignmentExpression[In, Yield, Await] : ConditionalExpression[?In, ?Yield, ?Await] [+Yield]YieldExpression[?In, ?Await] ArrowFunction[?In, ?Yield, ?Await] AsyncArrowFunction[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] = AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] AssignmentOperator AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] &&= AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] ||= AssignmentExpression[?In, ?Yield, ?Await] LeftHandSideExpression[?Yield, ?Await] ??= AssignmentExpression[?In, ?Yield, ?Await] AssignmentOperator : one of *= /= %= += -= <<= >>= >>>= &= ^= |= **=

In certain circumstances when processing an instance of the production
AssignmentExpression[In, Yield, Await] : LeftHandSideExpression[?Yield, ?Await] = AssignmentExpression[?In, ?Yield, ?Await]
the interpretation of LeftHandSideExpression is refined using the following grammar:

AssignmentPattern[Yield, Await] : ObjectAssignmentPattern[?Yield, ?Await] ArrayAssignmentPattern[?Yield, ?Await] ObjectAssignmentPattern[Yield, Await] : { } { AssignmentRestProperty[?Yield, ?Await] } { AssignmentPropertyList[?Yield, ?Await] } { AssignmentPropertyList[?Yield, ?Await] , AssignmentRestProperty[?Yield, ?Await]opt } ArrayAssignmentPattern[Yield, Await] : [ Elisionopt AssignmentRestElement[?Yield, ?Await]opt ] [ AssignmentElementList[?Yield, ?Await] ] [ AssignmentElementList[?Yield, ?Await] , Elisionopt AssignmentRestElement[?Yield, ?Await]opt ] AssignmentRestProperty[Yield, Await] : ... DestructuringAssignmentTarget[?Yield, ?Await] AssignmentPropertyList[Yield, Await] : AssignmentProperty[?Yield, ?Await] AssignmentPropertyList[?Yield, ?Await] , AssignmentProperty[?Yield, ?Await] AssignmentElementList[Yield, Await] : AssignmentElisionElement[?Yield, ?Await] AssignmentElementList[?Yield, ?Await] , AssignmentElisionElement[?Yield, ?Await] AssignmentElisionElement[Yield, Await] : Elisionopt AssignmentElement[?Yield, ?Await] AssignmentProperty[Yield, Await] : IdentifierReference[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt PropertyName[?Yield, ?Await] : AssignmentElement[?Yield, ?Await] AssignmentElement[Yield, Await] : DestructuringAssignmentTarget[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt AssignmentRestElement[Yield, Await] : ... DestructuringAssignmentTarget[?Yield, ?Await] DestructuringAssignmentTarget[Yield, Await] : LeftHandSideExpression[?Yield, ?Await]

 

Expression[In, Yield, Await] : AssignmentExpression[?In, ?Yield, ?Await] Expression[?In, ?Yield, ?Await] , AssignmentExpression[?In, ?Yield, ?Await]

A.4 Functions and Classes

UniqueFormalParameters[Yield, Await] : FormalParameters[?Yield, ?Await] FormalParameters[Yield, Await] : [empty] FunctionRestParameter[?Yield, ?Await] FormalParameterList[?Yield, ?Await] FormalParameterList[?Yield, ?Await] , FormalParameterList[?Yield, ?Await] , FunctionRestParameter[?Yield, ?Await] FormalParameterList[Yield, Await] : FormalParameter[?Yield, ?Await] FormalParameterList[?Yield, ?Await] , FormalParameter[?Yield, ?Await] FunctionRestParameter[Yield, Await] : BindingRestElement[?Yield, ?Await] FormalParameter[Yield, Await] : BindingElement[?Yield, ?Await] FunctionDeclaration[Yield, Await, Default] : function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } [+Default] function ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } FunctionExpression : function BindingIdentifier[~Yield, ~Await]opt ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } FunctionBody[Yield, Await] : FunctionStatementList[?Yield, ?Await] FunctionStatementList[Yield, Await] : StatementList[?Yield, ?Await, +Return]opt ArrowFunction[In, Yield, Await] : ArrowParameters[?Yield, ?Await] [no LineTerminator here] => ConciseBody[?In] ArrowParameters[Yield, Await] : BindingIdentifier[?Yield, ?Await] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] ConciseBody[In] : [lookahead ≠ {] ExpressionBody[?In, ~Await] { FunctionBody[~Yield, ~Await] } ExpressionBody[In, Await] : AssignmentExpression[?In, ~Yield, ?Await]

When processing an instance of the production
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
the interpretation of CoverParenthesizedExpressionAndArrowParameterList is refined using the following grammar:

ArrowFormalParameters[Yield, Await] : ( UniqueFormalParameters[?Yield, ?Await] )

 

AsyncArrowFunction[In, Yield, Await] : async [no LineTerminator here] AsyncArrowBindingIdentifier[?Yield] [no LineTerminator here] => AsyncConciseBody[?In] CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] [no LineTerminator here] => AsyncConciseBody[?In] AsyncConciseBody[In] : [lookahead ≠ {] ExpressionBody[?In, +Await] { AsyncFunctionBody } AsyncArrowBindingIdentifier[Yield] : BindingIdentifier[?Yield, +Await] CoverCallExpressionAndAsyncArrowHead[Yield, Await] : MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

When processing an instance of the production
AsyncArrowFunction[In, Yield, Await] : CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] [no LineTerminator here] => AsyncConciseBody[?In]
the interpretation of CoverCallExpressionAndAsyncArrowHead is refined using the following grammar:

AsyncArrowHead : async [no LineTerminator here] ArrowFormalParameters[~Yield, +Await]

 

MethodDefinition[Yield, Await] : PropertyName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] AsyncGeneratorMethod[?Yield, ?Await] get PropertyName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } get ClassElementName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } set ClassElementName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } PropertySetParameterList : FormalParameter[~Yield, ~Await] GeneratorMethod[Yield, Await] : * PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody } * ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorDeclaration[Yield, Await, Default] : function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } [+Default] function * ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorExpression : function * BindingIdentifier[+Yield, ~Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorBody : FunctionBody[+Yield, ~Await] YieldExpression[In, Await] : yield yield [no LineTerminator here] AssignmentExpression[?In, +Yield, ?Await] yield [no LineTerminator here] * AssignmentExpression[?In, +Yield, ?Await] AsyncGeneratorMethod[Yield, Await] : async [no LineTerminator here] * PropertyName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } async [no LineTerminator here] * ClassElementName[?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]opt ( FormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } AsyncGeneratorBody : FunctionBody[+Yield, +Await] AsyncFunctionDeclaration[Yield, Await, Default] : async [no LineTerminator here] function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } [+Default] async [no LineTerminator here] function ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionExpression : async [no LineTerminator here] function BindingIdentifier[~Yield, +Await]opt ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncMethod[Yield, Await] : async [no LineTerminator here] PropertyName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncMethod[Yield, Await] : async [no LineTerminator here] ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionBody : FunctionBody[~Yield, +Await] AwaitExpression[Yield] : await UnaryExpression[?Yield, +Await] ClassDeclaration[Yield, Await, Default] : class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await] [+Default] class ClassTail[?Yield, ?Await] ClassExpression[Yield, Await] : class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await] ClassTail[Yield, Await] : ClassHeritage[?Yield, ?Await]opt { ClassBody[?Yield, ?Await]opt } ClassHeritage[Yield, Await] : extends LeftHandSideExpression[?Yield, ?Await] ClassBody[Yield, Await] : ClassElementList[?Yield, ?Await]ClassElementList[?Yield, ?Await] ClassElementList[Yield, Await] : ClassElement[?Yield, ?Await] ClassElementList[?Yield, ?Await] ClassElement[?Yield, ?Await] ClassElement[Yield, Await] : MethodDefinition[?Yield, ?Await] static MethodDefinition[?Yield, ?Await] FieldDefinition[?Yield, ?Await] ; static FieldDefinition[?Yield, ?Await] ; ; FieldDefinition[Yield, Await] : ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt ClassElementName[Yield, Await] : PropertyName[?Yield, ?Await] PrivateIdentifier

B.3.3.3 Changes to EvalDeclarationInstantiation

During EvalDeclarationInstantiation the following steps are performed in place of step #step-evaldeclarationinstantiation-web-compat-insertion-point:

  1. 1. If strict is false, then
    1. a. Let declaredFunctionOrVarNames be a new empty List.
    2. b. Append to declaredFunctionOrVarNames the elements of declaredFunctionNames.
    3. c. Append to declaredFunctionOrVarNames the elements of declaredVarNames.
    4. d. For each FunctionDeclaration f that is directly contained in the StatementList of a Block, CaseClause, or DefaultClause Contained within body, do
      1. i. Let F be StringValue of the BindingIdentifier of f.
      2. ii. If replacing the FunctionDeclaration f with a VariableStatement that has F as a BindingIdentifier would not produce any Early Errors for body, then
        1. 1. Let bindingExists be false.
        2. 2. Let thisEnv be lexEnv.
        3. 3. Assert: The following loop will terminate.
        4. 4. Repeat, while thisEnv is not the same as varEnv,
          1. a. If thisEnv is not an object Environment Record, then
            1. i. If thisEnv.HasBinding(F) is true, then
              1. 1. Let bindingExists be true.
          2. b. Set thisEnv to thisEnv.[[OuterEnv]].
        5. 5. If bindingExists is false and varEnv is a global Environment Record, then
          1. a. If varEnv.HasLexicalDeclaration(F) is false, then
            1. i. Let fnDefinable be ? varEnv.CanDeclareGlobalVar(F).
          2. b. Else,
            1. i. Let fnDefinable be false.
        6. 6. Else,
          1. a. Let fnDefinable be true.
        7. 7. If bindingExists is false and fnDefinable is true, then
          1. a. If declaredFunctionOrVarNames does not contain F, then
            1. i. If varEnv is a global Environment Record, then
              1. 1. Perform ? varEnv.CreateGlobalVarBinding(F, true).
            2. ii. Else,
              1. 1. Let bindingExists be varEnv.HasBinding(F).
              2. 2. If bindingExists is false, then
                1. 1. Perform ! varEnv.CreateMutableBinding(F, true).
                2. 2. Perform ! varEnv.InitializeBinding(F, undefined).
            3. iii. Append F to declaredFunctionOrVarNames.
          2. b. When the FunctionDeclaration f is evaluated, perform the following steps in place of the FunctionDeclaration Evaluation algorithm provided in 15.2.6:
            1. i. Let genv be the running execution context's VariableEnvironment.
            2. ii. Let benv be the running execution context's LexicalEnvironment.
            3. iii. Let fobj be ! benv.GetBindingValue(F, false).
            4. iv. Perform ? genv.SetMutableBinding(F, fobj, false).
            5. v. Return NormalCompletion(empty).

B.3.3.6 Changes to BlockDeclarationInstantiation

During BlockDeclarationInstantiation the following steps are performed in place of step 34.a.ii.1:

  1. 1. If env.HasBinding(dn) is false, then
    1. a. Perform ! env.CreateMutableBinding(dn, false).

During BlockDeclarationInstantiation the following steps are performed in place of step 34.b.iii:

  1. 1. If the binding for fn in env is an uninitialized binding, then
    1. a. Perform env.InitializeBinding(fn, fo).
  2. 2. Else,
    1. a. Assert: d is a FunctionDeclaration.
    2. b. Perform env.SetMutableBinding(fn, fo, false).

B.3.5 VariableStatements in Catch Blocks

The content of subclause 14.15.1 is replaced with the following:

Catch : catch ( CatchParameter ) Block Note

The Block of a Catch clause may contain var declarations that bind a name that is also bound by the CatchParameter. At runtime, such bindings are instantiated in the VariableDeclarationEnvironment. They do not shadow the same-named bindings introduced by the CatchParameter and hence the Initializer for such var declarations will assign to the corresponding catch parameter rather than the var binding.

This modified behaviour also applies to var and function declarations introduced by direct eval calls contained within the Block of a Catch clause. This change is accomplished by modifying the algorithm of 19.2.1.3 as follows:

Step 3.d.i.2.a.i is replaced by:

  1. 1. If thisEnv is not the Environment Record for a Catch clause, throw a SyntaxError exception.

Step 711.d.ii.4.a.i.i is replaced by:

  1. 1. If thisEnv is not the Environment Record for a Catch clause, let bindingExists be true.

Usage

  1. Expand header by clicking "▼", if collapsed
  2. Select PR, single Revision, or search them by Search field, or select From/To range
  3. Select Section to compare

Found Problems?

File an Issue!