15 ECMAScript 언어: 함수와 클래스

Note

다양한 ECMAScript 언어 요소는 ECMAScript 함수 객체의 생성을 유발한다 (10.2). 이러한 함수의 평가는 해당 [[Call]] 내부 메서드의 실행으로 시작된다 (10.2.1).

15.1 매개변수 목록

구문

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: 조기 오류

UniqueFormalParameters : FormalParameters FormalParameters : FormalParameterList Note

FormalParameterList에서 동일한 BindingIdentifier가 여러 번 나타나는 것은 단순 매개변수 목록을 가지며 엄격 모드 코드에서 정의되지 않은 함수에 대해서만 허용된다.

15.1.2 Static Semantics: ContainsExpression

The syntax-directed operation ContainsExpression takes no arguments and returns 불리언. 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. formalsCoverParenthesizedExpressionAndArrowParameterList가 포함하는 ArrowFormalParameters로 설정한다.
  2. formalsContainsExpression을 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false를 반환한다.

15.1.3 Static Semantics: IsSimpleParameterList

The syntax-directed operation IsSimpleParameterList takes no arguments and returns 불리언. 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. formalsCoverParenthesizedExpressionAndArrowParameterList가 포함하는 ArrowFormalParameters로 설정한다.
  2. formalsIsSimpleParameterList를 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true를 반환한다.
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHead가 포함하는 AsyncArrowHead로 설정한다.
  2. headIsSimpleParameterList를 반환한다.

15.1.4 Static Semantics: HasInitializer

The syntax-directed operation HasInitializer takes no arguments and returns 불리언. 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 음이 아닌 정수. It is defined piecewise over the following productions:

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

FormalParameterList의 ExpectedArgumentCount는 rest 매개변수 또는 Initializer를 가진 첫 번째 FormalParameter의 왼쪽에 있는 FormalParameters의 개수이다. Initializer가 없는 FormalParameter는 Initializer가 있는 첫 번째 매개변수 이후에도 허용되지만, 이러한 매개변수는 기본값으로 undefined를 가지는 선택적 매개변수로 간주된다.

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. formalsCoverParenthesizedExpressionAndArrowParameterList가 포함하는 ArrowFormalParameters로 설정한다.
  2. formalsExpectedArgumentCount를 반환한다.
PropertySetParameterList : FormalParameter
  1. FormalParameterHasInitializertrue이면, 0을 반환한다.
  2. 1을 반환한다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. 1을 반환한다.

15.2 함수 정의

구문

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: 조기 오류

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

FunctionBodyLexicallyDeclaredNames에는 var 또는 함수 선언을 사용하여 바인딩된 식별자가 포함되지 않는다.

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

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

FunctionBody : FunctionStatementList
  1. FunctionBody의 지시어 서두가 Use Strict 지시어를 포함하면 true를 반환한다.
  2. false를 반환한다.

15.2.3 Runtime Semantics: EvaluateFunctionBody

The syntax-directed operation EvaluateFunctionBody takes arguments functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값의 리스트) and returns return 완료 또는 throw 완료. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(functionObject, argumentsList)를 수행한다.
  2. FunctionStatementList의 ? Evaluation을 수행한다.
  3. NOTE: 이전 단계가 정상 완료로 이어졌다면, 평가는 FunctionStatementList의 끝을 지나 진행하여 종료된 것이다.
  4. ReturnCompletion(undefined)을 반환한다.

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

The syntax-directed operation InstantiateOrdinaryFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record 또는 null) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextFunctionDeclaration에 의해 매치된 소스 텍스트로 둔다.
  3. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. MakeConstructor(closure)를 수행한다.
  6. closure를 반환한다.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceTextFunctionDeclaration에 의해 매치된 소스 텍스트로 둔다.
  2. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. MakeConstructor(closure)를 수행한다.
  5. closure를 반환한다.
Note

익명 FunctionDeclarationexport default 선언의 일부로만 나타날 수 있으므로, 그 함수 코드는 항상 엄격 모드 코드이다.

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

The syntax-directed operation InstantiateOrdinaryFunctionExpression takes optional argument name (프로퍼티 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name이 존재하지 않으면, name을 빈 문자열로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextFunctionExpression에 의해 매치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. MakeConstructor(closure)를 수행한다.
  8. closure를 반환한다.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Assert: name은 존재하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  7. sourceTextFunctionExpression에 의해 매치된 소스 텍스트로 둔다.
  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는 함수가 자기 자신을 재귀적으로 호출할 수 있도록 FunctionExpressionFunctionBody 내부에서 참조될 수 있다. 그러나 FunctionDeclaration에서와 달리, FunctionExpression 안의 BindingIdentifierFunctionExpression을 둘러싼 스코프에서 참조될 수 없으며 그 스코프에 영향을 주지 않는다.

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을 사용하여 정의된 모든 함수에는, 그 함수가 생성자로 사용될 가능성을 허용하기 위해 "prototype" 프로퍼티가 자동으로 생성된다.

FunctionStatementList : [empty]
  1. undefined를 반환한다.

15.3 화살표 함수 정의

구문

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]

보충 구문

다음 생성식의 인스턴스를 처리할 때
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
CoverParenthesizedExpressionAndArrowParameterList의 해석은 다음 문법을 사용하여 정제된다:

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

15.3.1 Static Semantics: 조기 오류

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 Static Semantics: ConciseBodyContainsUseStrict

The syntax-directed operation ConciseBodyContainsUseStrict takes no arguments and returns 불리언. 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 functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값들의 List) and returns 반환 완료 또는 던짐 완료. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. FunctionDeclarationInstantiation(functionObject, argumentsList)를 수행한다.
  2. ExpressionBody의 ? Evaluation을 반환한다.

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

The syntax-directed operation InstantiateArrowFunctionExpression takes optional argument name (속성 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextArrowFunction에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, env, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. closure를 반환한다.
Note

ArrowFunctionarguments, super, this, 또는 new.target에 대한 로컬 바인딩을 정의하지 않는다. ArrowFunction 내에서 arguments, super, this, 또는 new.target에 대한 모든 참조는 렉시컬하게 둘러싸는 환경의 바인딩으로 해석되어야 한다. 일반적으로 이는 바로 둘러싸는 함수의 Function Environment가 된다. ArrowFunctionsuper에 대한 참조를 포함할 수 있더라도, 단계 5에서 생성된 함수 객체는 MakeMethod를 수행하여 메서드로 만들어지지 않는다. super를 참조하는 ArrowFunction은 항상 비-ArrowFunction 내에 포함되며, super를 구현하는 데 필요한 상태는 ArrowFunction의 함수 객체가 캡처한 env를 통해 접근할 수 있다.

15.3.5 Runtime Semantics: Evaluation

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

15.4 메서드 정의

구문

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: 조기 오류

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 불리언. 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 불리언. 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 object (객체) and optional argument functionPrototype (객체) and returns [[Key]](속성 키) 및 [[Closure]](ECMAScript 함수 객체) 필드를 가진 Record를 포함하는 정상 완료 또는 갑작스러운 완료. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. functionPrototype이 존재하면,
    1. prototypefunctionPrototype으로 둔다.
  5. 그렇지 않으면,
    1. prototype%Function.prototype%으로 둔다.
  6. sourceTextMethodDefinition에 의해 일치된 소스 텍스트로 둔다.
  7. closureOrdinaryFunctionCreate(prototype, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  8. MakeMethod(closure, object)를 수행한다.
  9. Record { [[Key]]: propertyKey, [[Closure]]: closure }를 반환한다.

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

The syntax-directed operation MethodDefinitionEvaluation takes arguments object (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를 인수 object와 함께 MethodDefinition의 ? DefineMethod로 둔다.
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]])을 수행한다.
  3. DefineMethodProperty(object, methodDef.[[Key]], methodDef.[[Closure]], enumerable)를 반환한다.
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextMethodDefinition에 의해 일치된 소스 텍스트로 둔다.
  5. formalParameterList를 생성식 FormalParameters : [empty] 의 인스턴스로 둔다.
  6. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  7. MakeMethod(closure, object)를 수행한다.
  8. SetFunctionName(closure, propertyKey, "get")을 수행한다.
  9. propertyKeyPrivate Name이면,
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined }를 반환한다.
  10. desc를 PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둔다.
  11. DefinePropertyOrThrow(object, propertyKey, desc)를 수행한다.
  12. unused를 반환한다.
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextMethodDefinition에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  6. MakeMethod(closure, object)를 수행한다.
  7. SetFunctionName(closure, propertyKey, "set")을 수행한다.
  8. propertyKeyPrivate Name이면,
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure }를 반환한다.
  9. desc를 PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둔다.
  10. DefinePropertyOrThrow(object, propertyKey, desc)를 수행한다.
  11. unused를 반환한다.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextGeneratorMethod에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  6. MakeMethod(closure, object)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  10. DefineMethodProperty(object, propertyKey, closure, enumerable)를 반환한다.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncGeneratorMethod에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  6. MakeMethod(closure, object)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  10. DefineMethodProperty(object, propertyKey, closure, enumerable)를 반환한다.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKeyClassElementName의 ? Evaluation으로 둔다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncMethod에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  6. MakeMethod(closure, object)를 수행한다.
  7. SetFunctionName(closure, propertyKey)을 수행한다.
  8. DefineMethodProperty(object, propertyKey, closure, enumerable)를 반환한다.

15.5 제너레이터 함수 정의

구문

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 바로 뒤의 구문 컨텍스트는 InputElementRegExpOrTemplateTail 렉시컬 목표의 사용을 요구한다.

Note 2

YieldExpression은 제너레이터 함수의 FormalParameters 내에서 사용할 수 없다. FormalParameters의 일부인 모든 표현식은 결과 Generator가 재개 가능한 상태가 되기 전에 평가되기 때문이다.

Note 3

Generators와 관련된 추상 연산27.5.3에 정의되어 있다.

15.5.1 Static Semantics: 조기 오류

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 functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값들의 List) and returns 던짐 완료 또는 반환 완료. It is defined piecewise over the following productions:

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

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

The syntax-directed operation InstantiateGeneratorFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record 또는 null) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextGeneratorDeclaration에 의해 일치된 소스 텍스트로 둔다.
  3. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. closure를 반환한다.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceTextGeneratorDeclaration에 의해 일치된 소스 텍스트로 둔다.
  2. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  6. closure를 반환한다.
Note

익명 GeneratorDeclarationexport default 선언의 일부로만 나타날 수 있으며, 따라서 그 함수 코드는 항상 엄격 모드 코드이다.

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

The syntax-directed operation InstantiateGeneratorFunctionExpression takes optional argument name (속성 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextGeneratorExpression에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  9. closure를 반환한다.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Assert: name은 존재하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  7. sourceTextGeneratorExpression에 의해 일치된 소스 텍스트로 둔다.
  8. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. prototypeOrdinaryObjectCreate(%GeneratorPrototype%)로 둔다.
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  12. funcEnv.InitializeBinding(name, closure)를 수행한다.
  13. closure를 반환한다.
Note

GeneratorExpressionBindingIdentifierGeneratorExpressionFunctionBody 내부에서 참조될 수 있어 제너레이터 코드가 자신을 재귀적으로 호출할 수 있게 한다. 그러나 GeneratorDeclaration에서와 달리, GeneratorExpressionBindingIdentifierGeneratorExpression을 둘러싸는 스코프에서 참조될 수 없고 그 스코프에 영향을 주지 않는다.

15.5.5 Runtime Semantics: Evaluation

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpressionInstantiateGeneratorFunctionExpression을 반환한다.
YieldExpression : yield
  1. Yield(undefined)를 반환한다.
YieldExpression : yield AssignmentExpression
  1. exprRefAssignmentExpression의 ? Evaluation으로 둔다.
  2. value를 ? GetValue(exprRef)로 둔다.
  3. Yield(value)를 반환한다.
YieldExpression : yield * AssignmentExpression
  1. generatorKindGetGeneratorKind()로 둔다.
  2. Assert: generatorKindsync 또는 async이다.
  3. exprRefAssignmentExpression의 ? Evaluation으로 둔다.
  4. value를 ? GetValue(exprRef)로 둔다.
  5. iteratorRecord를 ? GetIterator(value, generatorKind)로 둔다.
  6. iteratoriteratorRecord.[[Iterator]]로 둔다.
  7. receivedNormalCompletion(undefined)로 둔다.
  8. 반복한다,
    1. received가 정상 완료이면,
      1. innerResult를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »)로 둔다.
      2. generatorKindasync이면, innerResult를 ? Await(innerResult)로 설정한다.
      3. innerResult가 객체가 아니면, TypeError 예외를 던진다.
      4. done을 ? IteratorComplete(innerResult)로 둔다.
      5. donetrue이면,
        1. IteratorValue(innerResult)를 반환한다.
      6. generatorKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))로 설정한다.
      7. 그렇지 않으면, receivedCompletion(GeneratorYield(innerResult))로 설정한다.
    2. 그렇지 않고 received가 던짐 완료이면,
      1. throw를 ? GetMethod(iterator, "throw")로 둔다.
      2. throwundefined가 아니면,
        1. innerResult를 ? Call(throw, iterator, « received.[[Value]] »)로 둔다.
        2. generatorKindasync이면, innerResult를 ? Await(innerResult)로 설정한다.
        3. NOTE: 내부 반복자의 throw 메서드에서 발생한 예외는 전파된다. 내부 throw 메서드의 정상 완료는 내부 next와 유사하게 처리된다.
        4. innerResult가 객체가 아니면, TypeError 예외를 던진다.
        5. done을 ? IteratorComplete(innerResult)로 둔다.
        6. donetrue이면,
          1. IteratorValue(innerResult)를 반환한다.
        7. generatorKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))로 설정한다.
        8. 그렇지 않으면, receivedCompletion(GeneratorYield(innerResult))로 설정한다.
      3. 그렇지 않으면,
        1. NOTE: iteratorthrow 메서드가 없으면, 이 throw는 yield* 루프를 종료하게 된다. 그러나 먼저 iterator에게 정리할 기회를 제공해야 한다.
        2. closeCompletionNormalCompletion(empty)으로 둔다.
        3. generatorKindasync이면, ? AsyncIteratorClose(iteratorRecord, closeCompletion)를 수행한다.
        4. 그렇지 않으면, ? IteratorClose(iteratorRecord, closeCompletion)를 수행한다.
        5. NOTE: 다음 단계는 iteratorthrow 메서드가 없다는 yield* 프로토콜 위반을 나타내기 위해 TypeError를 던진다.
        6. TypeError 예외를 던진다.
    3. 그렇지 않으면,
      1. Assert: received는 반환 완료이다.
      2. return을 ? GetMethod(iterator, "return")로 둔다.
      3. returnundefined이면,
        1. receivedValuereceived.[[Value]]로 둔다.
        2. generatorKindasync이면,
          1. receivedValue를 ? Await(receivedValue)로 설정한다.
        3. ReturnCompletion(receivedValue)를 반환한다.
      4. innerReturnResult를 ? Call(return, iterator, « received.[[Value]] »)로 둔다.
      5. generatorKindasync이면, innerReturnResult를 ? Await(innerReturnResult)로 설정한다.
      6. innerReturnResult가 객체가 아니면, TypeError 예외를 던진다.
      7. done을 ? IteratorComplete(innerReturnResult)로 둔다.
      8. donetrue이면,
        1. returnedValue를 ? IteratorValue(innerReturnResult)로 둔다.
        2. ReturnCompletion(returnedValue)를 반환한다.
      9. generatorKindasync이면, receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerReturnResult)))로 설정한다.
      10. 그렇지 않으면, receivedCompletion(GeneratorYield(innerReturnResult))로 설정한다.

15.6 비동기 제너레이터 함수 정의

구문

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은 비동기 제너레이터 함수의 FormalParameters 내에서 사용할 수 없다. FormalParameters의 일부인 모든 표현식은 결과 AsyncGenerator가 재개 가능한 상태가 되기 전에 평가되기 때문이다.

Note 2

AsyncGenerators와 관련된 추상 연산27.6.3에 정의되어 있다.

15.6.1 Static Semantics: 조기 오류

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 functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값들의 List) and returns 던짐 완료 또는 반환 완료. It is defined piecewise over the following productions:

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

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

The syntax-directed operation InstantiateAsyncGeneratorFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record 또는 null) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextAsyncGeneratorDeclaration에 의해 일치된 소스 텍스트로 둔다.
  3. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. closure를 반환한다.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceTextAsyncGeneratorDeclaration에 의해 일치된 소스 텍스트로 둔다.
  2. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  6. closure를 반환한다.
Note

익명 AsyncGeneratorDeclarationexport default 선언의 일부로만 나타날 수 있다.

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

The syntax-directed operation InstantiateAsyncGeneratorFunctionExpression takes optional argument name (속성 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncGeneratorExpression에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  9. closure를 반환한다.
AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. Assert: name은 존재하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  7. sourceTextAsyncGeneratorExpression에 의해 일치된 소스 텍스트로 둔다.
  8. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둔다.
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  12. funcEnv.InitializeBinding(name, closure)를 수행한다.
  13. closure를 반환한다.
Note

AsyncGeneratorExpressionBindingIdentifierAsyncGeneratorExpressionAsyncGeneratorBody 내부에서 참조될 수 있어 제너레이터 코드가 자신을 재귀적으로 호출할 수 있게 한다. 그러나 AsyncGeneratorDeclaration에서와 달리, AsyncGeneratorExpressionBindingIdentifierAsyncGeneratorExpression을 둘러싸는 스코프에서 참조될 수 없고 그 스코프에 영향을 주지 않는다.

15.6.5 Runtime Semantics: Evaluation

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

15.7 클래스 정의

구문

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

클래스 정의는 항상 엄격 모드 코드이다.

15.7.1 Static Semantics: 조기 오류

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList
  • ClassElementListPrototypePropertyNameList"constructor"를 두 번 이상 포함하면 구문 오류이다.
  • ClassElementListPrivateBoundIdentifiers에 중복 항목이 있으면 구문 오류이다. 단, 이름이 getter에 한 번, setter에 한 번만 사용되고 다른 항목에는 사용되지 않으며, getter와 setter가 둘 다 정적이거나 둘 다 비정적인 경우는 예외이다.
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 ClassElement 파스 노드 또는 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

조기 오류 규칙"constructor"라는 이름의 메서드 정의가 하나만 존재하고 그것이 접근자 속성이나 제너레이터 정의가 아님을 보장한다.

15.7.4 Static Semantics: IsStatic

The syntax-directed operation IsStatic takes no arguments and returns 불리언. 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 ClassElement 파스 노드들의 List. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElementClassElementKindnon-constructor-method이면,
    1. « ClassElement »를 반환한다.
  2. 새로운 빈 List를 반환한다.
ClassElementList : ClassElementList ClassElement
  1. listClassElementListNonConstructorElements로 둔다.
  2. ClassElementClassElementKindnon-constructor-method이면,
    1. ClassElementlist에 추가한다.
  3. list를 반환한다.

15.7.6 Static Semantics: PrototypePropertyNameList

The syntax-directed operation PrototypePropertyNameList takes no arguments and returns 속성 키들의 List. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. propNameClassElementPropName으로 둔다.
  2. propNameempty이면, 새로운 빈 List를 반환한다.
  3. ClassElementIsStatictrue이면, 새로운 빈 List를 반환한다.
  4. « propName »을 반환한다.
ClassElementList : ClassElementList ClassElement
  1. listClassElementListPrototypePropertyNameList로 둔다.
  2. propNameClassElementPropName으로 둔다.
  3. propNameempty이면, list를 반환한다.
  4. ClassElementIsStatictrue이면, list를 반환한다.
  5. list와 « propName »의 list-concatenation을 반환한다.

15.7.7 Static Semantics: AllPrivateIdentifiersValid

The syntax-directed operation AllPrivateIdentifiersValid takes argument names (String들의 List) and returns 불리언.

이 명세에서 아래에 나열되지 않은 모든 문법 생성식 대안은 암시적으로 AllPrivateIdentifiersValid에 대해 다음 기본 정의를 가진다:

  1. 파스 노드의 각 자식 노드 child에 대해, 다음을 수행한다
    1. child가 비단말의 인스턴스이면,
      1. 인수 names와 함께 childAllPrivateIdentifiersValidfalse이면, false를 반환한다.
  2. true를 반환한다.
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 포함하면,
    1. 인수 names와 함께 MemberExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 포함하면,
    1. 인수 names와 함께 CallExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 포함하면, true를 반환한다.
  2. false를 반환한다.
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifierStringValue를 포함하면,
    1. 인수 names와 함께 OptionalChainAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.
ClassBody : ClassElementList
  1. newNamesnamesClassBodyPrivateBoundIdentifierslist-concatenation으로 둔다.
  2. 인수 newNames와 함께 ClassElementListAllPrivateIdentifiersValid를 반환한다.
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifierStringValue를 포함하면,
    1. 인수 names와 함께 ShiftExpressionAllPrivateIdentifiersValid를 반환한다.
  2. false를 반환한다.

15.7.8 Static Semantics: PrivateBoundIdentifiers

The syntax-directed operation PrivateBoundIdentifiers takes no arguments and returns String들의 List. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementNamePrivateBoundIdentifiers를 반환한다.
ClassElementName : PrivateIdentifier
  1. 유일한 원소가 PrivateIdentifierStringValueList를 반환한다.
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 새로운 빈 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 불리언.

이 명세에서 아래에 나열되지 않은 모든 문법 생성식 대안은 암시적으로 ContainsArguments에 대해 다음 기본 정의를 가진다:

  1. 파스 노드의 각 자식 노드 child에 대해, 다음을 수행한다
    1. child가 비단말의 인스턴스이면,
      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 homeObject (객체) and returns ClassFieldDefinition Record를 포함하는 정상 완료 또는 갑작스러운 완료. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. nameClassElementName의 ? Evaluation으로 둔다.
  2. Initializer가 존재하면,
    1. formalParameterList를 생성식 FormalParameters : [empty] 의 인스턴스로 둔다.
    2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
    3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
    4. sourceText를 빈 유니코드 코드 포인트 시퀀스로 둔다.
    5. initializerOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, Initializer, non-lexical-this, env, privateEnv)로 둔다.
    6. MakeMethod(initializer, homeObject)를 수행한다.
    7. initializer.[[ClassFieldInitializerName]]name으로 설정한다.
  3. 그렇지 않으면,
    1. initializerempty로 둔다.
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer }를 반환한다.
Note
initializer를 위해 생성된 함수는 ECMAScript 코드에서 직접 접근할 수 없다.

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

The syntax-directed operation ClassStaticBlockDefinitionEvaluation takes argument homeObject (객체) and returns ClassStaticBlockDefinition Record. It is defined piecewise over the following productions:

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lex를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  2. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  3. sourceText를 빈 유니코드 코드 포인트 시퀀스로 둔다.
  4. formalParameters를 생성식 FormalParameters : [empty] 의 인스턴스로 둔다.
  5. bodyFunctionOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameters, ClassStaticBlockBody, non-lexical-this, lex, privateEnv)로 둔다.
  6. MakeMethod(bodyFunction, homeObject)를 수행한다.
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunction }를 반환한다.
Note
함수 bodyFunction은 ECMAScript 코드에서 직접 접근할 수 없다.

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

The syntax-directed operation EvaluateClassStaticBlockBody takes argument functionObject (ECMAScript 함수 객체) and returns 반환 완료 또는 던짐 완료. It is defined piecewise over the following productions:

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Assert: functionObjectClassStaticBlockDefinitionEvaluation 단계 5에서 생성된 합성 함수이다.
  2. FunctionDeclarationInstantiation(functionObject, « »)를 수행한다.
  3. ClassStaticBlockStatementList의 ? Evaluation을 수행한다.
  4. ReturnCompletion(undefined)를 반환한다.

15.7.13 Runtime Semantics: ClassElementEvaluation

The syntax-directed operation ClassElementEvaluation takes argument object (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. 인수 object와 함께 FieldDefinition의 ? ClassFieldDefinitionEvaluation을 반환한다.
ClassElement : MethodDefinition static MethodDefinition
  1. 인수 objectfalse와 함께 MethodDefinition의 ? MethodDefinitionEvaluation을 반환한다.
ClassElement : ClassStaticBlock
  1. 인수 object와 함께 ClassStaticBlockClassStaticBlockDefinitionEvaluation을 반환한다.
ClassElement : ;
  1. unused를 반환한다.

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

The syntax-directed operation ClassDefinitionEvaluation takes arguments classBinding (String 또는 undefined), className (속성 키 또는 Private Name), and sourceText (ECMAScript 소스 텍스트) and returns 함수 객체를 포함하는 정상 완료 또는 갑작스러운 완료.

Note

명세의 편의를 위해 private 메서드와 접근자는 클래스 인스턴스의 [[PrivateElements]] 슬롯에서 private 필드와 함께 포함된다. 그러나 주어진 객체는 주어진 클래스가 정의한 private 메서드와 접근자를 모두 가지거나 전혀 가지지 않는다. 이 기능은 구현체가 각 메서드나 접근자를 개별적으로 추적할 필요가 없는 전략을 사용하여 private 메서드와 접근자를 구현할 수 있도록 설계되었다.

예를 들어, 구현체는 인스턴스 private 메서드를 해당 Private Name과 직접 연결하고, 각 객체에 대해 어떤 클래스 생성자가 그 객체를 this 값으로 하여 실행되었는지를 추적할 수 있다. 그러면 객체에서 인스턴스 private 메서드를 조회하는 것은 그 메서드를 정의한 클래스 생성자가 해당 객체를 초기화하는 데 사용되었는지 확인한 뒤, Private Name과 연결된 메서드를 반환하는 것으로 이루어진다.

이는 private 필드와 다르다. 필드 초기자는 클래스 인스턴스화 중에 던질 수 있으므로, 개별 객체는 주어진 클래스의 private 필드 중 적절한 부분집합만 가질 수 있으며, 따라서 private 필드는 일반적으로 개별적으로 추적되어야 한다.

It is defined piecewise over the following productions:

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment라고 하자.
  2. classEnvNewDeclarativeEnvironment(env)라고 하자.
  3. classBindingundefined가 아니면,
    1. classEnv.CreateImmutableBinding(classBinding, true)를 수행한다.
  4. outerPrivateEnvironment를 실행 중인 실행 컨텍스트의 PrivateEnvironment라고 하자.
  5. classPrivateEnvironmentNewPrivateEnvironment(outerPrivateEnvironment)라고 하자.
  6. ClassBody가 존재하면,
    1. ClassBodyPrivateBoundIdentifiers의 각 String dn에 대해,
      1. classPrivateEnvironment.[[Names]]pn.[[Description]]dnPrivate Name pn을 포함하면,
        1. Assert: 이는 getter/setter 쌍에 대해서만 가능하다.
      2. 그렇지 않으면,
        1. name[[Description]]dn인 새로운 Private Name이라고 하자.
        2. nameclassPrivateEnvironment.[[Names]]에 추가한다.
  7. ClassHeritage가 존재하지 않으면,
    1. protoParent%Object.prototype%이라고 하자.
    2. constructorParent%Function.prototype%이라고 하자.
  8. 그렇지 않으면,
    1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정한다.
    2. NOTE: ClassHeritage를 평가할 때 실행 중인 실행 컨텍스트의 PrivateEnvironment는 outerPrivateEnvironment이다.
    3. superclassRefClassHeritage 평가의 Completion이라고 하자.
    4. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 env로 설정한다.
    5. superclass를 ? GetValue(? superclassRef)라고 하자.
    6. superclassnull이면,
      1. protoParentnull이라고 하자.
      2. constructorParent%Function.prototype%이라고 하자.
    7. 아니고 IsConstructor(superclass)가 false이면,
      1. TypeError 예외를 던진다.
    8. 그렇지 않으면,
      1. protoParent를 ? Get(superclass, "prototype")라고 하자.
      2. protoParent가 Object가 아니고 null도 아니면, TypeError 예외를 던진다.
      3. constructorParentsuperclass라고 하자.
  9. protoOrdinaryObjectCreate(protoParent)라고 하자.
  10. ClassBody가 존재하지 않으면, constructorempty라고 하자.
  11. 그렇지 않으면, constructorClassBodyConstructorMethod라고 하자.
  12. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정한다.
  13. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 classPrivateEnvironment로 설정한다.
  14. constructorempty이면,
    1. defaultConstructor를, 매개변수가 없고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 수행하는 새로운 Abstract Closure라고 하자:
      1. args[[Call]] 또는 [[Construct]]에 의해 이 함수에 전달된 인수들의 List라고 하자.
      2. NewTarget이 undefined이면, TypeError 예외를 던진다.
      3. constructorFunction을 활성 함수 객체라고 하자.
      4. constructorFunction.[[ConstructorKind]]derived이면,
        1. NOTE: 이 분기는 constructor(...args) { super(...args); }와 유사하게 동작한다. 가장 주목할 만한 차이점은, 앞서 언급한 ECMAScript 소스 텍스트%Array.prototype%%Symbol.iterator% 메서드를 관찰 가능하게 호출하지만, 이 함수는 그렇게 하지 않는다는 점이다.
        2. func를 ! constructorFunction.[[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, constructorFunction)를 수행한다.
      7. NormalCompletion(result)을 반환한다.
    2. constructorFunctionCreateBuiltinFunction(defaultConstructor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », the current Realm Record, constructorParent)라고 하자.
  15. 그렇지 않으면,
    1. constructorInfoprotoconstructorParent를 인수로 한 constructor의 ! DefineMethod라고 하자.
    2. constructorFunctionconstructorInfo.[[Closure]]라고 하자.
    3. MakeClassConstructor(constructorFunction)를 수행한다.
    4. SetFunctionName(constructorFunction, className)을 수행한다.
  16. constructorFunction.[[SourceText]]sourceText로 설정한다.
  17. MakeConstructor(constructorFunction, false, proto)를 수행한다.
  18. ClassHeritage가 존재하면, constructorFunction.[[ConstructorKind]]derived로 설정한다.
  19. DefineMethodProperty(proto, "constructor", constructorFunction, false)를 수행한다.
  20. ClassBody가 존재하지 않으면, elements를 새로운 빈 List라고 하자.
  21. 그렇지 않으면, elementsClassBodyNonConstructorElements라고 하자.
  22. instancePrivateMethods를 새로운 빈 List라고 하자.
  23. staticPrivateMethods를 새로운 빈 List라고 하자.
  24. instanceFields를 새로운 빈 List라고 하자.
  25. staticElements를 새로운 빈 List라고 하자.
  26. elements의 각 ClassElement e에 대해,
    1. eIsStaticfalse이면,
      1. elementproto를 인수로 한 eClassElementEvaluationCompletion이라고 하자.
    2. 그렇지 않으면,
      1. elementconstructorFunction을 인수로 한 eClassElementEvaluationCompletion이라고 하자.
    3. elementabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 env로 설정한다.
      2. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
      3. element를 반환한다.
    4. element를 ! element로 설정한다.
    5. elementPrivateElement이면,
      1. Assert: element.[[Kind]]method 또는 accessor 중 하나이다.
      2. eIsStaticfalse이면, containerinstancePrivateMethods라고 하자.
      3. 그렇지 않으면, containerstaticPrivateMethods라고 하자.
      4. container[[Key]]element.[[Key]]PrivateElement pe를 포함하면,
        1. Assert: element.[[Kind]]pe.[[Kind]]는 모두 accessor이다.
        2. element.[[Get]]undefined이면,
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: pe.[[Get]], [[Set]]: element.[[Set]] }라고 하자.
        3. 그렇지 않으면,
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: element.[[Get]], [[Set]]: pe.[[Set]] }라고 하자.
        4. container 안의 pecombined로 교체한다.
      5. 그렇지 않으면,
        1. elementcontainer에 추가한다.
    6. 아니고 elementClassFieldDefinition Record이면,
      1. eIsStaticfalse이면, elementinstanceFields에 추가한다.
      2. 그렇지 않으면, elementstaticElements에 추가한다.
    7. 아니고 elementClassStaticBlockDefinition Record이면,
      1. elementstaticElements에 추가한다.
  27. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 env로 설정한다.
  28. classBindingundefined가 아니면,
    1. classEnv.InitializeBinding(classBinding, constructorFunction)을 수행한다.
  29. constructorFunction.[[PrivateMethods]]instancePrivateMethods로 설정한다.
  30. constructorFunction.[[Fields]]instanceFields로 설정한다.
  31. staticPrivateMethods의 각 PrivateElement method에 대해,
    1. PrivateMethodOrAccessorAdd(constructorFunction, method)를 수행한다.
  32. staticElements의 각 요소 elementRecord에 대해,
    1. elementRecordClassFieldDefinition Record이면,
      1. resultCompletion(DefineField(constructorFunction, elementRecord))라고 하자.
    2. 그렇지 않으면,
      1. Assert: elementRecordClassStaticBlockDefinition Record이다.
      2. resultCompletion(Call(elementRecord.[[BodyFunction]], constructorFunction))라고 하자.
    3. resultabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
      2. result를 반환한다.
  33. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
  34. constructorFunction을 반환한다.

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

The syntax-directed operation BindingClassDeclarationEvaluation takes no arguments and returns 함수 객체를 포함하는 정상 완료 또는 갑작스러운 완료. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue로 둔다.
  2. sourceTextClassDeclaration에 의해 일치된 소스 텍스트로 둔다.
  3. value를 인수 className, className, 및 sourceText와 함께 ClassTail의 ? ClassDefinitionEvaluation으로 둔다.
  4. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  5. InitializeBoundName(className, value, env)를 수행한다.
  6. value를 반환한다.
ClassDeclaration : class ClassTail
  1. sourceTextClassDeclaration에 의해 일치된 소스 텍스트로 둔다.
  2. 인수 undefined, "default", 및 sourceText와 함께 ClassTail의 ? ClassDefinitionEvaluation을 반환한다.
Note

ClassDeclaration : class ClassTail ExportDeclaration의 일부로만 나타나며 그 바인딩의 설정은 해당 생성식의 평가 동작 일부로 처리된다. 16.2.3.7를 보라.

15.7.16 Runtime Semantics: Evaluation

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

ClassDeclaration : class ClassTail ExportDeclaration의 일부로만 나타나며 직접 평가되지 않는다.

ClassExpression : class ClassTail
  1. sourceTextClassExpression에 의해 일치된 소스 텍스트로 둔다.
  2. 인수 undefined, 빈 String, 및 sourceText와 함께 ClassTail의 ? ClassDefinitionEvaluation을 반환한다.
ClassExpression : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue로 둔다.
  2. sourceTextClassExpression에 의해 일치된 소스 텍스트로 둔다.
  3. 인수 className, className, 및 sourceText와 함께 ClassTail의 ? ClassDefinitionEvaluation을 반환한다.
ClassElementName : PrivateIdentifier
  1. privateIdentifierPrivateIdentifierStringValue로 둔다.
  2. privateEnvRec를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  3. namesprivateEnvRec.[[Names]]로 둔다.
  4. Assert: names의 정확히 하나의 원소가 [[Description]]privateIdentifierPrivate Name이다.
  5. privateNamenames 내에서 [[Description]]privateIdentifierPrivate Name으로 둔다.
  6. privateName을 반환한다.
ClassStaticBlockStatementList : [empty]
  1. undefined를 반환한다.

15.8 비동기 함수 정의

구문

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] 매개변수가 존재할 때 awaitAwaitExpression키워드로 파싱된다. [Await] 매개변수는 다음 컨텍스트의 최상위 수준에 존재하지만, FunctionBody와 같은 비단말에 따라 일부 컨텍스트에서는 매개변수가 없을 수 있다:

Script가 구문 목표 기호일 때, [Await] 매개변수가 없으면 await는 식별자로 파싱될 수 있다. 여기에는 다음 컨텍스트가 포함된다:

Note 2

YieldExpression과 달리, AwaitExpression의 피연산자를 생략하는 것은 구문 오류이다. 반드시 무언가를 await해야 한다.

15.8.1 Static Semantics: 조기 오류

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 env (Environment Record) and privateEnv (PrivateEnvironment Record 또는 null) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifierStringValue로 둔다.
  2. sourceTextAsyncFunctionDeclaration에 의해 일치된 소스 텍스트로 둔다.
  3. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  4. SetFunctionName(closure, name)을 수행한다.
  5. closure를 반환한다.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclaration에 의해 일치된 소스 텍스트로 둔다.
  2. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  3. SetFunctionName(closure, "default")를 수행한다.
  4. closure를 반환한다.

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

The syntax-directed operation InstantiateAsyncFunctionExpression takes optional argument name (속성 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncFunctionExpression에 의해 일치된 소스 텍스트로 둔다.
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  6. SetFunctionName(closure, name)을 수행한다.
  7. closure를 반환한다.
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. Assert: name은 존재하지 않는다.
  2. nameBindingIdentifierStringValue로 설정한다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  4. funcEnvNewDeclarativeEnvironment(outerEnv)로 둔다.
  5. funcEnv.CreateImmutableBinding(name, false)를 수행한다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  7. sourceTextAsyncFunctionExpression에 의해 일치된 소스 텍스트로 둔다.
  8. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateEnv)로 둔다.
  9. SetFunctionName(closure, name)을 수행한다.
  10. funcEnv.InitializeBinding(name, closure)를 수행한다.
  11. closure를 반환한다.
Note

AsyncFunctionExpressionBindingIdentifierAsyncFunctionExpressionAsyncFunctionBody 내부에서 참조될 수 있어 함수가 자신을 재귀적으로 호출할 수 있게 한다. 그러나 FunctionDeclaration에서와 달리, AsyncFunctionExpressionBindingIdentifierAsyncFunctionExpression을 둘러싸는 스코프에서 참조될 수 없고 그 스코프에 영향을 주지 않는다.

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

The syntax-directed operation EvaluateAsyncFunctionBody takes arguments functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값들의 List) and returns 반환 완료. It is defined piecewise over the following productions:

AsyncFunctionBody : FunctionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둔다.
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList))으로 둔다.
  3. 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을 반환한다.
AwaitExpression : await UnaryExpression
  1. exprRefUnaryExpression의 ? Evaluation으로 둔다.
  2. value를 ? GetValue(exprRef)로 둔다.
  3. Await(value)를 반환한다.

15.9 비동기 화살표 함수 정의

구문

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]

보충 구문

다음 생성식의 인스턴스를 처리할 때
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
CoverCallExpressionAndAsyncArrowHead의 해석은 다음 문법을 사용하여 정제된다:

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

15.9.1 Static Semantics: 조기 오류

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

15.9.2 Static Semantics: AsyncConciseBodyContainsUseStrict

The syntax-directed operation AsyncConciseBodyContainsUseStrict takes no arguments and returns 불리언. 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 functionObject (ECMAScript 함수 객체) and argumentsList (ECMAScript 언어 값들의 List) and returns 반환 완료. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둔다.
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList))으로 둔다.
  3. 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 (속성 키 또는 Private Name) and returns ECMAScript 함수 객체. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncArrowFunction에 의해 일치된 소스 텍스트로 둔다.
  5. parametersAsyncArrowBindingIdentifier로 둔다.
  6. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, env, privateEnv)로 둔다.
  7. SetFunctionName(closure, name)을 수행한다.
  8. closure를 반환한다.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. name이 존재하지 않으면, name을 빈 String으로 설정한다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둔다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둔다.
  4. sourceTextAsyncArrowFunction에 의해 일치된 소스 텍스트로 둔다.
  5. headCoverCallExpressionAndAsyncArrowHead가 커버하는 AsyncArrowHead로 둔다.
  6. parametersheadArrowFormalParameters로 둔다.
  7. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, env, privateEnv)로 둔다.
  8. SetFunctionName(closure, name)을 수행한다.
  9. closure를 반환한다.

15.9.5 Runtime Semantics: Evaluation

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

15.10 꼬리 위치 호출

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 내에 포함되어 있지 않으면, false를 반환한다.
  3. bodycall을 가장 가깝게 포함하는 FunctionBody, ConciseBody, 또는 AsyncConciseBody로 둔다.
  4. bodyGeneratorBodyFunctionBody이면, false를 반환한다.
  5. bodyAsyncFunctionBodyFunctionBody이면, false를 반환한다.
  6. bodyAsyncGeneratorBodyFunctionBody이면, false를 반환한다.
  7. bodyAsyncConciseBody이면, false를 반환한다.
  8. 인수 call과 함께 bodyHasCallInTailPosition 결과를 반환한다.
Note

꼬리 위치 호출은 호출자 컨텍스트 체인의 관찰을 가능하게 하는 일반적인 비표준 언어 확장(10.2.4 참조) 때문에 엄격 모드 코드에서만 정의된다.

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은 특정 소스 텍스트 범위를 나타내는 파스 노드이다. 다음 알고리즘이 call을 다른 파스 노드와 비교할 때, 그것은 이들이 동일한 소스 텍스트를 나타내는지에 대한 테스트이다.

Note 2

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

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. has를 인수 call과 함께 StatementListHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. 인수 call과 함께 StatementListItemHasCallInTailPosition을 반환한다.
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를 인수 call과 함께 첫 번째 StatementHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. 인수 call과 함께 두 번째 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. 인수 call과 함께 StatementHasCallInTailPosition을 반환한다.
LabelledStatement : LabelIdentifier : LabelledItem
  1. 인수 call과 함께 LabelledItemHasCallInTailPosition을 반환한다.
ReturnStatement : return Expression ;
  1. 인수 call과 함께 ExpressionHasCallInTailPosition을 반환한다.
SwitchStatement : switch ( Expression ) CaseBlock
  1. 인수 call과 함께 CaseBlockHasCallInTailPosition을 반환한다.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalse로 둔다.
  2. 첫 번째 CaseClauses가 존재하면, has를 인수 call과 함께 첫 번째 CaseClausesHasCallInTailPosition으로 설정한다.
  3. hastrue이면, true를 반환한다.
  4. has를 인수 call과 함께 DefaultClauseHasCallInTailPosition으로 설정한다.
  5. hastrue이면, true를 반환한다.
  6. 두 번째 CaseClauses가 존재하면, has를 인수 call과 함께 두 번째 CaseClausesHasCallInTailPosition으로 설정한다.
  7. has를 반환한다.
CaseClauses : CaseClauses CaseClause
  1. has를 인수 call과 함께 CaseClausesHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. 인수 call과 함께 CaseClauseHasCallInTailPosition을 반환한다.
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList가 존재하면, 인수 call과 함께 StatementListHasCallInTailPosition을 반환한다.
  2. false를 반환한다.
TryStatement : try Block Catch
  1. 인수 call과 함께 CatchHasCallInTailPosition을 반환한다.
TryStatement : try Block Finally try Block Catch Finally
  1. 인수 call과 함께 FinallyHasCallInTailPosition을 반환한다.
Catch : catch ( CatchParameter ) Block
  1. 인수 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 AwaitExpression 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. 인수 call과 함께 AssignmentExpressionHasCallInTailPosition을 반환한다.
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has를 인수 call과 함께 첫 번째 AssignmentExpressionHasCallInTailPosition으로 둔다.
  2. hastrue이면, true를 반환한다.
  3. 인수 call과 함께 두 번째 AssignmentExpressionHasCallInTailPosition을 반환한다.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. 인수 call과 함께 BitwiseORExpressionHasCallInTailPosition을 반환한다.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. 인수 call과 함께 LogicalANDExpressionHasCallInTailPosition을 반환한다.
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. 인수 call과 함께 BitwiseORExpressionHasCallInTailPosition을 반환한다.
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. CallExpressioncall이면, true를 반환한다.
  2. false를 반환한다.
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. 인수 call과 함께 OptionalChainHasCallInTailPosition을 반환한다.
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. false를 반환한다.
OptionalChain : ?. Arguments OptionalChain Arguments
  1. OptionalChaincall이면, true를 반환한다.
  2. false를 반환한다.
MemberExpression : MemberExpression TemplateLiteral
  1. MemberExpressioncall이면, true를 반환한다.
  2. false를 반환한다.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. exprCoverParenthesizedExpressionAndArrowParameterList가 커버하는 ParenthesizedExpression으로 둔다.
  2. 인수 call과 함께 exprHasCallInTailPosition을 반환한다.
ParenthesizedExpression : ( Expression )
  1. 인수 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: 현재 실행 컨텍스트는 이후 어떤 ECMAScript 코드나 내장 함수의 평가에도 사용되지 않는다. 이 추상 연산 호출 이후의 Call 호출은 그러한 평가를 수행하기 전에 새 실행 컨텍스트를 생성하고 푸시한다.
  2. 현재 실행 컨텍스트와 관련된 모든 자원을 폐기한다.
  3. unused를 반환한다.

꼬리 위치 호출은 대상 함수를 호출하기 전에 현재 실행 중인 함수 실행 컨텍스트와 관련된 일시적 내부 자원을 해제하거나, 대상 함수를 지원하기 위해 그 자원을 재사용해야 한다.

Note

예를 들어, 꼬리 위치 호출은 대상 함수의 활성화 레코드 크기가 호출 함수의 활성화 레코드 크기를 초과하는 양만큼만 구현체의 활성화 레코드 스택을 증가시켜야 한다. 대상 함수의 활성화 레코드가 더 작으면, 스택의 전체 크기는 감소해야 한다.