14 ECMAScript Language: Functions and Classes

NOTE Various ECMAScript language elements cause the creation of ECMAScript function objects (9.2). Evaluation of such functions starts with the execution of their [[Call]] internal method (9.2.1).

14.1 Function Definitions

Syntax

FunctionDeclaration[Yield, Default] :
function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody }
[+Default] function ( FormalParameters ) { FunctionBody }
FunctionExpression :
function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
StrictFormalParameters[Yield] :
FormalParameters[?Yield]
FormalParameters[Yield] :
[empty]
FormalParameterList[?Yield]
FormalParameterList[Yield] :
FunctionRestParameter[?Yield]
FormalsList[?Yield]
FormalsList[?Yield] , FunctionRestParameter[?Yield]
FormalsList[Yield] :
FormalParameter[?Yield]
FormalsList[?Yield] , FormalParameter[?Yield]
FunctionRestParameter[Yield] :
BindingRestElement[?Yield]
FormalParameter[Yield] :
BindingElement[?Yield]
FunctionBody[Yield] :
FunctionStatementList[?Yield]
FunctionStatementList[Yield] :
StatementList[?Yield, Return]opt

14.1.1 Directive Prologues and the Use Strict Directive

A Directive Prologue is the longest sequence of ExpressionStatement productions occurring as the initial StatementListItem or ModuleItem productions of a FunctionBody, a ScriptBody, or a ModuleBody and where each ExpressionStatement in the sequence consists entirely of a StringLiteral token followed by a semicolon. The semicolon may appear explicitly or may be inserted by automatic semicolon insertion. A Directive Prologue may be an empty sequence.

A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either the exact code unit sequences "use strict" or 'use strict'. A Use Strict Directive may not contain an EscapeSequence or LineContinuation.

A Directive Prologue may contain more than one Use Strict Directive. However, an implementation may issue a warning if this occurs.

NOTE The ExpressionStatement productions of a Directive Prologue are evaluated normally during evaluation of the containing production. Implementations may define implementation specific meanings for ExpressionStatement productions which are not a Use Strict Directive and which occur in a Directive Prologue. If an appropriate notification mechanism exists, an implementation should issue a warning if it encounters in a Directive Prologue an ExpressionStatement that is not a Use Strict Directive and which does not have a meaning defined by the implementation.

14.1.2 Static Semantics: Early Errors

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }

  • If the source code matching this production is strict code, the Early Error rules for StrictFormalParameters : FormalParameters are applied.

  • If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName eval or the IdentifierName arguments.

  • It is a Syntax Error if any element of the BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of FunctionBody.

  • It is a Syntax Error if FormalParameters Contains SuperProperty is true.

  • It is a Syntax Error if FunctionBody Contains SuperProperty is true.

  • It is a Syntax Error if FormalParameters Contains SuperCall is true.

  • It is a Syntax Error if FunctionBody Contains SuperCall is true.

NOTE 1 The LexicallyDeclaredNames of a FunctionBody does not include identifiers bound using var or function declarations.

StrictFormalParameters : FormalParameters
  • It is a Syntax Error if BoundNames of FormalParameters contains any duplicate elements.

FormalParameters : FormalParameterList
  • It is a Syntax Error if IsSimpleParameterList of FormalParameterList is false and BoundNames of FormalParameterList contains any duplicate elements.

NOTE 2 Multiple occurrences of the same BindingIdentifier in a FormalParameterList is only allowed for functions and generator functions which have simple parameter lists and which are not defined in strict mode code.

FunctionBody : FunctionStatementList
  • It is a Syntax Error if the LexicallyDeclaredNames of FunctionStatementList contains any duplicate entries.

  • It is a Syntax Error if any element of the LexicallyDeclaredNames of FunctionStatementList also occurs in the VarDeclaredNames of FunctionStatementList.

  • It is a Syntax Error if ContainsDuplicateLabels of FunctionStatementList with argument « » is true.

  • It is a Syntax Error if ContainsUndefinedBreakTarget of FunctionStatementList with argument « » is true.

  • It is a Syntax Error if ContainsUndefinedContinueTarget of FunctionStatementList with arguments « » and « » is true.

14.1.3 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Return the BoundNames of BindingIdentifier.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. Return «"*default*"».

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

FormalParameters : [empty]
  1. Return an empty List.
FormalParameterList : FormalsList , FunctionRestParameter
  1. Let names be BoundNames of FormalsList.
  2. Append to names the BoundNames of FunctionRestParameter.
  3. Return names.
FormalsList : FormalsList , FormalParameter
  1. Let names be BoundNames of FormalsList.
  2. Append to names the elements of BoundNames of FormalParameter.
  3. Return names.

14.1.4 Static Semantics: Contains

With parameter symbol.

See also: 5.3, 12.2.6.3, 12.3.1.1, 14.2.3, 14.4.4, 14.5.4

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }

FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }

  1. Return false.

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

14.1.5 Static Semantics: ContainsExpression

See also: 13.3.3.2, 14.2.4.

FormalParameters : [empty]
  1. Return false.
FormalParameterList : FunctionRestParameter
  1. Return false.
FormalParameterList : FormalsList , FunctionRestParameter
  1. Return ContainsExpression of FormalsList.
FormalsList : FormalsList , FormalParameter
  1. If ContainsExpression of FormalsList is true, return true.
  2. Return ContainsExpression of FormalParameter.

14.1.6 Static Semantics: ExpectedArgumentCount

See also: 14.2.5, 14.3.3.

FormalParameters : [empty]
  1. Return 0.
FormalParameterList : FunctionRestParameter
  1. Return 0.
FormalParameterList : FormalsList , FunctionRestParameter
  1. Return the ExpectedArgumentCount of FormalsList.

NOTE The ExpectedArgumentCount of a FormalParameterList is the number of FormalParameters to the left of either the rest parameter or the first FormalParameter with an Initializer. A FormalParameter without an initializer is allowed after the first parameter with an initializer but such parameters are considered to be optional with undefined as their default value.

FormalsList : FormalParameter
  1. If HasInitializer of FormalParameter is true return 0
  2. Return 1.
FormalsList : FormalsList , FormalParameter
  1. Let count be the ExpectedArgumentCount of FormalsList.
  2. If HasInitializer of FormalsList is true or HasInitializer of FormalParameter is true, return count.
  3. Return count+1.

14.1.7 Static Semantics: HasInitializer

See also: 13.3.3.3, 14.2.6.

FormalParameters : [empty]
  1. Return false.
FormalParameterList : FunctionRestParameter
  1. Return false.
FormalParameterList : FormalsList , FunctionRestParameter
  1. If HasInitializer of FormalsList is true, return true.
  2. Return false.
FormalsList : FormalsList , FormalParameter
  1. If HasInitializer of FormalsList is true, return true.
  2. Return HasInitializer of FormalParameter.

14.1.8 Static Semantics: HasName

See also: 12.2.1.2, 14.2.7, 14.4.7, 14.5.6.

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. Return false.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Return true.

14.1.9 Static Semantics: IsAnonymousFunctionDefinition ( production )

The abstract operation IsAnonymousFunctionDefinition determines if its argument is a function definition that does not bind a name. The argument production is the result of parsing an AssignmentExpression or Initializer. The following steps are taken:

  1. If IsFunctionDefinition of production is false, return false.
  2. Let hasName be the result of HasName of production.
  3. If hasName is true, return false.
  4. Return true.

14.1.10 Static Semantics: IsConstantDeclaration

See also: 13.3.1.3, 14.4.8, 14.5.7, 15.2.3.7.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }

  1. Return false.

14.1.11 Static Semantics: IsFunctionDefinition

See also: 12.2.1.3, 12.2.10.2, 12.3.1.2, 12.4.2, 12.5.2, 12.6.1, 12.7.1, 12.8.1, 12.9.1, 12.10.1, 12.11.1, 12.12.1, 12.13.1, 12.14.2, 12.15.1, 14.4.9, 14.5.8.

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. Return true.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Return true.

14.1.12 Static Semantics: IsSimpleParameterList

See also: 13.3.3.4, 14.2.8

FormalParameters : [empty]
  1. Return true.
FormalParameterList : FunctionRestParameter
  1. Return false.
FormalParameterList : FormalsList , FunctionRestParameter
  1. Return false.
FormalsList : FormalsList , FormalParameter
  1. If IsSimpleParameterList of FormalsList is false, return false.
  2. Return IsSimpleParameterList of FormalParameter.
FormalParameter : BindingElement
  1. Return IsSimpleParameterList of BindingElement.

14.1.13 Static Semantics: LexicallyDeclaredNames

See also: 13.2.5, 13.12.5, 13.13.6, 14.2.10, 15.1.3, 15.2.1.11.

FunctionStatementList : [empty]
  1. Return an empty List.
FunctionStatementList : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.

14.1.14 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.12.6, 13.13.7, 14.2.11, 15.1.4, 15.2.1.12, 15.2.3.8.

FunctionStatementList : [empty]
  1. Return an empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelLexicallyScopedDeclarations of StatementList.

14.1.15 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.2.12, 15.1.5, 15.2.1.13.

FunctionStatementList : [empty]
  1. Return an empty List.
FunctionStatementList : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.

14.1.16 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.2.13, 15.1.6, 15.2.1.14.

FunctionStatementList : [empty]
  1. Return an empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelVarScopedDeclarations of StatementList.

14.1.17 Runtime Semantics: EvaluateBody

With parameter functionObject.

See also: 14.2.15, 14.4.11.

FunctionBody : FunctionStatementList
  1. Return the result of evaluating FunctionStatementList.

14.1.18 Runtime Semantics: IteratorBindingInitialization

With parameters iteratorRecord and environment.

NOTE When undefined is passed for environment it indicates that a PutValue operation should be used to assign the initialization value. This is the case for formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to deal with the possibility of multiple parameters with the same name.

See also: 13.3.3.6, 14.2.14.

FormalParameters : [empty]
  1. Return NormalCompletion(empty).
FormalParameterList : FormalsList , FunctionRestParameter
  1. Let restIndex be the result of performing IteratorBindingInitialization for FormalsList using iteratorRecord, and environment as the arguments.
  2. ReturnIfAbrupt(restIndex).
  3. Return the result of performing IteratorBindingInitialization for FunctionRestParameter using iteratorRecord and environment as the arguments.
FormalsList : FormalsList , FormalParameter
  1. Let status be the result of performing IteratorBindingInitialization for FormalsList using iteratorRecord and environment as the arguments.
  2. ReturnIfAbrupt(status).
  3. Return the result of performing IteratorBindingInitialization for FormalParameter using iteratorRecord and environment as the arguments.
FormalParameter : BindingElement
  1. If HasInitializer of BindingElement is false, return the result of performing IteratorBindingInitialization for BindingElement using iteratorRecord and environment as the arguments.
  2. Let currentContext be the running execution context.
  3. Let originalEnv be the VariableEnvironment of currentContext.
  4. Assert: The VariableEnvironment and LexicalEnvironment of currentContext are the same.
  5. Assert: environment and originalEnv are the same.
  6. Let paramVarEnv be NewDeclarativeEnvironment(originalEnv).
  7. Set the VariableEnvironment of currentContext to paramVarEnv.
  8. Set the LexicalEnvironment of currentContext to paramVarEnv.
  9. Let result be the result of performing IteratorBindingInitialization for BindingElement using iteratorRecord and environment as the arguments.
  10. Set the VariableEnvironment of currentContext to originalEnv.
  11. Set the LexicalEnvironment of currentContext to originalEnv.
  12. Return result.

The new Environment Record created in step 6 is only used if the BindElements Initializer contains a direct eval.

14.1.19 Runtime Semantics: InstantiateFunctionObject

With parameter scope.

See also: 14.4.12.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. If the function code for FunctionDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let name be StringValue of BindingIdentifier.
  3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, strict).
  4. Perform MakeConstructor(F).
  5. Perform SetFunctionName(F, name).
  6. Return F.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. If the function code for FunctionDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, strict).
  3. Perform MakeConstructor(F).
  4. Perform SetFunctionName(F, "default").
  5. Return F.

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

14.1.20 Runtime Semantics: Evaluation

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Return NormalCompletion(empty).

NOTE 1 An alternative semantics is provided in B.3.3.

FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. Return NormalCompletion(empty).
FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. If the function code for FunctionExpression is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let scope be the LexicalEnvironment of the running execution context.
  3. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, strict).
  4. Perform MakeConstructor(closure).
  5. Return closure.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. If the function code for FunctionExpression is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let runningContext be the running execution context’s Lexical Environment.
  3. Let funcEnv be NewDeclarativeEnvironment(runningContext ).
  4. Let envRec be funcEnv’s EnvironmentRecord.
  5. Let name be StringValue of BindingIdentifier.
  6. Perform envRec.CreateImmutableBinding(name).
  7. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody, funcEnv, strict).
  8. Perform MakeConstructor(closure).
  9. Perform SetFunctionName(closure, name).
  10. Perform envRec.InitializeBinding(name, closure).
  11. Return NormalCompletion(closure).

NOTE 2 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.

NOTE 3 A prototype property is automatically created for every function defined using a FunctionDeclaration or FunctionExpression, to allow for the possibility that the function will be used as a constructor.

FunctionStatementList : [empty]
  1. Return NormalCompletion(undefined).

14.2 Arrow Function Definitions

Syntax

ArrowFunction[In, Yield] :
ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
ArrowParameters[Yield] :
BindingIdentifier[?Yield]
CoverParenthesizedExpressionAndArrowParameterList[?Yield]
ConciseBody[In] :
[lookahead ≠ { ] AssignmentExpression[?In]
{ FunctionBody }

Supplemental Syntax

When the production

      ArrowParameters[Yield] : CoverParenthesizedExpressionAndArrowParameterList[?Yield]

is recognized the following grammar is used to refine the interpretation of CoverParenthesizedExpressionAndArrowParameterList :

ArrowFormalParameters[Yield] :
( StrictFormalParameters[?Yield] )

14.2.1 Static Semantics: Early Errors

ArrowFunction : ArrowParameters => ConciseBody
  • It is a Syntax Error if ArrowParameters Contains YieldExpression is true.

  • It is a Syntax Error if ConciseBody Contains YieldExpression is true.

  • It is a Syntax Error if any element of the BoundNames of ArrowParameters also occurs in the LexicallyDeclaredNames of ConciseBody.

ArrowParameters[Yield] : CoverParenthesizedExpressionAndArrowParameterList[?Yield]

  • If the [Yield] grammar parameter is present on ArrowParameters, it is a Syntax Error if the lexical token sequence matched by CoverParenthesizedExpressionAndArrowParameterList[?Yield] cannot be parsed with no tokens left over using ArrowFormalParameters[Yield] as the goal symbol.

  • If the [Yield] grammar parameter is not present on ArrowParameters, it is a Syntax Error if the lexical token sequence matched by CoverParenthesizedExpressionAndArrowParameterList[?Yield] cannot be parsed with no tokens left over using ArrowFormalParameters as the goal symbol.

  • All early errors rules for ArrowFormalParameters and its derived productions also apply to CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList[?Yield].

14.2.2 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the BoundNames of formals.

14.2.3 Static Semantics: Contains

With parameter symbol.

See also: 5.3, 12.2.6.3, 12.3.1.1, 14.1.4, 14.4.4, 14.5.4

ArrowFunction : ArrowParameters => ConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super or this, return false.
  2. If ArrowParameters Contains symbol is true, return true;
  3. Return ConciseBody Contains symbol .

NOTE Normally, Contains does not look inside most function forms However, Contains is used to detect new.target, this, and super usage within an ArrowFunction.

ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return formals Contains symbol.

14.2.4 Static Semantics: ContainsExpression

See also: 13.3.3.2, 14.1.5.

ArrowParameters : BindingIdentifier
  1. Return false.

ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the ContainsExpression of formals.

14.2.5 Static Semantics: ExpectedArgumentCount

See also: 14.1.6,14.3.3.

ArrowParameters : BindingIdentifier
  1. Return 1.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the ExpectedArgumentCount of formals.

14.2.6 Static Semantics: HasInitializer

See also: 13.3.3.3, 14.1.7.

ArrowParameters : BindingIdentifier
  1. Return false.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the HasInitializer of formals.

14.2.7 Static Semantics: HasName

See also: 12.2.1.2, 14.1.8, 14.4.7, 14.5.6.

ArrowFunction : ArrowParameters => ConciseBody
  1. Return false.

14.2.8 Static Semantics: IsSimpleParameterList

See also: 13.3.3.4, 14.1.12.

ArrowParameters : BindingIdentifier
  1. Return true.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the IsSimpleParameterList of formals.

14.2.9 Static Semantics: CoveredFormalsList

ArrowParameters : BindingIdentifier
  1. Return BindingIdentifier.
CoverParenthesizedExpressionAndArrowParameterList[Yield] :
( Expression )
( )
( ... BindingIdentifier )
( Expression , ... BindingIdentifier )
  1. If the [Yield] grammar parameter is present for CoverParenthesizedExpressionAndArrowParameterList[Yield] return the result of parsing the lexical token stream matched by CoverParenthesizedExpressionAndArrowParameterList[Yield] using ArrowFormalParameters[Yield] as the goal symbol.
  2. If the [Yield] grammar parameter is not present for CoverParenthesizedExpressionAndArrowParameterList[Yield] return the result of parsing the lexical token stream matched by CoverParenthesizedExpressionAndArrowParameterList using ArrowFormalParameters as the goal symbol.

14.2.10 Static Semantics: LexicallyDeclaredNames

See also: 13.2.5, 13.12.5, 13.13.6, 14.1.13, 15.1.3, 15.2.1.11.

ConciseBody : AssignmentExpression
  1. Return an empty List.

14.2.11 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.12.6, 13.13.7, 14.1.14, 15.1.4, 15.2.1.12, 15.2.3.8.

ConciseBody : AssignmentExpression
  1. Return an empty List.

14.2.12 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 15.1.5, 15.2.1.13.

ConciseBody : AssignmentExpression
  1. Return an empty List.

14.2.13 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 15.1.6, 15.2.1.14.

ConciseBody : AssignmentExpression
  1. Return an empty List.

14.2.14 Runtime Semantics: IteratorBindingInitialization

With parameters iteratorRecord and environment.

See also: 13.3.3.6, 14.1.18.

NOTE When undefined is passed for environment it indicates that a PutValue operation should be used to assign the initialization value. This is the case for formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to deal with the possibility of multiple parameters with the same name.

ArrowParameters : BindingIdentifier
  1. Assert: iteratorRecord.[[done]] is false.
  2. Let next be IteratorStep(iteratorRecord.[[iterator]]).
  3. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
  4. ReturnIfAbrupt(next).
  5. If next is false, set iteratorRecord.[[done]] to true
  6. Else
    1. Let v be IteratorValue(next).
    2. If v is an abrupt completion, set iteratorRecord.[[done]] to true.
    3. ReturnIfAbrupt(v).
  7. If iteratorRecord.[[done]] is true, let v be undefined.
  8. Return the result of performing BindingInitialization for BindingIdentifier using v and environment as the arguments.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the result of performing IteratorBindingInitialization of formals with arguments iteratorRecord and environment.

14.2.15 Runtime Semantics: EvaluateBody

With parameter functionObject.

See also: 14.1.17, 14.4.11.

ConciseBody : AssignmentExpression
  1. Let exprRef be the result of evaluating AssignmentExpression.
  2. Let exprValue be GetValue(exprRef).
  3. ReturnIfAbrupt(exprValue).
  4. Return Completion{[[type]]: return, [[value]]: exprValue, [[target]]: empty}.

14.2.16 Runtime Semantics: Evaluation

ArrowFunction : ArrowParameters => ConciseBody
  1. If the function code for this ArrowFunction is strict mode code (10.2.1), let strict be true. Otherwise let strict be false.
  2. Let scope be the LexicalEnvironment of the running execution context.
  3. Let parameters be CoveredFormalsList of ArrowParameters.
  4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
  5. 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 4 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.

14.3 Method Definitions

Syntax

MethodDefinition[Yield] :
PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
GeneratorMethod[?Yield]
get PropertyName[?Yield] ( ) { FunctionBody }
set PropertyName[?Yield] ( PropertySetParameterList ) { FunctionBody }
PropertySetParameterList :
FormalParameter

14.3.1 Static Semantics: Early Errors

MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
  • It is a Syntax Error if any element of the BoundNames of StrictFormalParameters also occurs in the LexicallyDeclaredNames of FunctionBody.

MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
  • It is a Syntax Error if BoundNames of PropertySetParameterList contains any duplicate elements.

  • It is a Syntax Error if any element of the BoundNames of PropertySetParameterList also occurs in the LexicallyDeclaredNames of FunctionBody.

14.3.2 Static Semantics: ComputedPropertyContains

With parameter symbol.

See also: 12.2.6.2, 14.4.3, 14.5.5.

MethodDefinition :
PropertyName ( StrictFormalParameters ) { FunctionBody }
get PropertyName ( ) { FunctionBody }
set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.

14.3.3 Static Semantics: ExpectedArgumentCount

See also: 14.1.6, 14.2.5.

PropertySetParameterList : FormalParameter
  1. If HasInitializer of FormalParameter is true return 0
  2. Return 1.

14.3.4 Static Semantics: HasComputedPropertyKey

See also: 12.2.6.4, 14.4.5

MethodDefinition :
PropertyName ( StrictFormalParameters ) { FunctionBody }
get PropertyName ( ) { FunctionBody }
set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return HasComputedPropertyKey of PropertyName.

14.3.5 Static Semantics: HasDirectSuper

See also: 14.4.6.

MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
  1. If StrictFormalParameters Contains SuperCall is true, return true.
  2. Return FunctionBody Contains SuperCall.
MethodDefinition : get PropertyName ( ) { FunctionBody }
  1. Return FunctionBody Contains SuperCall.
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. If PropertySetParameterList Contains SuperCall is true, return true.
  2. Return FunctionBody Contains SuperCall.

14.3.6 Static Semantics: PropName

See also: 12.2.6.6, 14.4.10, 14.5.12

MethodDefinition :
PropertyName ( StrictFormalParameters ) { FunctionBody }
get PropertyName ( ) { FunctionBody }
set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return PropName of PropertyName.

14.3.7 Static Semantics: SpecialMethod

MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
  1. Return false.
MethodDefinition :
GeneratorMethod
get PropertyName ( ) { FunctionBody }
set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return true.

14.3.8 Runtime Semantics: DefineMethod

With parameters object and optional parameter functionPrototype.

MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context’s LexicalEnvironment.
  5. If functionPrototype was passed as a parameter, let kind be Normal; otherwise let kind be Method.
  6. Let closure be FunctionCreate(kind, StrictFormalParameters, FunctionBody, scope, strict). If functionPrototype was passed as a parameter then pass its value as the functionPrototype optional argument of FunctionCreate.
  7. Perform MakeMethod(closure, object).
  8. Return the Record{[[key]]: propKey, [[closure]]: closure}.

14.3.9 Runtime Semantics: PropertyDefinitionEvaluation

With parameters object and enumerable.

See also: 12.2.6.9, 14.4.13, B.3.1

MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
  1. Let methodDef be DefineMethod of MethodDefinition with argument object.
  2. ReturnIfAbrupt(methodDef).
  3. Perform SetFunctionName(methodDef.[[closure]], methodDef.[[key]]).
  4. Let desc be the Property Descriptor{[[Value]]: methodDef.[[closure]], [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
  5. Return DefinePropertyOrThrow(object, methodDef.[[key]], desc).
MethodDefinition : GeneratorMethod

See 14.4.

MethodDefinition : get PropertyName ( ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context’s LexicalEnvironment.
  5. Let formalParameterList be the production FormalParameters : [empty]
  6. Let closure be FunctionCreate(Method, formalParameterList, FunctionBody, scope, strict).
  7. Perform MakeMethod(closure, object).
  8. Perform SetFunctionName(closure, propKey, "get").
  9. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true}
  10. Return DefinePropertyOrThrow(object, propKey, desc).
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context’s LexicalEnvironment.
  5. Let closure be FunctionCreate(Method, PropertySetParameterList, FunctionBody, scope, strict).
  6. Perform MakeMethod(closure, object).
  7. Perform SetFunctionName(closure, propKey, "set").
  8. Let desc be the PropertyDescriptor{[[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true}
  9. Return DefinePropertyOrThrow(object, propKey, desc).

14.4 Generator Function Definitions

Syntax

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

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 25.3.3.

14.4.1 Static Semantics: Early Errors

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  • It is a Syntax Error if HasDirectSuper of GeneratorMethod is true.

  • It is a Syntax Error if StrictFormalParameters Contains YieldExpression is true.

  • It is a Syntax Error if any element of the BoundNames of StrictFormalParameters also occurs in the LexicallyDeclaredNames of GeneratorBody.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  • It is a Syntax Error if HasDirectSuper of GeneratorDeclaration is true.
GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  • It is a Syntax Error if HasDirectSuper of GeneratorExpression is true.

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

  • If the source code matching this production is strict code, the Early Error rules for StrictFormalParameters : FormalParameters are applied.

  • If the source code matching this production is strict code, it is a Syntax Error if BindingIdentifier is the IdentifierName eval or the IdentifierName arguments.

  • It is a Syntax Error if any element of the BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of GeneratorBody.

  • It is a Syntax Error if FormalParameters Contains YieldExpression is true.

  • It is a Syntax Error if FormalParameters Contains SuperProperty is true.

  • It is a Syntax Error if GeneratorBody Contains SuperProperty is true.

14.4.2 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.5.2, 15.2.2.2, 15.2.3.2.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Return the BoundNames of BindingIdentifier.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. Return «"*default*"».

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

14.4.3 Static Semantics: ComputedPropertyContains

With parameter symbol.

See also: 12.2.6.2, 14.3.2, 14.5.5.

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.

14.4.4 Static Semantics: Contains

With parameter symbol.

See also: 5.3, 12.2.6.3, 12.3.1.1, 14.1.4, 14.2.3, 14.5.4

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }

  1. Return false.
GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. Return false.

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

14.4.5 Static Semantics: HasComputedPropertyKey

See also: 12.2.6.4, 14.3.4.

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  1. Return IsComputedPropertyKey of PropertyName.

14.4.6 Static Semantics: HasDirectSuper

See also: 14.3.5.

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  1. If StrictFormalParameters Contains SuperCall is true, return true.
  2. Return GeneratorBody Contains SuperCall.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }

  1. If FormalParameters Contains SuperCall is true, return true.
  2. Return GeneratorBody Contains SuperCall.

14.4.7 Static Semantics: HasName

See also: 12.2.1.2, 14.1.8, 14.2.7, 14.5.6.

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. Return false.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Return true.

14.4.8 Static Semantics: IsConstantDeclaration

See also: 13.3.1.3, 14.1.10, 14.5.7, 15.2.3.7.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }

  1. Return false.

14.4.9 Static Semantics: IsFunctionDefinition

See also: 12.2.1.3, 12.2.10.2, 12.3.1.2, 12.4.2, 12.5.2, 12.6.1, 12.7.1, 12.8.1, 12.9.1, 12.10.1, 12.11.1, 12.12.1, 12.13.1, 12.14.2, 12.15.1, 14.1.11, 14.5.8.

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. Return true.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Return true.

14.4.10 Static Semantics: PropName

See also: 12.2.6.6, 14.3.6, 14.5.12

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  1. Return PropName of PropertyName.

14.4.11 Runtime Semantics: EvaluateBody

With parameter functionObject.

See also: 14.1.17, 14.2.15.

GeneratorBody : FunctionBody
  1. Let G be OrdinaryCreateFromConstructor(functionObject, "%GeneratorPrototype%", «‍[[GeneratorState]], [[GeneratorContext]]» ).
  2. ReturnIfAbrupt(G).
  3. Perform GeneratorStart(G, FunctionBody).
  4. Return Completion{[[type]]: return, [[value]]: G, [[target]]: empty}.

NOTE If the generator was invoked using [[Call]], the this binding will have already been initialized in the normal manner. If the generator was invoked using [[Construct]], the this bind is not initialized and any references to this within the FunctionBody will produce a ReferenceError exception.

14.4.12 Runtime Semantics: InstantiateFunctionObject

With parameter scope.

See also: 14.1.19.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. If the function code for GeneratorDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let name be StringValue of BindingIdentifier.
  3. Let F be GeneratorFunctionCreate(Normal, FormalParameters, GeneratorBody, scope, strict).
  4. Let prototype be ObjectCreate(%GeneratorPrototype%).
  5. Perform MakeConstructor(F, true, prototype).
  6. Perform SetFunctionName(F, name).
  7. Return F.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. If the function code for GeneratorDeclaration is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let F be GeneratorFunctionCreate(Normal, FormalParameters, GeneratorBody, scope, strict).
  3. Let prototype be ObjectCreate(%GeneratorPrototype%).
  4. Perform MakeConstructor(F, true, prototype).
  5. Perform SetFunctionName(F, "default").
  6. Return F.

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

14.4.13 Runtime Semantics: PropertyDefinitionEvaluation

With parameter object and enumerable.

See also: 12.2.6.9, 14.3.9, B.3.1

GeneratorMethod : * PropertyName ( StrictFormalParameters ) { GeneratorBody }
  1. Let propKey be the result of evaluating PropertyName.
  2. ReturnIfAbrupt(propKey).
  3. If the function code for this GeneratorMethod is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context’s LexicalEnvironment.
  5. Let closure be GeneratorFunctionCreate(Method, StrictFormalParameters, GeneratorBody, scope, strict).
  6. Perform MakeMethod(closure, object).
  7. Let prototype be ObjectCreate(%GeneratorPrototype%).
  8. Perform MakeConstructor(closure, true, prototype).
  9. Perform SetFunctionName(closure, propKey).
  10. Let desc be the Property Descriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
  11. Return DefinePropertyOrThrow(object, propKey, desc).

14.4.14 Runtime Semantics: Evaluation

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. If the function code for this GeneratorExpression is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let scope be the LexicalEnvironment of the running execution context.
  3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, GeneratorBody, scope, strict).
  4. Let prototype be ObjectCreate(%GeneratorPrototype%).
  5. Perform MakeConstructor(closure, true, prototype).
  6. Return closure.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. If the function code for this GeneratorExpression is strict mode code, let strict be true. Otherwise let strict be false.
  2. Let runningContext be the running execution context’s Lexical Environment.
  3. Let funcEnv be NewDeclarativeEnvironment(runningContext).
  4. Let envRec be funcEnv’s EnvironmentRecord.
  5. Let name be StringValue of BindingIdentifier.
  6. Perform envRec.CreateImmutableBinding(name).
  7. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, GeneratorBody, funcEnv, strict).
  8. Let prototype be ObjectCreate(%GeneratorPrototype%).
  9. Perform MakeConstructor (closure, true, prototype).
  10. Perform SetFunctionName(closure, name).
  11. Perform envRec.InitializeBinding(name, closure).
  12. 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.

YieldExpression : yield
  1. Return GeneratorYield(CreateIterResultObject(undefined, false)).
YieldExpression : yield AssignmentExpression
  1. Let exprRef be the result of evaluating AssignmentExpression.
  2. Let value be GetValue(exprRef).
  3. ReturnIfAbrupt(value).
  4. Return GeneratorYield(CreateIterResultObject(value, false)).
YieldExpression : yield * AssignmentExpression
  1. Let exprRef be the result of evaluating AssignmentExpression.
  2. Let value be GetValue(exprRef).
  3. Let iterator be GetIterator(value).
  4. ReturnIfAbrupt(iterator).
  5. Let received be NormalCompletion(undefined).
  6. Repeat
    1. If received.[[type]] is normal, then
      1. Let innerResult be IteratorNext(iterator, received.[[value]]).
      2. ReturnIfAbrupt(innerResult).
      3. Let done be IteratorComplete(innerResult).
      4. ReturnIfAbrupt(done).
      5. If done is true, then
        1. Return IteratorValue (innerResult).
      6. Let received be GeneratorYield(innerResult).
    2. Else if received.[[type]] is throw, then
      1. Let throw be GetMethod(iterator, "throw").
      2. ReturnIfAbrupt(throw).
      3. If throw is not undefined, then
        1. Let innerResult be Call(throw, iterator, «‍received.[[value]]»).
        2. ReturnIfAbrupt(innerResult).
        3. NOTE: Exceptions from the inner iterator throw method are propagated. Normal completions from an inner throw method are processed similarly to an inner next.
        4. If Type(innerResult) is not Object, throw a TypeError exception.
        5. Let done be IteratorComplete(innerResult).
        6. ReturnIfAbrupt(done).
        7. If done is true, then
          1. Let value be IteratorValue(innerResult).
          2. ReturnIfAbrupt(value).
          3. Return Completion{[[type]]: return , [[value]]:value, [[target]]:empty}.
        8. Let received be GeneratorYield(innerResult).
      4. Else,
        1. NOTE: If iterator does not have a throw method, this throw is going to terminate the yield* loop. But first we need to give iterator a chance to clean up.
        2. Let closeResult be IteratorClose(iterator, Completion{[[type]]: normal , [[value]]: empty, [[target]]:empty}).
        3. ReturnIfAbrupt(closeResult).
        4. NOTE: The next step throws a TypeError to indicate that there was a yield* protocol violation: iterator does not have a throw method.
        5. Throw a TypeError exception.
    3. Else,
      1. Assert: received.[[type]] is return.
      2. Let return be GetMethod(iterator, "return").
      3. ReturnIfAbrupt(return).
      4. If return is undefined, return Completion(received).
      5. Let innerReturnResult be Call(return, iterator, «‍received.[[value]]»).
      6. ReturnIfAbrupt(innerReturnResult).
      7. If Type(innerReturnResult) is not Object, throw a TypeError exception.
      8. Let done be IteratorComplete(innerReturnResult).
      9. ReturnIfAbrupt(done).
      10. If done is true, then
        1. Let value be IteratorValue(innerReturnResult).
        2. ReturnIfAbrupt(value).
        3. Return Completion{[[type]]: return , [[value]]: value, [[target]]:empty}.
      11. Let received be GeneratorYield(innerReturnResult).

14.5 Class Definitions

Syntax

ClassDeclaration[Yield, Default] :
class BindingIdentifier[?Yield] ClassTail[?Yield]
[+Default] class ClassTail[?Yield]
ClassExpression[Yield] :
class BindingIdentifier[?Yield]opt ClassTail[?Yield]
ClassTail[Yield] :
ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }
ClassHeritage[Yield] :
extends LeftHandSideExpression[?Yield]
ClassBody[Yield] :
ClassElementList[?Yield]
ClassElementList[Yield] :
ClassElement[?Yield]
ClassElementList[?Yield] ClassElement[?Yield]
ClassElement[Yield] :
MethodDefinition[?Yield]
static MethodDefinition[?Yield]
;

NOTE A ClassBody is always strict code.

14.5.1 Static Semantics: Early Errors

ClassTail : ClassHeritageopt { ClassBody }
  • It is a Syntax Error if ClassHeritage is not present and the following algorithm evaluates to true:

    1. Let constructor be ConstructorMethod of ClassBody.
    2. If constructor is empty, return false.
    3. Return HasDirectSuper of constructor.
ClassBody : ClassElementList
  • It is a Syntax Error if PrototypePropertyNameList of ClassElementList contains more than one occurrence of "constructor".

ClassElement : MethodDefinition
  • It is a Syntax Error if PropName of MethodDefinition is not "constructor" and HasDirectSuper of MethodDefinition is true.

  • It is a Syntax Error if PropName of MethodDefinition is "constructor" and SpecialMethod of MethodDefinition is true.

ClassElement : static MethodDefinition
  • It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
  • It is a Syntax Error if PropName of MethodDefinition is "prototype".

14.5.2 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 15.2.2.2, 15.2.3.2.

ClassDeclaration : class BindingIdentifier ClassTail
  1. Return the BoundNames of BindingIdentifier.
ClassDeclaration : class ClassTail
  1. Return «"*default*"».

14.5.3 Static Semantics: ConstructorMethod

ClassElementList : ClassElement
  1. If ClassElement is the production ClassElement : ; , return empty.
  2. If IsStatic of ClassElement is true, return empty.
  3. If PropName of ClassElement is not "constructor", return empty.
  4. Return ClassElement.
ClassElementList : ClassElementList ClassElement
  1. Let head be ConstructorMethod of ClassElementList.
  2. If head is not empty, return head.
  3. If ClassElement is the production ClassElement : ; , return empty.
  4. If IsStatic of ClassElement is true, return empty.
  5. If PropName of ClassElement is not "constructor", return empty.
  6. Return ClassElement.

NOTE Early Error rules ensure that there is only one method definition named "constructor" and that it is not an accessor property or generator definition.

14.5.4 Static Semantics: Contains

With parameter symbol.

See also: 5.3, 12.2.6.3, 12.3.1.1, 14.1.4, 14.2.3, 14.4.4

ClassTail : ClassHeritageopt { ClassBody }
  1. If symbol is ClassBody, return true.
  2. If symbol is ClassHeritage, then
    1. If ClassHeritage is present, return true otherwise return false.
  3. Let inHeritage be ClassHeritage Contains symbol.
  4. If inHeritage is true, return true.
  5. Return the result of ComputedPropertyContains for ClassBody with argument symbol.

NOTE Static semantic rules that depend upon substructure generally do not look into class bodies except for PropertyName productions.

14.5.5 Static Semantics: ComputedPropertyContains

With parameter symbol.

See also: 12.2.6.2, 14.3.2, 14.4.3.

ClassElementList : ClassElementList ClassElement
  1. Let inList be the result of ComputedPropertyContains for ClassElementList with argument symbol.
  2. If inList is true, return true.
  3. Return the result of ComputedPropertyContains for ClassElement with argument symbol.
ClassElement : MethodDefinition
  1. Return the result of ComputedPropertyContains for MethodDefinition with argument symbol.
ClassElement : static MethodDefinition
  1. Return the result of ComputedPropertyContains for MethodDefinition with argument symbol.
ClassElement : ;
  1. Return false.

14.5.6 Static Semantics: HasName

See also: 12.2.1.2, 14.1.8, 14.2.7, 14.4.7.

ClassExpression : class ClassTail
  1. Return false.
ClassExpression : class BindingIdentifier ClassTail
  1. Return true.

14.5.7 Static Semantics: IsConstantDeclaration

See also: 13.3.1.3, 14.1.10, 14.4.8, 15.2.3.7.

ClassDeclaration : class BindingIdentifier ClassTail

ClassDeclaration : class ClassTail
  1. Return false.

14.5.8 Static Semantics: IsFunctionDefinition

See also: 12.2.1.3, 12.2.10.2, 12.3.1.2, 12.4.2, 12.5.2, 12.6.1, 12.7.1, 12.8.1, 12.9.1, 12.10.1, 12.11.1, 12.12.1, 12.13.1, 12.14.2, 12.15.1, 14.1.11, 14.4.9.

ClassExpression : class ClassTail
  1. Return true.
ClassExpression : class BindingIdentifier ClassTail
  1. Return true.

14.5.9 Static Semantics: IsStatic

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

14.5.10 Static Semantics: NonConstructorMethodDefinitions

ClassElementList : ClassElement
  1. If ClassElement is the production ClassElement : ; , return a new empty List.
  2. If IsStatic of ClassElement is false and PropName of ClassElement is "constructor", return a new empty List.
  3. Return a List containing ClassElement.
ClassElementList : ClassElementList ClassElement
  1. Let list be NonConstructorMethodDefinitions of ClassElementList.
  2. If ClassElement is the production ClassElement : ; , return list.
  3. If IsStatic of ClassElement is false and PropName of ClassElement is "constructor", return list.
  4. Append ClassElement to the end of list.
  5. Return list.

14.5.11 Static Semantics: PrototypePropertyNameList

ClassElementList : ClassElement
  1. If PropName of ClassElement is empty, return a new empty List.
  2. If IsStatic of ClassElement is true, return a new empty List.
  3. Return a List containing PropName of ClassElement.
ClassElementList : ClassElementList ClassElement
  1. Let list be PrototypePropertyNameList of ClassElementList.
  2. If PropName of ClassElement is empty, return list.
  3. If IsStatic of ClassElement is true, return list.
  4. Append PropName of ClassElement to the end of list.
  5. Return list.

14.5.12 Static Semantics: PropName

See also: 12.2.6.6, 14.3.6, 14.4.10

ClassElement : ;
  1. Return empty.

14.5.13 Static Semantics: StaticPropertyNameList

ClassElementList : ClassElement
  1. If PropName of ClassElement is empty, return a new empty List.
  2. If IsStatic of ClassElement is false, return a new empty List.
  3. Return a List containing PropName of ClassElement.
ClassElementList : ClassElementList ClassElement
  1. Let list be StaticPropertyNameList of ClassElementList.
  2. If PropName of ClassElement is empty, return list.
  3. If IsStatic of ClassElement is false, return list.
  4. Append PropName of ClassElement to the end of list.
  5. Return list.

14.5.14 Runtime Semantics: ClassDefinitionEvaluation

With parameter className.

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. Let lex be the LexicalEnvironment of the running execution context.
  2. Let classScope be NewDeclarativeEnvironment(lex).
  3. Let classScopeEnvRec be classScope’s EnvironmentRecord.
  4. If className is not undefined, then
    1. Perform classScopeEnvRec.CreateImmutableBinding(className, true).
  5. If ClassHeritageopt is not present, then
    1. Let protoParent be the intrinsic object %ObjectPrototype%.
    2. Let constructorParent be the intrinsic object %FunctionPrototype%.
  6. Else
    1. Set the running execution context’s LexicalEnvironment to classScope.
    2. Let superclass be the result of evaluating ClassHeritage.
    3. Set the running execution context’s LexicalEnvironment to lex.
    4. ReturnIfAbrupt(superclass).
    5. If superclass is null, then
      1. Let protoParent be null.
      2. Let constructorParent be the intrinsic object %FunctionPrototype%.
    6. Else if IsConstructor(superclass) is false, throw a TypeError exception.
    7. Else
      1. If superclass has a [[FunctionKind]] internal slot whose value is "generator", throw a TypeError exception.
      2. Let protoParent be Get(superclass, "prototype").
      3. ReturnIfAbrupt(protoParent).
      4. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
      5. Let constructorParent be superclass.
  7. Let proto be ObjectCreate(protoParent).
  8. If ClassBodyopt is not present, let constructor be empty.
  9. Else, let constructor be ConstructorMethod of ClassBody.
  10. If constructor is empty, then,
    1. If ClassHeritageopt is present, then
      1. Let constructor be the result of parsing the source text
            constructor(... args){ super (...args);}
        using the syntactic grammar with the goal symbol MethodDefinition.
    2. Else,
      1. Let constructor be the result of parsing the source text
            constructor( ){ }
        using the syntactic grammar with the goal symbol MethodDefinition.
  11. Set the running execution context’s LexicalEnvironment to classScope.
  12. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument.
  13. Assert: constructorInfo is not an abrupt completion.
  14. Let F be constructorInfo.[[closure]]
  15. If ClassHeritageopt is present, set F’s [[ConstructorKind]] internal slot to "derived".
  16. Perform MakeConstructor(F, false, proto).
  17. Perform MakeClassConstructor(F).
  18. Perform CreateMethodProperty(proto, "constructor", F).
  19. If ClassBodyopt is not present, let methods be a new empty List.
  20. Else, let methods be NonConstructorMethodDefinitions of ClassBody.
  21. For each ClassElement m in order from methods
    1. If IsStatic of m is false, then
      1. Let status be the result of performing PropertyDefinitionEvaluation for m with arguments proto and false.
    2. Else,
      1. Let status be the result of performing PropertyDefinitionEvaluation for m with arguments F and false.
    3. If status is an abrupt completion, then
      1. Set the running execution context’s LexicalEnvironment to lex.
      2. Return Completion(status).
  22. Set the running execution context’s LexicalEnvironment to lex.
  23. If className is not undefined, then
    1. Perform classScopeEnvRec.InitializeBinding(className, F).
  24. Return F.

14.5.15 Runtime Semantics: BindingClassDeclarationEvaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. Let className be StringValue of BindingIdentifier.
  2. Let value be the result of ClassDefinitionEvaluation of ClassTail with argument className.
  3. ReturnIfAbrupt(value).
  4. Let hasNameProperty be HasOwnProperty(value, "name").
  5. ReturnIfAbrupt(hasNameProperty).
  6. If hasNameProperty is false, then perform SetFunctionName(value, className).
  7. Let env be the running execution context’s LexicalEnvironment.
  8. Let status be InitializeBoundName(className, value, env).
  9. ReturnIfAbrupt(status).
  10. Return value.
ClassDeclaration : class ClassTail
  1. Return the result of ClassDefinitionEvaluation of ClassTail with argument undefined.

NOTE ClassDeclaration : class ClassTail only occurs as part of an ExportDeclaration and the setting of a name property and establishing its binding are handled as part of the evaluation action for that production. See 15.2.3.11.

14.5.16 Runtime Semantics: Evaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. Let status be the result of BindingClassDeclarationEvaluation of this ClassDeclaration.
  2. ReturnIfAbrupt(status).
  3. Return NormalCompletion(empty).

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

ClassExpression : class BindingIdentifieropt ClassTail
  1. If BindingIdentifieropt is not present, let className be undefined.
  2. Else, let className be StringValue of BindingIdentifier.
  3. Let value be the result of ClassDefinitionEvaluation of ClassTail with argument className.
  4. ReturnIfAbrupt(value).
  5. If className is not undefined, then
    1. Let hasNameProperty be HasOwnProperty(value, "name").
    2. ReturnIfAbrupt(hasNameProperty).
    3. If hasNameProperty is false, then
      1. Perform SetFunctionName(value, className).
  6. Return NormalCompletion(value).

NOTE 2 If the class definition included a name static method then that method is not over-written with a name data property for the class name.

14.6 Tail Position Calls

14.6.1 Static Semantics: IsInTailPosition(nonterminal)

The abstract operation IsInTailPosition with argument nonterminal performs the following steps:

  1. Assert: nonterminal is a parsed grammar production.
  2. If the source code matching nonterminal is not strict code, return false.
  3. If nonterminal is not contained within a FunctionBody or ConciseBody, return false.
  4. Let body be the FunctionBody or ConciseBody that most closely contains nonterminal.
  5. If body is the FunctionBody of a GeneratorBody, return false.
  6. Return the result of HasProductionInTailPosition of body with argument nonterminal.

NOTE Tail Position calls are only defined in strict mode code because of a common non-standard language extension (see 9.2.7) that enables observation of the chain of caller contexts.

14.6.2 Static Semantics: HasProductionInTailPosition

With parameter nonterminal.

NOTE nonterminal is a parsed grammar production that represent a specific range of source text. When the following algorithms compare nonterminal to other grammar symbols they are testing whether the same source text was matched by both symbols.

14.6.2.1 Statement Rules

ConciseBody : AssignmentExpression
  1. Return HasProductionInTailPosition of AssignmentExpression with argument nonterminal.
StatementList : StatementList StatementListItem
  1. Let has be HasProductionInTailPosition of StatementList with argument nonterminal.
  2. If has is true, return true.
  3. Return HasProductionInTailPosition of StatementListItem with argument nonterminal.

FunctionStatementList : [empty]

StatementListItem : Declaration

Statement :
VariableStatement
EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ThrowStatement
DebuggerStatement
Block : { }
ReturnStatement : return ;
LabelledItem : FunctionDeclaration
IterationStatement :
for ( LeftHandSideExpression in Expression ) Statement
for ( var ForBinding in Expression ) Statement
for ( ForDeclaration in Expression ) Statement
for ( LeftHandSideExpression of AssignmentExpression ) Statement
for ( var ForBinding of AssignmentExpression ) Statement
for ( ForDeclaration of AssignmentExpression ) Statement
CaseBlock : { }
  1. Return false.
IfStatement : if ( Expression ) Statement else Statement
  1. Let has be HasProductionInTailPosition of the first Statement with argument nonterminal.
  2. If has is true, return true.
  3. Return HasProductionInTailPosition of the second Statement with argument nonterminal.

IfStatement : if ( Expression ) Statement

IterationStatement :
do Statement while ( Expression ) ;
while ( Expression ) Statement
for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
WithStatement : with ( Expression ) Statement
  1. Return HasProductionInTailPosition of Statement with argument nonterminal.
LabelledStatement :
LabelIdentifier : LabelledItem
  1. Return HasProductionInTailPosition of LabelledItem with argument nonterminal.
ReturnStatement : return Expression ;
  1. Return HasProductionInTailPosition of Expression with argument nonterminal.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return HasProductionInTailPosition of CaseBlock with argument nonterminal.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. Let has be false.
  2. If the first CaseClauses is present, let has be HasProductionInTailPosition of the first CaseClauses with argument nonterminal.
  3. If has is true, return true.
  4. Let has be HasProductionInTailPosition of the DefaultClause with argument nonterminal.
  5. If has is true, return true.
  6. If the second CaseClauses is present, let has be HasProductionInTailPosition of the second CaseClauses with argument nonterminal.
  7. Return has.
CaseClauses : CaseClauses CaseClause
  1. Let has be HasProductionInTailPosition of CaseClauses with argument nonterminal.
  2. If has is true, return true.
  3. Return HasProductionInTailPosition of CaseClause with argument nonterminal.

CaseClause : case Expression : StatementListopt

DefaultClause : default : StatementListopt
  1. If StatementList is present, return HasProductionInTailPosition of StatementList with argument nonterminal.
  2. Return false.
TryStatement : try Block Catch
  1. Return HasProductionInTailPosition of Catch with argument nonterminal.

TryStatement : try Block Finally

TryStatement : try Block Catch Finally
  1. Return HasProductionInTailPosition of Finally with argument nonterminal.
Catch : catch ( CatchParameter ) Block
  1. Return HasProductionInTailPosition of Block with argument nonterminal.

14.6.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. Function calls cannot return reference values, so such a GetValue operation will always returns the same value as the actual function call result.

AssignmentExpression :
YieldExpression
ArrowFunction
LeftHandSideExpression = AssignmentExpression
LeftHandSideExpression AssignmentOperator 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 UnaryExpression
UnaryExpression :
delete UnaryExpression
void UnaryExpression
typeof UnaryExpression
++ UnaryExpression
-- UnaryExpression
+ UnaryExpression
- UnaryExpression
~ UnaryExpression
! UnaryExpression
PostfixExpression :
LeftHandSideExpression ++
LeftHandSideExpression --
CallExpression :
SuperCall
CallExpression [ Expression ]
CallExpression . IdentifierName
NewExpression : new NewExpression
MemberExpression :
MemberExpression [ Expression ]
MemberExpression . IdentifierName
SuperProperty
MetaProperty
new MemberExpression Arguments
PrimaryExpression :
this
IdentifierReference
Literal
ArrayLiteral
ObjectLiteral
FunctionExpression
ClassExpression
GeneratorExpression
RegularExpressionLiteral
TemplateLiteral
  1. Return false.
Expression :
AssignmentExpression
Expression , AssignmentExpression
  1. Return HasProductionInTailPosition of AssignmentExpression with argument nonterminal.
ConditionalExpression : LogicalORExpression ? AssignmentExpression : AssignmentExpression
  1. Let has be HasProductionInTailPosition of the first AssignmentExpression with argument nonterminal.
  2. If has is true, return true.
  3. Return HasProductionInTailPosition of the second AssignmentExpression with argument nonterminal.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. Return HasProductionInTailPosition of BitwiseORExpression with argument nonterminal.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. Return HasProductionInTailPosition of LogicalANDExpression with argument nonterminal.
CallExpression :
MemberExpression Arguments
CallExpression Arguments
CallExpression TemplateLiteral
  1. If this CallExpression is nonterminal, return true.
  2. Return false.
MemberExpression :
MemberExpression TemplateLiteral
  1. If this MemberExpression is nonterminal, return true.
  2. Return false.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. Let expr be CoveredParenthesizedExpression of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return HasProductionInTailPosition of expr with argument nonterminal.
ParenthesizedExpression :
( Expression )
  1. Return HasProductionInTailPosition of Expression with argument nonterminal.

14.6.3 Runtime Semantics: PrepareForTailCall ( )

The abstract operation PrepareForTailCall performs the following steps:

  1. Let leafContext be the running execution context.
  2. Suspend leafContext.
  3. Pop leafContext from the execution context stack. The execution context now on the top of the stack becomes the running execution context.
  4. Assert: leafContext has no further use. It will never be activated as the running execution context.

A tail position call must either release any transient internal resources associated with the currently executing function execution context before invoking the target function or reuse those resources in support of the target function.

NOTE For example, a tail position call should only grow an implementation’s activation record stack by the amount that the size of the target function’s activation record exceeds the size of the calling function’s activation record. If the target function’s activation record is smaller, then the total size of the stack should decrease.