15 ECMAScript 언어: Functions and Classes

Note

다양한 ECMAScript language element는 ECMAScript function object(10.2)의 creation을 cause합니다. 그러한 function의 Evaluation은 그 [[Call]] internal method(10.2.1)의 execution으로 시작됩니다.

15.1 Parameter Lists

Syntax

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]

15.1.1 Static Semantics: Early Errors

UniqueFormalParameters : FormalParameters FormalParameters : FormalParameterList Note

FormalParameterList 안에서 같은 BindingIdentifier가 multiple occurrence로 나타나는 것은 simple parameter list를 가지고 strict mode code 안에서 defined되지 않은 function에 대해서만 allowed됩니다.

15.1.2 Static Semantics: ContainsExpression

The syntax-directed operation ContainsExpression takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ObjectBindingPattern : { } { BindingRestProperty }
  1. false를 반환한다.
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. BindingPropertyListContainsExpression을 반환한다.
ArrayBindingPattern : [ Elisionopt ]
  1. false를 반환한다.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. BindingRestElementContainsExpression을 반환한다.
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. BindingElementListContainsExpression을 반환한다.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. hasBindingElementListContainsExpression으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. BindingRestElementContainsExpression을 반환한다.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. hasBindingPropertyListContainsExpression으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. BindingPropertyContainsExpression을 반환한다.
BindingElementList : BindingElementList , BindingElisionElement
  1. hasBindingElementListContainsExpression으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. BindingElisionElementContainsExpression을 반환한다.
BindingElisionElement : Elisionopt BindingElement
  1. BindingElementContainsExpression을 반환한다.
BindingProperty : PropertyName : BindingElement
  1. hasPropertyNameIsComputedPropertyKey로 둔다.
  2. hastrue이면, true를 반환한다.
  3. BindingElementContainsExpression을 반환한다.
BindingElement : BindingPattern Initializer
  1. true를 반환한다.
SingleNameBinding : BindingIdentifier
  1. false를 반환한다.
SingleNameBinding : BindingIdentifier Initializer
  1. true를 반환한다.
BindingRestElement : ... BindingIdentifier
  1. false를 반환한다.
BindingRestElement : ... BindingPattern
  1. BindingPatternContainsExpression을 반환한다.
FormalParameters : [empty]
  1. false를 반환한다.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterListContainsExpressiontrue이면, true를 반환한다.
  2. FunctionRestParameterContainsExpression을 반환한다.
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListContainsExpressiontrue이면, true를 반환한다.
  2. FormalParameterContainsExpression을 반환한다.
ArrowParameters : BindingIdentifier
  1. false를 반환한다.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListcovered하는 ArrowFormalParameters로 둔다.
  2. formalsContainsExpression을 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false를 반환한다.

15.1.3 Static Semantics: IsSimpleParameterList

The syntax-directed operation IsSimpleParameterList takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

BindingElement : BindingPattern
  1. false를 반환한다.
BindingElement : BindingPattern Initializer
  1. false를 반환한다.
SingleNameBinding : BindingIdentifier
  1. true를 반환한다.
SingleNameBinding : BindingIdentifier Initializer
  1. false를 반환한다.
FormalParameters : [empty]
  1. true를 반환한다.
FormalParameters : FunctionRestParameter
  1. false를 반환한다.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. false를 반환한다.
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListIsSimpleParameterListfalse이면, false를 반환한다.
  2. FormalParameterIsSimpleParameterList를 반환한다.
FormalParameter : BindingElement
  1. BindingElementIsSimpleParameterList를 반환한다.
ArrowParameters : BindingIdentifier
  1. true를 반환한다.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListcovered하는 ArrowFormalParameters로 둔다.
  2. formalsIsSimpleParameterList를 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true를 반환한다.
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHeadcovered하는 AsyncArrowHead로 둔다.
  2. headIsSimpleParameterList를 반환한다.

15.1.4 Static Semantics: HasInitializer

The syntax-directed operation HasInitializer takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

BindingElement : BindingPattern
  1. false를 반환한다.
BindingElement : BindingPattern Initializer
  1. true를 반환한다.
SingleNameBinding : BindingIdentifier
  1. false를 반환한다.
SingleNameBinding : BindingIdentifier Initializer
  1. true를 반환한다.
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListHasInitializertrue이면, true를 반환한다.
  2. FormalParameterHasInitializer를 반환한다.

15.1.5 Static Semantics: ExpectedArgumentCount

The syntax-directed operation ExpectedArgumentCount takes no arguments and returns a non-negative integer. It is defined piecewise over the following productions:

FormalParameters : [empty] FunctionRestParameter
  1. 0을 반환한다.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterListExpectedArgumentCount를 반환한다.
Note

FormalParameterList의 ExpectedArgumentCount는 rest parameter 또는 Initializer를 가진 first FormalParameter의 left에 있는 FormalParameters의 수입니다. initializer가 없는 FormalParameter는 initializer를 가진 first parameter 뒤에 allowed되지만, 그러한 parameter는 undefined를 default value로 하는 optional parameter로 considered됩니다.

FormalParameterList : FormalParameter
  1. FormalParameterHasInitializertrue이면, 0을 반환한다.
  2. 1을 반환한다.
FormalParameterList : FormalParameterList , FormalParameter
  1. countFormalParameterListExpectedArgumentCount로 둔다.
  2. FormalParameterListHasInitializertrue이거나 FormalParameterHasInitializertrue이면, count를 반환한다.
  3. count + 1을 반환한다.
ArrowParameters : BindingIdentifier
  1. 1을 반환한다.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListcovered하는 ArrowFormalParameters로 둔다.
  2. formalsExpectedArgumentCount를 반환한다.
PropertySetParameterList : FormalParameter
  1. FormalParameterHasInitializertrue이면, 0을 반환한다.
  2. 1을 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. 1을 반환한다.

15.2 Function Definitions

Syntax

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

15.2.1 Static Semantics: Early Errors

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

FunctionBodyLexicallyDeclaredNames는 var 또는 function declaration을 사용하여 bound된 identifier를 include하지 않습니다.

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

The syntax-directed operation FunctionBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionBodyDirective PrologueUse Strict Directive를 contain하면, true를 반환한다.
  2. false를 반환한다.

15.2.3 Runtime Semantics: EvaluateFunctionBody

The syntax-directed operation EvaluateFunctionBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(funcObj, argList)를 수행한다.
  2. FunctionStatementListEvaluation을 ? 수행한다.
  3. NOTE: previous step이 normal completion을 result했다면, evaluation은 FunctionStatementList의 end를 지나 proceed함으로써 finished된 것이다.
  4. ReturnCompletion(undefined)를 반환한다.

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

The syntax-directed operation InstantiateOrdinaryFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextFunctionDeclaration에 matched된 source text로 둔다.
  3. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. MakeConstructor(closure)를 수행한다.
  6. closure를 반환한다.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceTextFunctionDeclaration에 matched된 source text로 둔다.
  2. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. MakeConstructor(closure)를 수행한다.
  5. closure를 반환한다.
Note

anonymous FunctionDeclarationexport default declaration의 part로만 occur할 수 있으므로, 그 function code는 따라서 항상 strict mode code입니다.

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

The syntax-directed operation InstantiateOrdinaryFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextFunctionExpression에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. MakeConstructor(closure)를 수행한다.
  8. closure를 반환한다.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Assert: name은 present하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnvrunning execution context의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  7. sourceTextFunctionExpression에 matched된 source text로 둔다.
  8. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. MakeConstructor(closure)를 수행한다.
  11. funcEnv.InitializeBinding(name, closure)를 수행한다.
  12. closure를 반환한다.
Note

FunctionExpression 안의 BindingIdentifier는 function이 recursively 자신을 call할 수 있도록 FunctionExpressionFunctionBody 내부에서 referenced될 수 있습니다. 그러나 FunctionDeclaration과 달리 FunctionExpression 안의 BindingIdentifierFunctionExpression을 enclosing하는 scope에서 referenced될 수 없고 그 scope에 affect하지 않습니다.

15.2.6 Runtime Semantics: Evaluation

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. empty를 반환한다.
Note 1 FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. empty를 반환한다.
FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
  1. FunctionExpressionInstantiateOrdinaryFunctionExpression을 반환한다.
Note 2

FunctionDeclaration 또는 FunctionExpression을 사용하여 defined된 모든 function에는, 그 function이 constructor로 사용될 possibility를 allow하기 위해 "prototype" property가 automatically created됩니다.

FunctionStatementList : [empty]
  1. undefined를 반환한다.
FunctionStatementList : StatementList
  1. resultStatementListEvaluationCompletion으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. 단언: envDeclarative Environment Record이다.
  4. DisposeResources(env.[[DisposableResourceStack]], result)를 반환한다.

15.3 Arrow Function Definitions

Syntax

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]

Supplemental Syntax

production
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
의 instance를 processing할 때, CoverParenthesizedExpressionAndArrowParameterList의 interpretation은 다음 grammar를 사용하여 refined됩니다:

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

15.3.1 Static Semantics: Early Errors

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 Static Semantics: ConciseBodyContainsUseStrict

The syntax-directed operation ConciseBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. false를 반환한다.
ConciseBody : { FunctionBody }
  1. FunctionBodyFunctionBodyContainsUseStrict를 반환한다.

15.3.3 Runtime Semantics: EvaluateConciseBody

The syntax-directed operation EvaluateConciseBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)를 수행한다.
  2. ExpressionBodyEvaluation을 ? 반환한다.

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

The syntax-directed operation InstantiateArrowFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextArrowFunction에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, envRecord, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. closure를 반환한다.
Note

ArrowFunctionarguments, super, this 또는 new.target을 위한 local binding을 define하지 않습니다. ArrowFunction 안의 arguments, super, this 또는 new.target에 대한 모든 reference는 lexically enclosing environment 안의 binding으로 resolve되어야 합니다. 보통 이는 immediately enclosing function의 Function Environment입니다. ArrowFunctionsuper에 대한 reference를 contain할 수 있더라도, step 5에서 created되는 function objectMakeMethod를 수행하여 method로 만들어지지 않습니다. super를 reference하는 ArrowFunction은 항상 non-ArrowFunction 안에 contained되며, super를 implement하는 데 필요한 state는 ArrowFunctionfunction object가 capture하는 envRecord를 통해 accessible합니다.

15.3.5 Runtime Semantics: Evaluation

ArrowFunction : ArrowParameters => ConciseBody
  1. ArrowFunctionInstantiateArrowFunctionExpression을 반환한다.
ExpressionBody : AssignmentExpression
  1. exprRefAssignmentExpressionEvaluation으로 ? 둔다.
  2. exprValue를 ? GetValue(exprRef)로 둔다.
  3. ReturnCompletion(exprValue)를 반환한다.

15.4 Method Definitions

Syntax

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

15.4.1 Static Semantics: Early Errors

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

15.4.2 Static Semantics: HasDirectSuper

The syntax-directed operation HasDirectSuper takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. UniqueFormalParameters Contains SuperCalltrue이면, true를 반환한다.
  2. FunctionBody Contains SuperCall을 반환한다.
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. FunctionBody Contains SuperCall을 반환한다.
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. PropertySetParameterList Contains SuperCalltrue이면, true를 반환한다.
  2. FunctionBody Contains SuperCall을 반환한다.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. UniqueFormalParameters Contains SuperCalltrue이면, true를 반환한다.
  2. GeneratorBody Contains SuperCall을 반환한다.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. UniqueFormalParameters Contains SuperCalltrue이면, true를 반환한다.
  2. AsyncGeneratorBody Contains SuperCall을 반환한다.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. UniqueFormalParameters Contains SuperCalltrue이면, true를 반환한다.
  2. AsyncFunctionBody Contains SuperCall을 반환한다.

15.4.3 Static Semantics: SpecialMethod

The syntax-directed operation SpecialMethod takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. false를 반환한다.
MethodDefinition : GeneratorMethod AsyncMethod AsyncGeneratorMethod get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. true를 반환한다.

15.4.4 Runtime Semantics: DefineMethod

The syntax-directed operation DefineMethod takes argument obj (an Object) and optional argument proto (an Object) and returns either a normal completion containing a Record with fields [[Key]] (a property key) and [[Closure]] (an ECMAScript function object) or an abrupt completion. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. proto가 present하지 않으면, proto%Function.prototype%으로 설정한다.
  5. sourceTextMethodDefinition에 matched된 source text로 둔다.
  6. closureOrdinaryFunctionCreate(proto, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  7. MakeMethod(closure, obj)를 수행한다.
  8. Record { [[Key]]: propertyKey, [[Closure]]: closure }를 반환한다.

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

The syntax-directed operation MethodDefinitionEvaluation takes arguments obj (an Object) and enumerable (a Boolean) and returns either a normal completion containing either a PrivateElement or unused, or an abrupt completion. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDef를 argument obj를 가진 MethodDefinitionDefineMethod로 ? 둔다.
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]])을 수행한다.
  3. DefineMethodProperty(obj, methodDef.[[Key]], methodDef.[[Closure]], enumerable)를 반환한다.
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextMethodDefinition에 matched된 source text로 둔다.
  5. formalParamList를 production FormalParameters : [empty] 의 instance로 둔다.
  6. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  7. MakeMethod(closure, obj)를 수행한다.
  8. SetFunctionName(closure, propertyKey, "get")을 수행한다.
  9. propertyKeyPrivate Name이면, 다음을 수행한다.
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined }를 반환한다.
  10. propertyDesc를 PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둔다.
  11. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)를 수행한다.
  12. unused를 반환한다.
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextMethodDefinition에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. MakeMethod(closure, obj)를 수행한다.
  7. SetFunctionName(closure, propertyKey, "set")을 수행한다.
  8. propertyKeyPrivate Name이면, 다음을 수행한다.
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure }를 반환한다.
  9. propertyDesc를 PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둔다.
  10. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)를 수행한다.
  11. unused를 반환한다.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextGeneratorMethod에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. MakeMethod(closure, obj)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. protoOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  10. DefineMethodProperty(obj, propertyKey, closure, enumerable)를 반환한다.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncGeneratorMethod에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. MakeMethod(closure, obj)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  10. DefineMethodProperty(obj, propertyKey, closure, enumerable)를 반환한다.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKeyClassElementNameEvaluation으로 ? 둔다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncMethod에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. MakeMethod(closure, obj)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. DefineMethodProperty(obj, propertyKey, closure, enumerable)를 반환한다.

15.5 Generator Function Definitions

Syntax

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 } GeneratorMethod[Yield, Await] : * ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[+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

yield 바로 뒤의 syntactic context는 InputElementRegExpOrTemplateTail lexical goal의 use를 require합니다.

Note 2

YieldExpression은 generator function의 FormalParameters 안에서 사용할 수 없습니다. 왜냐하면 FormalParameters의 part인 모든 expression은 resulting Generator가 resumable state에 있기 전에 evaluated되기 때문입니다.

Note 3

Generator와 관련된 abstract operation은 27.8.3에 defined되어 있습니다.

15.5.1 Static Semantics: Early Errors

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

15.5.2 Runtime Semantics: EvaluateGeneratorBody

The syntax-directed operation EvaluateGeneratorBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a throw completion or a return completion. It is defined piecewise over the following productions:

GeneratorBody : FunctionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)를 수행한다.
  2. gen을 ? OrdinaryCreateFromConstructor(funcObj, "%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] »)로 둔다.
  3. gen.[[GeneratorBrand]]empty로 설정한다.
  4. gen.[[GeneratorState]]suspended-start로 설정한다.
  5. GeneratorStart(gen, FunctionBody)를 수행한다.
  6. ReturnCompletion(gen)을 반환한다.

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

The syntax-directed operation InstantiateGeneratorFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextGeneratorDeclaration에 matched된 source text로 둔다.
  3. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. protoOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. closure를 반환한다.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceTextGeneratorDeclaration에 matched된 source text로 둔다.
  2. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. protoOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  6. closure를 반환한다.
Note

anonymous GeneratorDeclarationexport default declaration의 part로만 occur할 수 있으므로, 그 function code는 따라서 항상 strict mode code입니다.

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

The syntax-directed operation InstantiateGeneratorFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextGeneratorExpression에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. protoOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  9. closure를 반환한다.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Assert: name은 present하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnvrunning execution context의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  7. sourceTextGeneratorExpression에 matched된 source text로 둔다.
  8. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. protoOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  12. funcEnv.InitializeBinding(name, closure)를 수행한다.
  13. closure를 반환한다.
Note

GeneratorExpression 안의 BindingIdentifier는 generator code가 recursively 자신을 call할 수 있도록 GeneratorExpressionFunctionBody 내부에서 referenced될 수 있습니다. 그러나 GeneratorDeclaration과 달리 GeneratorExpression 안의 BindingIdentifierGeneratorExpression을 enclosing하는 scope에서 referenced될 수 없고 그 scope에 affect하지 않습니다.

15.5.5 Runtime Semantics: Evaluation

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpressionInstantiateGeneratorFunctionExpression을 반환한다.
YieldExpression : yield
  1. Yield(undefined)를 반환한다.
YieldExpression : yield AssignmentExpression
  1. exprRefAssignmentExpressionEvaluation으로 ? 둔다.
  2. value를 ? GetValue(exprRef)로 둔다.
  3. Yield(value)를 반환한다.
YieldExpression : yield * AssignmentExpression
  1. genKindGetGeneratorKind()로 둔다.
  2. Assert: genKindsync 또는 async 중 하나이다.
  3. exprRefAssignmentExpressionEvaluation으로 ? 둔다.
  4. value를 ? GetValue(exprRef)로 둔다.
  5. iteratorRecord를 ? GetIterator(value, genKind)로 둔다.
  6. iteratoriteratorRecord.[[Iterator]]로 둔다.
  7. receivedNormalCompletion(undefined)로 둔다.
  8. Repeat,
    1. receivednormal completion이면, 다음을 수행한다.
      1. innerResult를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »)로 둔다.
      2. genKindasync이면, innerResult를 ? Await(innerResult)로 설정한다.
      3. innerResult가 Object가 아니면, TypeError exception을 throw한다.
      4. done을 ? IteratorComplete(innerResult)로 둔다.
      5. donetrue이면, 다음을 수행한다.
        1. IteratorValue(innerResult)를 반환한다.
      6. genKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))로 설정한다.
      7. 그렇지 않으면, receivedCompletion(GeneratorYield(innerResult))로 설정한다.
    2. 그렇지 않고 receivedthrow completion이면, 다음을 수행한다.
      1. throw를 ? GetMethod(iterator, "throw")로 둔다.
      2. throwundefined가 아니면, 다음을 수행한다.
        1. innerResult를 ? Call(throw, iterator, « received.[[Value]] »)로 둔다.
        2. genKindasync이면, innerResult를 ? Await(innerResult)로 설정한다.
        3. NOTE: inner iterator throw method로부터의 exception은 propagated된다. inner throw method로부터의 normal completion은 inner next와 similar하게 processed된다.
        4. innerResult가 Object가 아니면, TypeError exception을 throw한다.
        5. done을 ? IteratorComplete(innerResult)로 둔다.
        6. donetrue이면, 다음을 수행한다.
          1. IteratorValue(innerResult)를 반환한다.
        7. genKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))로 설정한다.
        8. 그렇지 않으면, receivedCompletion(GeneratorYield(innerResult))로 설정한다.
      3. 그렇지 않으면,
        1. NOTE: iteratorthrow method를 가지지 않으면, 이 throw는 yield* loop를 terminate할 것이다. 하지만 먼저 iterator에게 cleanup할 chance를 주어야 한다.
        2. closeCompletionNormalCompletion(empty)로 둔다.
        3. genKindasync이면, ? AsyncIteratorClose(iteratorRecord, closeCompletion)를 수행한다.
        4. 그렇지 않으면, ? IteratorClose(iteratorRecord, closeCompletion)를 수행한다.
        5. NOTE: next step은 yield* protocol violation이 있었음을 indicate하기 위해 TypeError를 throw한다: iteratorthrow method를 가지지 않는다.
        6. TypeError exception을 throw한다.
    3. 그렇지 않으면,
      1. Assert: receivedreturn completion이다.
      2. return을 ? GetMethod(iterator, "return")으로 둔다.
      3. returnundefined이면, 다음을 수행한다.
        1. receivedValuereceived.[[Value]]로 둔다.
        2. genKindasync이면, 다음을 수행한다.
          1. receivedValue를 ? Await(receivedValue)로 설정한다.
        3. ReturnCompletion(receivedValue)를 반환한다.
      4. innerReturnResult를 ? Call(return, iterator, « received.[[Value]] »)로 둔다.
      5. genKindasync이면, innerReturnResult를 ? Await(innerReturnResult)로 설정한다.
      6. innerReturnResult가 Object가 아니면, TypeError exception을 throw한다.
      7. done을 ? IteratorComplete(innerReturnResult)로 둔다.
      8. donetrue이면, 다음을 수행한다.
        1. returnedValue를 ? IteratorValue(innerReturnResult)로 둔다.
        2. ReturnCompletion(returnedValue)를 반환한다.
      9. genKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerReturnResult)))로 설정한다.
      10. 그렇지 않으면, receivedCompletion(GeneratorYield(innerReturnResult))로 설정한다.

15.6 Async Generator Function Definitions

Syntax

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

YieldExpressionAwaitExpression은 async generator function의 FormalParameters 안에서 사용할 수 없습니다. 왜냐하면 FormalParameters의 part인 모든 expression은 resulting AsyncGenerator가 resumable state에 있기 전에 evaluated되기 때문입니다.

Note 2

AsyncGenerator와 관련된 abstract operation은 27.9.3에 defined되어 있습니다.

15.6.1 Static Semantics: Early Errors

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

15.6.2 Runtime Semantics: EvaluateAsyncGeneratorBody

The syntax-directed operation EvaluateAsyncGeneratorBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a throw completion or a return completion. It is defined piecewise over the following productions:

AsyncGeneratorBody : FunctionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)를 수행한다.
  2. gen을 ? OrdinaryCreateFromConstructor(funcObj, "%AsyncGeneratorPrototype%", « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]], [[GeneratorBrand]] »)로 둔다.
  3. gen.[[GeneratorBrand]]empty로 설정한다.
  4. gen.[[AsyncGeneratorState]]suspended-start로 설정한다.
  5. AsyncGeneratorStart(gen, FunctionBody)를 수행한다.
  6. ReturnCompletion(gen)을 반환한다.

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

The syntax-directed operation InstantiateAsyncGeneratorFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextAsyncGeneratorDeclaration에 matched된 source text로 둔다.
  3. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. closure를 반환한다.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceTextAsyncGeneratorDeclaration에 matched된 source text로 둔다.
  2. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  6. closure를 반환한다.
Note

anonymous AsyncGeneratorDeclarationexport default declaration의 part로만 occur할 수 있습니다.

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

The syntax-directed operation InstantiateAsyncGeneratorFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncGeneratorExpression에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  9. closure를 반환한다.
AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. Assert: name은 present하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnvrunning execution context의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  7. sourceTextAsyncGeneratorExpression에 matched된 source text로 둔다.
  8. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  12. funcEnv.InitializeBinding(name, closure)를 수행한다.
  13. closure를 반환한다.
Note

AsyncGeneratorExpression 안의 BindingIdentifier는 generator code가 recursively 자신을 call할 수 있도록 AsyncGeneratorExpressionAsyncGeneratorBody 내부에서 referenced될 수 있습니다. 그러나 AsyncGeneratorDeclaration과 달리 AsyncGeneratorExpression 안의 BindingIdentifierAsyncGeneratorExpression을 enclosing하는 scope에서 referenced될 수 없고 그 scope에 affect하지 않습니다.

15.6.5 Runtime Semantics: Evaluation

AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }
  1. AsyncGeneratorExpressionInstantiateAsyncGeneratorFunctionExpression을 반환한다.

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] : 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] ; ClassStaticBlock ; FieldDefinition[Yield, Await] : ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt ClassElementName[Yield, Await] : PropertyName[?Yield, ?Await] PrivateIdentifier ClassStaticBlock : static { ClassStaticBlockBody } ClassStaticBlockBody : ClassStaticBlockStatementList ClassStaticBlockStatementList : StatementList[~Yield, +Await, ~Return]opt Note

class definition은 항상 strict mode code입니다.

15.7.1 Static Semantics: Early Errors

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList
  • ClassElementListPrototypePropertyNameList"constructor"의 occurrence를 둘 이상 contain하면 Syntax Error입니다.
  • ClassElementListPrivateBoundIdentifiers가 duplicate entry를 contain하면 Syntax Error입니다. 단, name이 getter에 한 번, setter에 한 번 사용되고 다른 entry에는 사용되지 않으며, getter와 setter가 둘 다 static이거나 둘 다 non-static인 경우는 예외입니다.
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ; FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 Static Semantics: ClassElementKind

The syntax-directed operation ClassElementKind takes no arguments and returns constructor-method, non-constructor-method, or empty. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. MethodDefinitionPropName"constructor"이면, constructor-method를 반환한다.
  2. non-constructor-method를 반환한다.
ClassElement : static MethodDefinition FieldDefinition ; static FieldDefinition ;
  1. non-constructor-method를 반환한다.
ClassElement : ClassStaticBlock
  1. non-constructor-method를 반환한다.
ClassElement : ;
  1. empty를 반환한다.

15.7.3 Static Semantics: ConstructorMethod

The syntax-directed operation ConstructorMethod takes no arguments and returns a ClassElement Parse Node or empty. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElementClassElementKindconstructor-method이면, ClassElement를 반환한다.
  2. empty를 반환한다.
ClassElementList : ClassElementList ClassElement
  1. headClassElementListConstructorMethod로 둔다.
  2. headempty가 아니면, head를 반환한다.
  3. ClassElementClassElementKindconstructor-method이면, ClassElement를 반환한다.
  4. empty를 반환한다.
Note

Early Error rule은 "constructor"라는 name의 method definition이 하나만 있고 그것이 accessor property 또는 generator definition이 아님을 ensure합니다.

15.7.4 Static Semantics: IsStatic

The syntax-directed operation IsStatic takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. false를 반환한다.
ClassElement : static MethodDefinition
  1. true를 반환한다.
ClassElement : FieldDefinition ;
  1. false를 반환한다.
ClassElement : static FieldDefinition ;
  1. true를 반환한다.
ClassElement : ClassStaticBlock
  1. true를 반환한다.
ClassElement : ;
  1. false를 반환한다.

15.7.5 Static Semantics: NonConstructorElements

The syntax-directed operation NonConstructorElements takes no arguments and returns a List of ClassElement Parse Nodes. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElementClassElementKindnon-constructor-method이면, 다음을 수행한다.
    1. « ClassElement »를 반환한다.
  2. 새 empty List를 반환한다.
ClassElementList : ClassElementList ClassElement
  1. listClassElementListNonConstructorElements로 둔다.
  2. ClassElementClassElementKindnon-constructor-method이면, 다음을 수행한다.
    1. ClassElementlist에 append한다.
  3. list를 반환한다.

15.7.6 Static Semantics: PrototypePropertyNameList

The syntax-directed operation PrototypePropertyNameList takes no arguments and returns a List of property keys. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. propertyNameClassElementPropName으로 둔다.
  2. propertyNameempty이면, 새 empty List를 반환한다.
  3. ClassElementIsStatictrue이면, 새 empty List를 반환한다.
  4. « propertyName »를 반환한다.
ClassElementList : ClassElementList ClassElement
  1. listClassElementListPrototypePropertyNameList로 둔다.
  2. propertyNameClassElementPropName으로 둔다.
  3. propertyNameempty이면, list를 반환한다.
  4. ClassElementIsStatictrue이면, list를 반환한다.
  5. list와 « propertyName »의 list-concatenation을 반환한다.

15.7.7 Static Semantics: AllPrivateIdentifiersValid

The syntax-directed operation AllPrivateIdentifiersValid takes argument names (a List of Strings) and returns a Boolean.

이 명세에서 아래에 listed되지 않은 모든 grammar production alternative는 암묵적으로 AllPrivateIdentifiersValid에 대해 다음 default definition을 가집니다:

  1. Parse Node의 각 child node child에 대해, 다음을 수행한다.
    1. child가 nonterminal의 instance이면, 다음을 수행한다.
      1. argument names를 가진 childAllPrivateIdentifiersValidfalse이면, false를 반환한다.
  2. true를 반환한다.
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 contain하면, 다음을 수행한다.
    1. argument names를 가진 MemberExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 contain하면, 다음을 수행한다.
    1. argument names를 가진 CallExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 contain하면, true를 반환한다.
  2. false를 반환한다.
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 contain하면, 다음을 수행한다.
    1. argument names를 가진 OptionalChainAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
ClassBody : ClassElementList
  1. newNamesnamesClassBodyPrivateBoundIdentifierslist-concatenation으로 둔다.
  2. argument newNames를 가진 ClassElementListAllPrivateIdentifiersValid를 반환한다.
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifierStringValue를 contain하면, 다음을 수행한다.
    1. argument names를 가진 ShiftExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.

15.7.8 Static Semantics: PrivateBoundIdentifiers

The syntax-directed operation PrivateBoundIdentifiers takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementNamePrivateBoundIdentifiers를 반환한다.
ClassElementName : PrivateIdentifier
  1. sole element가 PrivateIdentifierStringValueList를 반환한다.
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 새 empty List를 반환한다.
ClassElementList : ClassElementList ClassElement
  1. names1ClassElementListPrivateBoundIdentifiers로 둔다.
  2. names2ClassElementPrivateBoundIdentifiers로 둔다.
  3. names1names2list-concatenation을 반환한다.
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. ClassElementNamePrivateBoundIdentifiers를 반환한다.

15.7.9 Static Semantics: ContainsArguments

The syntax-directed operation ContainsArguments takes no arguments and returns a Boolean.

이 명세에서 아래에 listed되지 않은 모든 grammar production alternative는 암묵적으로 ContainsArguments에 대해 다음 default definition을 가집니다:

  1. Parse Node의 각 child node child에 대해, 다음을 수행한다.
    1. child가 nonterminal의 instance이면, 다음을 수행한다.
      1. childContainsArgumentstrue이면, true를 반환한다.
  2. false를 반환한다.
IdentifierReference : Identifier
  1. IdentifierStringValue"arguments"이면, true를 반환한다.
  2. false를 반환한다.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. false를 반환한다.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. ClassElementNameContainsArguments를 반환한다.

15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation

The syntax-directed operation ClassFieldDefinitionEvaluation takes argument homeObj (an Object) and returns either a normal completion containing a ClassFieldDefinition Record or an abrupt completion. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. nameClassElementNameEvaluation으로 ? 둔다.
  2. Initializer가 present하면, 다음을 수행한다.
    1. formalParamList를 production FormalParameters : [empty] 의 instance로 둔다.
    2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
    3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
    4. sourceText를 Unicode code point의 empty sequence로 둔다.
    5. initializerOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, Initializer, non-lexical-this, envRecord, privateEnv)로 둔다.
    6. MakeMethod(initializer, homeObj)를 수행한다.
    7. initializer.[[ClassFieldInitializerName]]name으로 설정한다.
  3. 그렇지 않으면,
    1. initializerempty로 둔다.
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer }를 반환한다.
Note
initializer를 위해 created된 function은 ECMAScript code에 의해 never directly accessible하지 않습니다.

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

The syntax-directed operation ClassStaticBlockDefinitionEvaluation takes argument homeObj (an Object) and returns a ClassStaticBlockDefinition Record. It is defined piecewise over the following productions:

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lexicalEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment라고 하자.
  2. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment라고 하자.
  3. sourceText를 Unicode 코드 포인트의 빈 시퀀스라고 하자.
  4. formalParams를 생성식 FormalParameters : [empty] 의 인스턴스라고 하자.
  5. bodyFuncOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParams, ClassStaticBlockBody, non-lexical-this, lexicalEnv, privateEnv)라고 하자.
  6. MakeMethod(bodyFunc, homeObj)를 수행한다.
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunc }를 반환한다.
Note
function bodyFunc는 ECMAScript code에 의해 never directly accessible하지 않습니다.

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

The syntax-directed operation EvaluateClassStaticBlockBody takes argument funcObj (an ECMAScript function object) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. 단언: funcObjClassStaticBlockDefinitionEvaluation 단계 5에서 생성된 합성 함수이다.
  2. FunctionDeclarationInstantiation(funcObj, « »)를 수행한다.
  3. resultClassStaticBlockStatementListEvaluationCompletion으로 둔다.
  4. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  5. 단언: envRecordDeclarative Environment Record이다.
  6. DisposeResources(envRecord.[[DisposableResourceStack]], result)를 수행한다.
  7. ReturnCompletion(undefined)을 반환한다.

15.7.13 Runtime Semantics: ClassElementEvaluation

The syntax-directed operation ClassElementEvaluation takes argument obj (an Object) and returns either a normal completion containing either a ClassFieldDefinition Record, a ClassStaticBlockDefinition Record, a PrivateElement, or unused, or an abrupt completion. It is defined piecewise over the following productions:

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. argument obj를 가진 FieldDefinitionClassFieldDefinitionEvaluation을 ? 반환한다.
ClassElement : MethodDefinition static MethodDefinition
  1. arguments objfalse를 가진 MethodDefinitionMethodDefinitionEvaluation을 ? 반환한다.
ClassElement : ClassStaticBlock
  1. argument obj를 가진 ClassStaticBlockClassStaticBlockDefinitionEvaluation을 반환한다.
ClassElement : ;
  1. unused를 반환한다.

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

The syntax-directed operation ClassDefinitionEvaluation takes arguments classBinding (a String or undefined), className (a property key or a Private Name), and sourceText (ECMAScript source text) and returns either a normal completion containing a function object or an abrupt completion.

Note

specification의 ease를 위해, private method와 accessor는 private field와 함께 class instance의 [[PrivateElements]] slot에 included됩니다. 그러나 given object는 given class에 의해 defined된 private method 및 accessor를 모두 가지거나 전혀 가지지 않습니다. 이 feature는 implementation이 각 method 또는 accessor를 individual하게 tracking할 필요가 없는 strategy를 사용하여 private method와 accessor를 implement하도록 choose할 수 있게 designed되었습니다.

예를 들어, implementation은 instance private method를 그 corresponding Private Name과 직접 associate하고, 각 object에 대해 어느 class constructor가 그 object를 this value로 사용하여 run되었는지를 track할 수 있습니다. 그러면 object에서 instance private method를 looking up하는 것은 method를 define하는 class constructor가 object를 initialize하는 데 사용되었는지 checking한 다음, Private Name과 associated된 method를 returning하는 것으로 구성됩니다.

이는 private field와 다릅니다: field initializer는 class instantiation 중에 throw할 수 있으므로, individual object는 given class의 private field의 proper subset만 가질 수 있고, 따라서 private field는 일반적으로 individual하게 tracked되어야 합니다.

It is defined piecewise over the following productions:

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment라고 하자.
  2. classEnvNewDeclarativeEnvironment(envRecord)라고 하자.
  3. classBindingundefined가 아니면,
    1. classEnv.CreateImmutableBinding(classBinding, true)를 수행한다.
  4. outerPrivateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment라고 하자.
  5. classPrivateEnvNewPrivateEnvironment(outerPrivateEnv)라고 하자.
  6. ClassBody가 있으면,
    1. ClassBodyPrivateBoundIdentifiers의 각 String description에 대해 다음을 수행한다.
      1. classPrivateEnv.[[Names]][[Description]]descriptionPrivate Name privateName을 포함하면,
        1. Assert: 이것은 getter/setter 쌍에 대해서만 가능하다.
      2. 그렇지 않으면,
        1. name[[Description]]description인 새로운 Private Name이라고 하자.
        2. nameclassPrivateEnv.[[Names]]에 추가한다.
  7. ClassHeritage가 없으면,
    1. protoParent%Object.prototype%이라고 하자.
    2. ctorParent%Function.prototype%이라고 하자.
  8. 그렇지 않으면,
    1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정한다.
    2. NOTE: ClassHeritage를 평가할 때 실행 중인 실행 컨텍스트의 PrivateEnvironment는 outerPrivateEnv이다.
    3. superclassRefClassHeritageEvaluationCompletion이라고 하자.
    4. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정한다.
    5. superclass를 ? GetValue(? superclassRef)라고 하자.
    6. superclassnull이면,
      1. protoParentnull이라고 하자.
      2. ctorParent%Function.prototype%이라고 하자.
    7. 그렇지 않고 IsConstructor(superclass)가 false이면,
      1. TypeError 예외를 던진다.
    8. 그렇지 않으면,
      1. protoParent를 ? Get(superclass, "prototype")라고 하자.
      2. protoParent가 Object가 아니고 protoParentnull도 아니면, TypeError 예외를 던진다.
      3. ctorParentsuperclass라고 하자.
  9. protoOrdinaryObjectCreate(protoParent)라고 하자.
  10. ClassBody가 없으면 ctorempty라고 하자.
  11. 그렇지 않으면, ctorClassBodyConstructorMethod라고 하자.
  12. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정한다.
  13. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 classPrivateEnv로 설정한다.
  14. ctorempty이면,
    1. defaultCtor를 매개변수가 없고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 수행하는 새로운 Abstract Closure라고 하자.
      1. args[[Call]] 또는 [[Construct]]가 이 함수에 전달한 인수의 List라고 하자.
      2. NewTarget이 undefined이면, TypeError 예외를 던진다.
      3. ctorFunc활성 함수 객체라고 하자.
      4. ctorFunc.[[ConstructorKind]]derived이면,
        1. NOTE: 이 분기는 constructor(...args) { super(...args); }와 유사하게 동작한다. 가장 두드러진 차이점은 앞의 ECMAScript 소스 텍스트는 관찰 가능하게 %Array.prototype%%Symbol.iterator% 메서드를 호출하지만, 이 함수는 그렇지 않다는 점이다.
        2. func를 ! ctorFunc.[[GetPrototypeOf]]()라고 하자.
        3. IsConstructor(func)가 false이면, TypeError 예외를 던진다.
        4. result를 ? Construct(func, args, NewTarget)라고 하자.
      5. 그렇지 않으면,
        1. NOTE: 이 분기는 constructor() {}와 유사하게 동작한다.
        2. result를 ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%")라고 하자.
      6. InitializeInstanceElements(result, ctorFunc)를 수행한다.
      7. NormalCompletion(result)를 반환한다.
    2. ctorFuncCreateBuiltinFunction(defaultCtor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », the current Realm Record, ctorParent)라고 하자.
  15. 그렇지 않으면,
    1. ctorInfoctorDefineMethod에 인수 protoctorParent를 전달한 결과라고 하자.
    2. ctorFuncctorInfo.[[Closure]]라고 하자.
    3. MakeClassConstructor(ctorFunc)를 수행한다.
    4. SetFunctionName(ctorFunc, className)를 수행한다.
  16. ctorFunc.[[SourceText]]sourceText로 설정한다.
  17. MakeConstructor(ctorFunc, false, proto)를 수행한다.
  18. ClassHeritage가 있으면, ctorFunc.[[ConstructorKind]]derived로 설정한다.
  19. DefineMethodProperty(proto, "constructor", ctorFunc, false)를 수행한다.
  20. ClassBody가 없으면 classElements를 새로운 빈 List라고 하자.
  21. 그렇지 않으면, classElementsClassBodyNonConstructorElements라고 하자.
  22. instancePrivateMethods를 새로운 빈 List라고 하자.
  23. staticPrivateMethods를 새로운 빈 List라고 하자.
  24. instanceFields를 새로운 빈 List라고 하자.
  25. staticElements를 새로운 빈 List라고 하자.
  26. classElements의 각 ClassElement classElement에 대해 다음을 수행한다.
    1. classElementIsStaticfalse이면,
      1. element를 인수 proto를 사용한 classElementClassElementEvaluationCompletion이라고 하자.
    2. 그렇지 않으면,
      1. element를 인수 ctorFunc를 사용한 classElementClassElementEvaluationCompletion이라고 하자.
    3. elementabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정한다.
      2. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정한다.
      3. element를 반환한다.
    4. element를 ! element로 설정한다.
    5. elementPrivateElement이면,
      1. Assert: element.[[Kind]]method 또는 accessor 중 하나이다.
      2. classElementIsStaticfalse이면 containerinstancePrivateMethods라고 하자.
      3. 그렇지 않으면, containerstaticPrivateMethods라고 하자.
      4. container[[Key]]element.[[Key]]PrivateElement existingElement를 포함하면,
        1. Assert: element.[[Kind]]existingElement.[[Kind]]는 둘 다 accessor이다.
        2. element.[[Get]]undefined이면,
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: existingElement.[[Get]], [[Set]]: element.[[Set]] }라고 하자.
        3. 그렇지 않으면,
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: element.[[Get]], [[Set]]: existingElement.[[Set]] }라고 하자.
        4. containerexistingElementcombined로 대체한다.
      5. 그렇지 않으면,
        1. elementcontainer에 추가한다.
    6. 그렇지 않고 elementClassFieldDefinition Record이면,
      1. classElementIsStaticfalse이면, elementinstanceFields에 추가한다.
      2. 그렇지 않으면, elementstaticElements에 추가한다.
    7. 그렇지 않고 elementClassStaticBlockDefinition Record이면,
      1. elementstaticElements에 추가한다.
  27. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정한다.
  28. classBindingundefined가 아니면,
    1. classEnv.InitializeBinding(classBinding, ctorFunc)를 수행한다.
  29. ctorFunc.[[PrivateMethods]]instancePrivateMethods로 설정한다.
  30. ctorFunc.[[Fields]]instanceFields로 설정한다.
  31. staticPrivateMethods의 각 PrivateElement method에 대해 다음을 수행한다.
    1. PrivateMethodOrAccessorAdd(ctorFunc, method)를 수행한다.
  32. staticElements의 각 요소 elementRecord에 대해 다음을 수행한다.
    1. elementRecordClassFieldDefinition Record이면,
      1. resultCompletion(DefineField(ctorFunc, elementRecord))라고 하자.
    2. 그렇지 않으면,
      1. Assert: elementRecordClassStaticBlockDefinition Record이다.
      2. resultCompletion(Call(elementRecord.[[BodyFunction]], ctorFunc))라고 하자.
    3. resultabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정한다.
      2. result를 반환한다.
  33. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정한다.
  34. ctorFunc를 반환한다.

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

The syntax-directed operation BindingClassDeclarationEvaluation takes no arguments and returns either a normal completion containing a function object or an abrupt completion. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue로 둔다.
  2. sourceTextClassDeclaration에 matched된 source text로 둔다.
  3. value를 arguments className, className, 및 sourceText를 가진 ClassTailClassDefinitionEvaluation으로 ? 둔다.
  4. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  5. InitializeBoundName(className, value, envRecord)를 수행한다.
  6. value를 반환한다.
ClassDeclaration : class ClassTail
  1. sourceTextClassDeclaration에 matched된 source text로 둔다.
  2. arguments undefined, "default", 및 sourceText를 가진 ClassTailClassDefinitionEvaluation을 ? 반환한다.
Note

ClassDeclaration : class ClassTail ExportDeclaration의 part로만 occur하며, 그 binding의 establishment는 해당 production을 위한 evaluation action의 part로 handled됩니다. 16.2.3.7를 참조하십시오.

15.7.16 Runtime Semantics: Evaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. this ClassDeclarationBindingClassDeclarationEvaluation을 ? 수행한다.
  2. empty를 반환한다.
Note

ClassDeclaration : class ClassTail ExportDeclaration의 part로만 occur하며 never directly evaluated되지 않습니다.

ClassExpression : class ClassTail
  1. sourceTextClassExpression에 matched된 source text로 둔다.
  2. arguments undefined, empty String, 및 sourceText를 가진 ClassTailClassDefinitionEvaluation을 ? 반환한다.
ClassExpression : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue로 둔다.
  2. sourceTextClassExpression에 matched된 source text로 둔다.
  3. arguments className, className, 및 sourceText를 가진 ClassTailClassDefinitionEvaluation을 ? 반환한다.
ClassElementName : PrivateIdentifier
  1. privateIdentifierPrivateIdentifierStringValue로 둔다.
  2. privateEnvRecordrunning execution context의 PrivateEnvironment로 둔다.
  3. namesprivateEnvRecord.[[Names]]로 둔다.
  4. Assert: names의 exactly one element는 [[Description]]privateIdentifierPrivate Name이다.
  5. privateName[[Description]]privateIdentifiernames 안의 Private Name으로 둔다.
  6. privateName을 반환한다.
ClassStaticBlockStatementList : [empty]
  1. undefined를 반환한다.

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] ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionBody : FunctionBody[~Yield, +Await] AwaitExpression[Yield] : await UnaryExpression[?Yield, +Await] Note 1

[Await] parameter가 present할 때 awaitAwaitExpressionkeyword로 parsed됩니다. [Await] parameter는 다음 context의 top level에서 present하지만, FunctionBody와 같은 nonterminal에 따라 일부 context에서는 parameter가 absent할 수 있습니다:

Script가 syntactic goal symbol일 때, [Await] parameter가 absent하면 await는 identifier로 parsed될 수 있습니다. 여기에는 다음 context가 포함됩니다:

Note 2

YieldExpression과 달리, AwaitExpression의 operand를 omit하는 것은 Syntax Error입니다. 반드시 something을 await해야 합니다.

15.8.1 Static Semantics: Early Errors

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

15.8.2 Runtime Semantics: InstantiateAsyncFunctionObject

The syntax-directed operation InstantiateAsyncFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextAsyncFunctionDeclaration에 matched된 source text로 둔다.
  3. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. closure를 반환한다.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclaration에 matched된 source text로 둔다.
  2. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. closure를 반환한다.

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

The syntax-directed operation InstantiateAsyncFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncFunctionExpression에 matched된 source text로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. closure를 반환한다.
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. Assert: name은 present하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnvrunning execution context의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  7. sourceTextAsyncFunctionExpression에 matched된 source text로 둔다.
  8. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. funcEnv.InitializeBinding(name, closure)를 수행한다.
  11. closure를 반환한다.
Note

AsyncFunctionExpression 안의 BindingIdentifier는 function이 recursively 자신을 call할 수 있도록 AsyncFunctionExpressionAsyncFunctionBody 내부에서 referenced될 수 있습니다. 그러나 FunctionDeclaration과 달리 AsyncFunctionExpression 안의 BindingIdentifierAsyncFunctionExpression을 enclosing하는 scope에서 referenced될 수 없고 그 scope에 affect하지 않습니다.

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

The syntax-directed operation EvaluateAsyncFunctionBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion. It is defined piecewise over the following productions:

AsyncFunctionBody : FunctionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둔다.
  2. completionCompletion(FunctionDeclarationInstantiation(funcObj, argList))로 둔다.
  3. completionabrupt completion이면, 다음을 수행한다.
    1. Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)를 수행한다.
  4. 그렇지 않으면,
    1. AsyncFunctionStart(promiseCapability, FunctionBody)를 수행한다.
  5. ReturnCompletion(promiseCapability.[[Promise]])를 반환한다.

15.8.5 Runtime Semantics: Evaluation

AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. AsyncFunctionExpressionInstantiateAsyncFunctionExpression을 반환한다.
UnaryExpression : CoverAwaitExpressionAndAwaitUsingDeclarationHead
  1. exprCoverAwaitExpressionAndAwaitUsingDeclarationHead가 cover하는 AwaitExpression으로 둔다.
  2. exprEvaluation을 ? 반환한다.
AwaitExpression : await UnaryExpression
  1. exprRefUnaryExpressionEvaluation으로 ? 둔다.
  2. value를 ? GetValue(exprRef)로 둔다.
  3. Await(value)를 반환한다.

15.9 Async Arrow Function Definitions

Syntax

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]

Supplemental Syntax

production
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
의 instance를 processing할 때, CoverCallExpressionAndAsyncArrowHead의 interpretation은 다음 grammar를 사용하여 refined됩니다:

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

15.9.1 Static Semantics: Early Errors

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody

15.9.2 Static Semantics: AsyncConciseBodyContainsUseStrict

The syntax-directed operation AsyncConciseBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. false를 반환한다.
AsyncConciseBody : { AsyncFunctionBody }
  1. AsyncFunctionBodyFunctionBodyContainsUseStrict를 반환한다.

15.9.3 Runtime Semantics: EvaluateAsyncConciseBody

The syntax-directed operation EvaluateAsyncConciseBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둔다.
  2. completionCompletion(FunctionDeclarationInstantiation(funcObj, argList))로 둔다.
  3. completionabrupt completion이면, 다음을 수행한다.
    1. Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)를 수행한다.
  4. 그렇지 않으면,
    1. AsyncFunctionStart(promiseCapability, ExpressionBody)를 수행한다.
  5. ReturnCompletion(promiseCapability.[[Promise]])를 반환한다.

15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression

The syntax-directed operation InstantiateAsyncArrowFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncArrowFunction에 matched된 source text로 둔다.
  5. paramsAsyncArrowBindingIdentifier로 둔다.
  6. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)로 둔다.
  7. SetFunctionName(closure, name)을 수행한다.
  8. closure를 반환한다.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. name이 present하지 않으면, name을 empty String으로 설정한다.
  2. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  3. privateEnvrunning execution context의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncArrowFunction에 matched된 source text로 둔다.
  5. headCoverCallExpressionAndAsyncArrowHeadcovered하는 AsyncArrowHead로 둔다.
  6. paramsheadArrowFormalParameters로 둔다.
  7. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)로 둔다.
  8. SetFunctionName(closure, name)을 수행한다.
  9. closure를 반환한다.

15.9.5 Runtime Semantics: Evaluation

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. AsyncArrowFunctionInstantiateAsyncArrowFunctionExpression을 반환한다.

15.10 Tail Position Calls

15.10.1 Static Semantics: IsInTailPosition ( call )

The abstract operation IsInTailPosition takes argument call (a CallExpression Parse Node, a MemberExpression Parse Node, or an OptionalChain Parse Node) and returns a Boolean. It performs the following steps when called:

  1. IsStrict(call)가 false이면, false를 반환한다.
  2. callFunctionBody, ConciseBody 또는 AsyncConciseBody 안에 contained되어 있지 않으면, false를 반환한다.
  3. bodycall을 most closely contain하는 FunctionBody, ConciseBody 또는 AsyncConciseBody로 둔다.
  4. bodyGeneratorBodyFunctionBody이면, false를 반환한다.
  5. bodyAsyncFunctionBodyFunctionBody이면, false를 반환한다.
  6. bodyAsyncGeneratorBodyFunctionBody이면, false를 반환한다.
  7. bodyAsyncConciseBody이면, false를 반환한다.
  8. argument call를 가진 bodyHasCallInTailPosition의 result를 반환한다.
Note

Tail Position call은 caller context의 chain을 observation할 수 있게 하는 common non-standard language extension(10.2.4 참조) 때문에 strict mode code에서만 defined됩니다.

15.10.2 Static Semantics: HasCallInTailPosition

The syntax-directed operation HasCallInTailPosition takes argument call (a CallExpression Parse Node, a MemberExpression Parse Node, or an OptionalChain Parse Node) and returns a Boolean.

Note 1

call은 소스 텍스트의 특정 범위를 나타내는 Parse Node이다. 다음 알고리즘들이 call을 다른 Parse Node와 비교할 때, 이는 그것들이 동일한 소스 텍스트를 나타내는지에 대한 검사이다.

Note 2

호출 결과의 GetValue를 반환하는 것이 바로 뒤따르는 잠재적 꼬리 위치 호출도 가능한 꼬리 위치 호출이다. 함수 호출은 Reference Record를 반환할 수 없으므로, 이러한 GetValue 연산은 항상 실제 함수 호출 결과와 동일한 값을 반환한다.

Note 3

같은 Block, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody, AsyncGeneratorBody, AsyncFunctionBody 또는 ClassStaticBlockBody 안에서 호출 앞에 오는 using 선언 또는 await using 선언은 그 호출이 가능한 꼬리 위치 호출이 되는 것을 방지한다.

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. has를 인수 call로 파생된 StatementListHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. 파생된 StatementListContainsUsingtrue이면, false를 반환한다.
  4. 인수 callStatementListItemHasCallInTailPosition을 반환한다.
FunctionStatementList : [empty] StatementListItem : Declaration Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement BreakStatement ThrowStatement DebuggerStatement Block : { } ReturnStatement : return ; LabelledItem : FunctionDeclaration ForInOfStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement CaseBlock : { }
  1. false를 반환한다.
IfStatement : if ( Expression ) Statement else Statement
  1. has를 argument call를 가진 first StatementHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. argument call를 가진 second StatementHasCallInTailPosition을 반환한다.
IfStatement : if ( Expression ) Statement DoWhileStatement : do Statement while ( Expression ) ; WhileStatement : while ( Expression ) Statement ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement WithStatement : with ( Expression ) Statement
  1. argument call를 가진 StatementHasCallInTailPosition을 반환한다.
LabelledStatement : LabelIdentifier : LabelledItem
  1. argument call를 가진 LabelledItemHasCallInTailPosition을 반환한다.
ReturnStatement : return Expression ;
  1. argument call를 가진 ExpressionHasCallInTailPosition을 반환한다.
SwitchStatement : switch ( Expression ) CaseBlock
  1. argument call를 가진 CaseBlockHasCallInTailPosition을 반환한다.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalse로 둔다.
  2. first CaseClauses가 present하면, has를 argument call를 가진 first CaseClausesHasCallInTailPosition으로 설정한다.
  3. hastrue이면, true를 반환한다.
  4. has를 argument call를 가진 DefaultClauseHasCallInTailPosition으로 설정한다.
  5. hastrue이면, true를 반환한다.
  6. second CaseClauses가 present하면, has를 argument call를 가진 second CaseClausesHasCallInTailPosition으로 설정한다.
  7. has를 반환한다.
CaseClauses : CaseClauses CaseClause
  1. has를 argument call를 가진 CaseClausesHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. argument call를 가진 CaseClauseHasCallInTailPosition을 반환한다.
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList가 present하면, argument call를 가진 StatementListHasCallInTailPosition을 반환한다.
  2. false를 반환한다.
TryStatement : try Block Catch
  1. argument call를 가진 CatchHasCallInTailPosition을 반환한다.
TryStatement : try Block Finally try Block Catch Finally
  1. argument call를 가진 FinallyHasCallInTailPosition을 반환한다.
Catch : catch ( CatchParameter ) Block
  1. argument call를 가진 BlockHasCallInTailPosition을 반환한다.
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 PrivateIdentifier 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 CoverAwaitExpressionAndAwaitUsingDeclarationHead CallExpression : SuperCall ImportCall 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. false를 반환한다.
Expression : AssignmentExpression Expression , AssignmentExpression
  1. argument call를 가진 AssignmentExpressionHasCallInTailPosition을 반환한다.
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has를 argument call를 가진 first AssignmentExpressionHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. argument call를 가진 second AssignmentExpressionHasCallInTailPosition을 반환한다.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. argument call를 가진 BitwiseORExpressionHasCallInTailPosition을 반환한다.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. argument call를 가진 LogicalANDExpressionHasCallInTailPosition을 반환한다.
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. argument call를 가진 BitwiseORExpressionHasCallInTailPosition을 반환한다.
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. this CallExpressioncall이면, true를 반환한다.
  2. false를 반환한다.
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. argument call를 가진 OptionalChainHasCallInTailPosition을 반환한다.
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. false를 반환한다.
OptionalChain : ?. Arguments OptionalChain Arguments
  1. this OptionalChaincall이면, true를 반환한다.
  2. false를 반환한다.
MemberExpression : MemberExpression TemplateLiteral
  1. this MemberExpressioncall이면, true를 반환한다.
  2. false를 반환한다.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. exprCoverParenthesizedExpressionAndArrowParameterListcovered하는 ParenthesizedExpression으로 둔다.
  2. argument call를 가진 exprHasCallInTailPosition을 반환한다.
ParenthesizedExpression : ( Expression )
  1. argument call를 가진 ExpressionHasCallInTailPosition을 반환한다.

15.10.3 PrepareForTailCall ( )

The abstract operation PrepareForTailCall takes no arguments and returns unused. It performs the following steps when called:

  1. Assert: current execution context는 이후 어떤 ECMAScript code 또는 built-in function의 evaluation에도 사용되지 않는다. 이 abstract operation의 invocation 이후 Call의 invocation은 그러한 evaluation을 수행하기 전에 new execution context를 create하고 push할 것이다.
  2. current execution context와 associated된 모든 resource를 discard한다.
  3. unused를 반환한다.

tail position call은 target function을 invoking하기 전에 currently executing function execution context와 associated된 모든 transient internal resource를 release하거나, target function을 support하기 위해 그러한 resource를 reuse해야 합니다.

Note

예를 들어, tail position call은 target function의 activation record size가 calling function의 activation record size를 초과하는 amount만큼만 implementation의 activation record stack을 grow해야 합니다. target function의 activation record가 더 작으면, stack의 total size는 decrease해야 합니다.