15 ECMAScript 언어: 함수와 클래스(Functions and Classes)

Note

다양한 ECMAScript 언어 요소는 ECMAScript 함수 객체(10.2)를 생성한다. 그러한 함수들의 평가(evaluation)는 그들의 [[Call]] 내부 메서드(10.2.1) 실행으로 시작한다.

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 의 BoundNames 에 중복 요소가 있으면 Syntax Error 이다.
FormalParameters : FormalParameterList Note

같은 BindingIdentifier 의 다중 출현은 간단한(simple) 매개변수 리스트를 가지며 엄격 모드 코드에서 정의되지 않은 함수에 대해서만 허용된다.

15.1.2 정적 의미론: ContainsExpression : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ObjectBindingPattern : { } { BindingRestProperty }
  1. false 반환.
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. BindingPropertyList 의 ContainsExpression 결과 반환.
ArrayBindingPattern : [ Elisionopt ]
  1. false 반환.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. BindingRestElement 의 ContainsExpression 결과 반환.
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. BindingElementList 의 ContainsExpression 결과 반환.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. hasBindingElementList 의 ContainsExpression 결과로 둔다.
  2. hastrue 이면 true 반환.
  3. BindingRestElement 의 ContainsExpression 결과 반환.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. hasBindingPropertyList 의 ContainsExpression 결과로 둔다.
  2. hastrue 이면 true 반환.
  3. BindingProperty 의 ContainsExpression 결과 반환.
BindingElementList : BindingElementList , BindingElisionElement
  1. hasBindingElementList 의 ContainsExpression 결과로 둔다.
  2. hastrue 이면 true 반환.
  3. BindingElisionElement 의 ContainsExpression 결과 반환.
BindingElisionElement : Elisionopt BindingElement
  1. BindingElement 의 ContainsExpression 결과 반환.
BindingProperty : PropertyName : BindingElement
  1. has 를 IsComputedPropertyKey(PropertyName) 로 둔다.
  2. hastrue 이면 true 반환.
  3. BindingElement 의 ContainsExpression 결과 반환.
BindingElement : BindingPattern Initializer
  1. true 반환.
SingleNameBinding : BindingIdentifier
  1. false 반환.
SingleNameBinding : BindingIdentifier Initializer
  1. true 반환.
BindingRestElement : ... BindingIdentifier
  1. false 반환.
BindingRestElement : ... BindingPattern
  1. BindingPattern 의 ContainsExpression 결과 반환.
FormalParameters : [empty]
  1. false 반환.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterList 의 ContainsExpression 이 true 이면 true 반환.
  2. FunctionRestParameter 의 ContainsExpression 결과 반환.
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterList 의 ContainsExpression 이 true 이면 true 반환.
  2. FormalParameter 의 ContainsExpression 결과 반환.
ArrowParameters : BindingIdentifier
  1. false 반환.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList 가 커버하는 ArrowFormalParameters 로 둔다.
  2. formals 의 ContainsExpression 결과 반환.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false 반환.

15.1.3 정적 의미론: IsSimpleParameterList : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. IsSimpleParameterList(FormalParameterList) 가 false 이면 false 반환.
  2. IsSimpleParameterList(FormalParameter) 반환.
FormalParameter : BindingElement
  1. IsSimpleParameterList(BindingElement) 반환.
ArrowParameters : BindingIdentifier
  1. true 반환.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList 가 커버하는 ArrowFormalParameters 로 둔다.
  2. IsSimpleParameterList(formals) 반환.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true 반환.
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHead 가 커버하는 AsyncArrowHead 로 둔다.
  2. IsSimpleParameterList(head) 반환.

15.1.4 정적 의미론: HasInitializer : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. HasInitializer(FormalParameterList) 가 true 이면 true 반환.
  2. HasInitializer(FormalParameter) 반환.

15.1.5 정적 의미론: ExpectedArgumentCount : 음이 아닌 정수

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FormalParameters : [empty] FunctionRestParameter
  1. 0 반환.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterList 의 ExpectedArgumentCount 반환.
Note

FormalParameterList 의 ExpectedArgumentCount 는 나머지(rest) 매개변수 또는 Initializer 를 가진 첫 번째 FormalParameter 의 왼쪽에 있는 FormalParameters 의 개수이다. 초기화자가 있는 첫 매개변수 뒤에 초기화자 없는 매개변수가 올 수 있지만 그러한 매개변수들은 undefined 를 기본값으로 갖는 선택(optional) 매개변수로 간주된다.

FormalParameterList : FormalParameter
  1. HasInitializer(FormalParameter) 가 true 이면 0 반환.
  2. 1 반환.
FormalParameterList : FormalParameterList , FormalParameter
  1. countFormalParameterList 의 ExpectedArgumentCount 로 둔다.
  2. HasInitializer(FormalParameterList) 가 true 이거나 HasInitializer(FormalParameter) 가 true 이면 count 반환.
  3. count + 1 반환.
ArrowParameters : BindingIdentifier
  1. 1 반환.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList 가 커버하는 ArrowFormalParameters 로 둔다.
  2. formals 의 ExpectedArgumentCount 반환.
PropertySetParameterList : FormalParameter
  1. HasInitializer(FormalParameter) 가 true 이면 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

FunctionBody 의 LexicallyDeclaredNames 는 var 혹은 function 선언으로 바인딩된 식별자를 포함하지 않는다.

FunctionBody : FunctionStatementList

15.2.2 정적 의미론: FunctionBodyContainsUseStrict : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionBodyDirective PrologueUse Strict Directive 가 포함되어 있으면 true 반환; 그렇지 않으면 false 반환.

15.2.3 런타임 의미론: EvaluateFunctionBody : return completion 또는 throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(functionObject, argumentsList) 수행.
  2. FunctionStatementList 의 Evaluation 수행.
  3. NOTE: 이전 단계가 정상 completion 을 반환했다면 FunctionStatementList 끝을 통과하여 평가가 종료된 것이다.
  4. ReturnCompletion(undefined) 반환.

15.2.4 런타임 의미론: InstantiateOrdinaryFunctionObject : ECMAScript function object

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. nameBindingIdentifier 의 StringValue 로 둔다.
  2. sourceTextFunctionDeclaration 이 매칭한 소스 텍스트로 둔다.
  3. FOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv) 로 둔다.
  4. SetFunctionName(F, name) 수행.
  5. MakeConstructor(F) 수행.
  6. F 반환.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceTextFunctionDeclaration 이 매칭한 소스 텍스트로 둔다.
  2. FOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv) 로 둔다.
  3. SetFunctionName(F, "default") 수행.
  4. MakeConstructor(F) 수행.
  5. F 반환.
Note

익명 FunctionDeclaration 은 오직 export default 선언의 일부로만 나타날 수 있으며 그 함수 코드는 항상 strict mode 코드이다.

15.2.5 런타임 의미론: InstantiateOrdinaryFunctionExpression : ECMAScript function object

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. 단언: name 은 존재하지 않는다.
  2. nameBindingIdentifier 의 StringValue 로 둔다.
  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

FunctionExpressionBindingIdentifier 는 그 FunctionExpressionFunctionBody 내부에서 참조되어 재귀 호출을 가능하게 한다. 그러나 FunctionDeclaration 과 달리 FunctionExpressionBindingIdentifierFunctionExpression 을 둘러싼 외부 스코프에서 참조할 수 없고 영향을 주지 않는다.

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. FunctionExpression 의 InstantiateOrdinaryFunctionExpression 반환.
Note 2

FunctionDeclaration 또는 FunctionExpression 으로 정의된 모든 함수에 대해 "prototype" 프로퍼티가 자동으로 생성되어 그 함수가 생성자로 사용될 가능성을 허용한다.

FunctionStatementList : [empty]
  1. undefined 반환.

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

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

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

15.3.1 정적 의미론: 조기 오류(Static Semantics: Early Errors)

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 정적 의미론: ConciseBodyContainsUseStrict : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. false 반환.
ConciseBody : { FunctionBody }
  1. FunctionBodyContainsUseStrict(FunctionBody) 반환.

15.3.3 런타임 의미론: EvaluateConciseBody : return completion 또는 throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. FunctionDeclarationInstantiation(functionObject, argumentsList) 수행.
  2. ExpressionBody 의 Evaluation 결과를 ? 로 반환.

15.3.4 런타임 의미론: InstantiateArrowFunctionExpression : ECMAScript function object

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. name 이 존재하지 않으면 name = "".
  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 내부의 이러한 식별자 참조는 렉시컬 외부 환경의 바인딩으로 해석되어야 한다. 일반적으로 이는 바로 둘러싼 함수의 Function Environment 가 된다. 비록 ArrowFunctionsuper 를 포함할 수 있지만 단계 5 에서 생성된 함수 객체MakeMethod 를 수행하여 메서드로 만들지 않는다. super 를 참조하는 ArrowFunction 은 항상 비-ArrowFunction 안에 포함되며, super 구현에 필요한 상태는 캡처된 env 를 통해 접근 가능하다.

15.3.5 런타임 의미론: 평가(Runtime Semantics: Evaluation)

ArrowFunction : ArrowParameters => ConciseBody
  1. ArrowFunction 의 InstantiateArrowFunctionExpression 반환.
ExpressionBody : AssignmentExpression
  1. exprRefAssignmentExpression 평가 결과 (?) 로 둔다.
  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 정적 의미론: HasDirectSuper : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 정적 의미론: SpecialMethod : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 런타임 의미론: DefineMethod 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  2. env 를 실행 중 실행 컨텍스트의 LexicalEnvironment 로 둔다.
  3. privateEnv 를 실행 중 실행 컨텍스트의 PrivateEnvironment 로 둔다.
  4. functionPrototype 이 존재하면
    1. prototype = functionPrototype
  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]]: propKey, [[Closure]]: closure } 반환.

15.4.5 런타임 의미론: MethodDefinitionEvaluation 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDefMethodDefinition 의 DefineMethod(object) 결과 (?) 로 둔다.
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]) 수행.
  3. DefineMethodProperty(object, methodDef.[[Key]], methodDef.[[Closure]], enumerable) 반환.
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  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, propKey, "get") 수행.
  9. propKeyPrivate Name 이면
    1. PrivateElement { [[Key]]: propKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined } 반환.
  10. 그렇지 않으면
    1. desc = PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
    2. DefinePropertyOrThrow(object, propKey, desc) 수행.
    3. unused 반환.
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  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, propKey, "set") 수행.
  8. propKeyPrivate Name 이면
    1. PrivateElement { [[Key]]: propKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure } 반환.
  9. 그렇지 않으면
    1. desc = PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }.
    2. DefinePropertyOrThrow(object, propKey, desc) 수행.
    3. unused 반환.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  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, propKey) 수행.
  8. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) 로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  10. DefineMethodProperty(object, propKey, closure, enumerable) 반환.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  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, propKey) 수행.
  8. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) 로 둔다.
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  10. DefineMethodProperty(object, propKey, closure, enumerable) 반환.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propKeyClassElementName 평가 결과 (?) 로 둔다.
  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, propKey) 수행.
  8. DefineMethodProperty(object, propKey, 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 바로 뒤의 문맥은 InputElementRegExpOrTemplateTail 어휘 목표(lexical goal)를 사용해야 한다.

Note 2

YieldExpression 은 제너레이터 함수의 FormalParameters 안에서 사용할 수 없다. 그 이유는 FormalParameters 에 속하는 모든 표현식이, 생성된 Generator 가 재개(resumable) 가능한 상태가 되기 이전에 평가되기 때문이다.

Note 3

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

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 런타임 의미론: EvaluateGeneratorBody : throw completion 또는 return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.5.3 런타임 의미론: InstantiateGeneratorFunctionObject : ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. nameBindingIdentifier 의 StringValue 로 둔다.
  2. sourceTextGeneratorDeclaration 이 매칭한 소스 텍스트로 둔다.
  3. FOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) 로 둔다.
  4. SetFunctionName(F, name) 수행.
  5. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) 로 둔다.
  6. DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  7. F 반환.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceTextGeneratorDeclaration 이 매칭한 소스 텍스트로 둔다.
  2. FOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) 로 둔다.
  3. SetFunctionName(F, "default") 수행.
  4. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) 로 둔다.
  5. DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  6. F 반환.
Note

익명 GeneratorDeclarationexport default 선언의 일부로만 등장할 수 있으며 그 함수 코드는 항상 strict mode 코드이다.

15.5.4 런타임 의미론: InstantiateGeneratorFunctionExpression : ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name 이 존재하지 않으면 name = "" 로 설정한다.
  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. 단언: name 은 존재하지 않는다.
  2. nameBindingIdentifier 의 StringValue 로 설정한다.
  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

GeneratorExpressionBindingIdentifier 는 그 FunctionBody 내부에서 참조되어 제너레이터 코드가 재귀 호출될 수 있게 한다. 그러나 GeneratorDeclaration 과 달리, 해당 BindingIdentifier 는 둘러싼 스코프에서 참조할 수 없고 영향을 주지 않는다.

15.5.5 런타임 의미론: 평가 (Runtime Semantics: Evaluation)

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpression 의 InstantiateGeneratorFunctionExpression 결과를 반환한다.
YieldExpression : yield
  1. Yield(undefined) 를 반환한다.
YieldExpression : yield AssignmentExpression
  1. exprRefAssignmentExpression 평가 결과 (?) 로 둔다.
  2. value 를 ? GetValue(exprRef) 로 둔다.
  3. Yield(value) 반환.
YieldExpression : yield * AssignmentExpression
  1. generatorKindGetGeneratorKind() 로 둔다.
  2. 단언: generatorKindsync 또는 async 이어야 한다.
  3. exprRefAssignmentExpression 평가 결과 (?) 로 둔다.
  4. value 를 ? GetValue(exprRef) 로 둔다.
  5. iteratorRecord 를 ? GetIterator(value, generatorKind) 로 둔다.
  6. iteratoriteratorRecord.[[Iterator]] 로 둔다.
  7. receivedNormalCompletion(undefined) 로 둔다.
  8. 반복,
    1. receivednormal completion 이라면
      1. innerResult 를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] ») 로 둔다.
      2. generatorKindasync 이면 innerResult 를 ? Await(innerResult) 로 둔다.
      3. innerResult 가 Object 가 아니면 TypeError 예외를 던진다.
      4. done 을 ? IteratorComplete(innerResult) 로 둔다.
      5. donetrue 이면
        1. IteratorValue(innerResult) 반환.
      6. generatorKindasync 이면 received = Completion(AsyncGeneratorYield(? IteratorValue(innerResult))).
      7. 아니면 received = Completion(GeneratorYield(innerResult)).
    2. 아니고 receivedthrow completion 이라면
      1. throw 를 ? GetMethod(iterator, "throw") 로 둔다.
      2. throwundefined 가 아니면
        1. innerResult 를 ? Call(throw, iterator, « received.[[Value]] ») 로 둔다.
        2. generatorKindasync 이면 innerResult 를 ? Await(innerResult) 로 둔다.
        3. NOTE: 내부 iterator throw 메서드에서 발생한 예외는 전파되고, 정상 completion 은 내부 next 와 유사하게 처리된다.
        4. innerResult 가 Object 가 아니면 TypeError 예외를 던진다.
        5. done = ? IteratorComplete(innerResult).
        6. donetrue 이면
          1. IteratorValue(innerResult) 반환.
        7. generatorKindasync 이면 received = Completion(AsyncGeneratorYield(? IteratorValue(innerResult))).
        8. 아니면 received = Completion(GeneratorYield(innerResult)).
      3. 그렇지 않으면
        1. NOTE: iteratorthrow 메서드가 없으면 본 throw 로 yield* 루프가 종료되며, 먼저 정리 기회를 준다.
        2. closeCompletion = NormalCompletion(empty) 로 둔다.
        3. generatorKindasync 이면 ? AsyncIteratorClose(iteratorRecord, closeCompletion) 수행.
        4. 아니면 ? IteratorClose(iteratorRecord, closeCompletion) 수행.
        5. NOTE: 다음 단계에서 TypeErroryield* 프로토콜 위반(throw 메서드 부재)을 나타낸다.
        6. TypeError 예외를 던진다.
    3. 그 밖의 경우
      1. 단언: receivedreturn completion 이다.
      2. return 을 ? GetMethod(iterator, "return") 로 둔다.
      3. returnundefined 이면
        1. value = received.[[Value]].
        2. generatorKindasync 이면 value = ? Await(value).
        3. ReturnCompletion(value) 반환.
      4. innerReturnResult = ? Call(return, iterator, « received.[[Value]] »).
      5. generatorKindasync 이면 innerReturnResult = ? Await(innerReturnResult).
      6. innerReturnResult 가 Object 가 아니면 TypeError 예외를 던진다.
      7. done = ? IteratorComplete(innerReturnResult).
      8. donetrue 이면
        1. value = ? IteratorValue(innerReturnResult).
        2. ReturnCompletion(value) 반환.
      9. generatorKindasync 이면 received = Completion(AsyncGeneratorYield(? IteratorValue(innerReturnResult))).
      10. 아니면 received = Completion(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 함수의 FormalParameters 내부에서 사용할 수 없다. 이는 해당 표현식들이 AsyncGenerator 가 재개 가능한 상태가 되기 전에 평가되기 때문이다.

Note 2

AsyncGenerator 관련 추상 연산은 27.6.3 에 정의되어 있다.

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 런타임 의미론: EvaluateAsyncGeneratorBody : throw completion 또는 return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 런타임 의미론: InstantiateAsyncGeneratorFunctionObject : ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. nameBindingIdentifier 의 StringValue 로 둔다.
  2. sourceTextAsyncGeneratorDeclaration 이 매칭한 소스 텍스트로 둔다.
  3. FOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) 로 둔다.
  4. SetFunctionName(F, name) 수행.
  5. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) 로 둔다.
  6. DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  7. F 반환.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceTextAsyncGeneratorDeclaration 이 매칭한 소스 텍스트로 둔다.
  2. FOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) 로 둔다.
  3. SetFunctionName(F, "default") 수행.
  4. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) 로 둔다.
  5. DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  6. F 반환.
Note

익명 AsyncGeneratorDeclarationexport default 선언에서만 나타날 수 있다.

15.6.4 런타임 의미론: InstantiateAsyncGeneratorFunctionExpression : ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name 이 존재하지 않으면 name = "" 로 설정한다.
  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. 단언: name 은 존재하지 않는다.
  2. name = BindingIdentifier 의 StringValue.
  3. outerEnv = 실행 중 실행 컨텍스트의 LexicalEnvironment.
  4. funcEnv = NewDeclarativeEnvironment(outerEnv).
  5. funcEnv.CreateImmutableBinding(name, false) 수행.
  6. privateEnv = 실행 중 실행 컨텍스트의 PrivateEnvironment.
  7. sourceText = AsyncGeneratorExpression 이 매칭한 소스 텍스트.
  8. closure = OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateEnv).
  9. SetFunctionName(closure, name) 수행.
  10. prototype = OrdinaryObjectCreate(%AsyncGeneratorPrototype%).
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) 수행.
  12. funcEnv.InitializeBinding(name, closure) 수행.
  13. closure 반환.
Note

AsyncGeneratorExpressionBindingIdentifier 는 해당 AsyncGeneratorBody 내부에서 재귀 호출을 위해 참조될 수 있으나 AsyncGeneratorDeclaration 과 달리 둘러싼 스코프에는 영향을 주지 않는다.

15.6.5 런타임 의미론: 평가 (Runtime Semantics: Evaluation)

AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }
  1. AsyncGeneratorExpression 의 InstantiateAsyncGeneratorFunctionExpression 결과를 반환한다.

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

클래스 정의는 항상 strict mode 코드이다.

15.7.1 정적 의미론: 조기 오류 (Static Semantics: Early Errors)

ClassTail : ClassHeritageopt { ClassBody }
  • ClassHeritage 가 존재하지 않고 아래 알고리즘이 true 를 반환하면 Syntax Error 이다:

    1. constructorClassBody 의 ConstructorMethod 로 둔다.
    2. constructorempty 이면 false 반환.
    3. HasDirectSuper(constructor) 반환.
ClassBody : ClassElementList
  • ClassElementList 의 PrototypePropertyNameList 에 "constructor" 가 두 번 이상 나타나면 Syntax Error 이다.
  • ClassElementList 의 PrivateBoundIdentifiers 에 중복 항목이 있으면 (단, 동일 이름이 getter 1회와 setter 1회만, 그리고 둘 다 static 이거나 둘 다 non-static 인 경우를 제외) Syntax Error 이다.
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  • PropName(FieldDefinition) 이 "prototype" 또는 "constructor" 이면 Syntax Error 이다.
FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 정적 의미론: ClassElementKind : constructor-method, non-constructor-method, 또는 empty

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. MethodDefinition 의 PropName 이 "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 정적 의미론: ConstructorMethod : ClassElement Parse Node 또는 empty

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElement 의 ClassElementKind 가 constructor-method 이면 ClassElement 반환.
  2. empty 반환.
ClassElementList : ClassElementList ClassElement
  1. headClassElementList 의 ConstructorMethod 로 둔다.
  2. headempty 이면 head 반환.
  3. ClassElement 의 ClassElementKind 가 constructor-method 이면 ClassElement 반환.
  4. empty 반환.
Note

조기 오류 규칙은 이름이 "constructor" 인 메서드 정의가 하나뿐이며 accessor 나 generator 정의가 아님을 보장한다.

15.7.4 정적 의미론: IsStatic : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 정적 의미론: NonConstructorElements : ClassElement Parse Node 들의 List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElement 의 ClassElementKind 가 non-constructor-method 이면
    1. « ClassElement » 반환.
  2. 새 빈 List 반환.
ClassElementList : ClassElementList ClassElement
  1. listClassElementList 의 NonConstructorElements 로 둔다.
  2. ClassElement 의 ClassElementKind 가 non-constructor-method 이면
    1. list 끝에 ClassElement 추가.
  3. list 반환.

15.7.6 정적 의미론: PrototypePropertyNameList : property key 들의 List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. propNameClassElement 의 PropName 으로 둔다.
  2. propNameempty 이면 새 빈 List 반환.
  3. IsStatic(ClassElement) 가 true 이면 새 빈 List 반환.
  4. « propName » 반환.
ClassElementList : ClassElementList ClassElement
  1. listClassElementList 의 PrototypePropertyNameList 로 둔다.
  2. propNameClassElement 의 PropName 으로 둔다.
  3. propNameempty 이면 list 반환.
  4. IsStatic(ClassElement) 가 true 이면 list 반환.
  5. list 와 « propName » 의 리스트 연결을 반환.

15.7.7 정적 의미론: AllPrivateIdentifiersValid : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

아래에 명시되지 않은 모든 생성물 대안은 다음 기본 정의를 암묵적으로 갖는다:

  1. 이 Parse Node 의 각 자식 노드 child 에 대해
    1. child 가 비단말(nonterminal) 인스턴스이면
      1. AllPrivateIdentifiersValid(child, names) 가 false 이면 false 반환.
  2. true 반환.
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifier 의 StringValue 를 포함하면
    1. AllPrivateIdentifiersValid(MemberExpression, names) 반환.
  2. false 반환.
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifier 의 StringValue 를 포함하면
    1. AllPrivateIdentifiersValid(CallExpression, names) 반환.
  2. false 반환.
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifier 의 StringValue 를 포함하면 true 반환.
  2. false 반환.
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifier 의 StringValue 를 포함하면
    1. AllPrivateIdentifiersValid(OptionalChain, names) 반환.
  2. false 반환.
ClassBody : ClassElementList
  1. newNamesnamesClassBody 의 PrivateBoundIdentifiers 의 리스트 연결로 둔다.
  2. AllPrivateIdentifiersValid(ClassElementList, newNames) 반환.
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifier 의 StringValue 를 포함하면
    1. AllPrivateIdentifiersValid(ShiftExpression, names) 반환.
  2. false 반환.

15.7.8 정적 의미론: PrivateBoundIdentifiers : String 들의 List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. PrivateBoundIdentifiers(ClassElementName) 반환.
ClassElementName : PrivateIdentifier
  1. PrivateIdentifier 의 StringValue 하나만을 요소로 갖는 List 반환.
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 새 빈 List 반환.
ClassElementList : ClassElementList ClassElement
  1. names1 = PrivateBoundIdentifiers(ClassElementList).
  2. names2 = PrivateBoundIdentifiers(ClassElement).
  3. 리스트 연결(names1, names2) 반환.
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. PrivateBoundIdentifiers(ClassElementName) 반환.

15.7.9 정적 의미론: ContainsArguments : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

아래에 나열되지 않은 모든 생성물 대안은 다음 기본 정의를 갖는다:

  1. 이 Parse Node 의 각 자식 child 에 대해
    1. child 가 비단말 인스턴스이면
      1. ContainsArguments(child) 가 true 이면 true 반환.
  2. false 반환.
IdentifierReference : Identifier
  1. Identifier 의 StringValue 가 "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. ContainsArguments(ClassElementName) 반환.

15.7.10 런타임 의미론: ClassFieldDefinitionEvaluation : ClassFieldDefinition Record 를 담은 정상 completion 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.7.11 런타임 의미론: ClassStaticBlockDefinitionEvaluation : ClassStaticBlockDefinition Record

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lex 를 실행 중 실행 컨텍스트의 LexicalEnvironment 로 둔다.
  2. privateEnv 를 실행 중 실행 컨텍스트의 PrivateEnvironment 로 둔다.
  3. sourceText 를 빈 Unicode 코드 포인트 시퀀스로 둔다.
  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 런타임 의미론: EvaluateClassStaticBlockBody : return completion 또는 throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. 단언: functionObject 는 ClassStaticBlockDefinitionEvaluation 단계 5 에서 생성된 합성(synthetic) 함수이다.
  2. FunctionDeclarationInstantiation(functionObject, « ») 수행.
  3. ? Evaluation(ClassStaticBlockStatementList) 수행.
  4. ReturnCompletion(undefined) 반환.

15.7.13 런타임 의미론: ClassElementEvaluation 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. FieldDefinition에 대해 object를 인수로 하여 ClassFieldDefinitionEvaluation을 ? 반환한다.
ClassElement : MethodDefinition static MethodDefinition
  1. MethodDefinition에 대해 objectfalse를 인수로 하여 MethodDefinitionEvaluation을 ? 반환한다.
ClassElement : ClassStaticBlock
  1. ClassStaticBlock에 대해 object를 인수로 하여 ClassStaticBlockDefinitionEvaluation을 반환한다.
ClassElement : ;
  1. unused을 반환한다.

15.7.14 런타임 의미론: ClassDefinitionEvaluation: 함수 객체를 포함하는 정상 완료 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

Note

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

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

이는 private 필드와는 다르다. 필드 초기화자가 클래스 인스턴스화 중에 throw될 수 있으므로, 개별 객체는 해당 클래스의 일부 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. ClassBody의 PrivateBoundIdentifiers의 각 String dn에 대해 다음을 수행한다:
      1. classPrivateEnvironment.[[Names]][[Description]]dnPrivate Name pn을 포함하면,
        1. 단언: 이는 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. 참고: ClassHeritage를 평가할 때 실행 중인 실행 컨텍스트의 PrivateEnvironment는 outerPrivateEnvironment이다.
    3. superclassRefCompletion(Evaluation of ClassHeritage)로 둔다.
    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. 그렇지 않으면, constructorClassBody의 ConstructorMethod로 둔다.
  12. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정한다.
  13. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 classPrivateEnvironment로 설정한다.
  14. constructorempty이면,
    1. defaultConstructor를 매개변수가 없고 아무것도 캡처하지 않는 새 Abstract Closure로 두고, 호출될 때 다음 단계를 수행하도록 한다:
      1. args[[Call]] 또는 [[Construct]]에 의해 이 함수에 전달된 인수의 List로 둔다.
      2. NewTarget이 undefined이면, TypeError 예외를 던진다.
      3. F를 활성 함수 객체로 둔다.
      4. F.[[ConstructorKind]]derived이면,
        1. 참고: 이 분기는 constructor(...args) { super(...args); }와 유사하게 동작한다. 가장 주목할 만한 차이점은 앞서 언급한 ECMAScript 소스 텍스트가 %Array.prototype%%Symbol.iterator% 메서드를 관찰 가능하게 호출하는 반면, 이 함수는 그렇지 않는다는 것이다.
        2. func를 ! F.[[GetPrototypeOf]]()로 둔다.
        3. IsConstructor(func)가 false이면, TypeError 예외를 던진다.
        4. result를 ? Construct(func, args, NewTarget)로 둔다.
      5. 그렇지 않으면,
        1. 참고: 이 분기는 constructor() {}와 유사하게 동작한다.
        2. result를 ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%")로 둔다.
      6. InitializeInstanceElements(result, F)를 수행한다.
      7. NormalCompletion(result)를 반환한다.
    2. FCreateBuiltinFunction(defaultConstructor, 0, className, « [[ConstructorKind]], [[SourceText]] », the current Realm Record, constructorParent)로 둔다.
  15. 그렇지 않으면,
    1. constructorInfo를 ! DefineMethod of constructor with arguments proto and constructorParent로 둔다.
    2. FconstructorInfo.[[Closure]]로 둔다.
    3. MakeClassConstructor(F)를 수행한다.
    4. SetFunctionName(F, className)을 수행한다.
  16. F.[[SourceText]]sourceText로 설정한다.
  17. MakeConstructor(F, false, proto)를 수행한다.
  18. ClassHeritage가 존재하면, F.[[ConstructorKind]]derived로 설정한다.
  19. DefineMethodProperty(proto, "constructor", F, false)를 수행한다.
  20. ClassBody가 존재하지 않으면, elements를 새 빈 List로 둔다.
  21. 그렇지 않으면, elementsClassBody의 NonConstructorElements로 둔다.
  22. instancePrivateMethods를 새 빈 List로 둔다.
  23. staticPrivateMethods를 새 빈 List로 둔다.
  24. instanceFields를 새 빈 List로 둔다.
  25. staticElements를 새 빈 List로 둔다.
  26. elements의 각 ClassElement e에 대해 다음을 수행한다:
    1. e의 IsStatic이 false이면,
      1. elementCompletion(ClassElementEvaluation of e with argument proto)로 둔다.
    2. 그렇지 않으면,
      1. elementCompletion(ClassElementEvaluation of e with argument F)로 둔다.
    3. elementabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 env로 설정한다.
      2. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
      3. element를 반환한다.
    4. element를 ! element로 설정한다.
    5. elementPrivateElement이면,
      1. 단언: element.[[Kind]]method 또는 accessor 중 하나이다.
      2. e의 IsStatic이 false이면, containerinstancePrivateMethods로 둔다; 그렇지 않으면, containerstaticPrivateMethods로 둔다.
      3. container[[Key]]element.[[Key]]PrivateElement pe를 포함하면,
        1. 단언: 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로 대체한다.
      4. 그렇지 않으면,
        1. elementcontainer에 추가한다.
    6. 그렇지 않고 elementClassFieldDefinition Record이면,
      1. e의 IsStatic이 false이면, elementinstanceFields에 추가한다.
      2. 그렇지 않으면, elementstaticElements에 추가한다.
    7. 그렇지 않고 elementClassStaticBlockDefinition Record이면,
      1. elementstaticElements에 추가한다.
  27. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 env로 설정한다.
  28. classBindingundefined가 아니면,
    1. classEnv.InitializeBinding(classBinding, F)를 수행한다.
  29. F.[[PrivateMethods]]instancePrivateMethods로 설정한다.
  30. F.[[Fields]]instanceFields로 설정한다.
  31. staticPrivateMethods의 각 PrivateElement method에 대해,
    1. PrivateMethodOrAccessorAdd(F, method)를 수행한다.
  32. staticElements의 각 요소 elementRecord에 대해,
    1. elementRecordClassFieldDefinition Record이면,
      1. resultCompletion(DefineField(F, elementRecord))로 둔다.
    2. 그렇지 않으면,
      1. 단언: elementRecordClassStaticBlockDefinition Record이다.
      2. resultCompletion(Call(elementRecord.[[BodyFunction]], F))로 둔다.
    3. resultabrupt completion이면,
      1. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
      2. result를 반환한다.
  33. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnvironment로 설정한다.
  34. F를 반환한다.

15.7.15 런타임 의미론: BindingClassDeclarationEvaluation : 함수 객체를 포함하는 정상 완료 또는 abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. BindingIdentifier의 StringValue를 className으로 둔다.
  2. ClassDeclaration이 매칭한 소스 텍스트를 sourceText로 둔다.
  3. ClassTail에 대해 className, className, sourceText를 인수로 하여 ClassDefinitionEvaluation의 결과를 value로 둔다.
  4. 실행 컨텍스트의 LexicalEnvironment를 env로 둔다.
  5. InitializeBoundName(className, value, env)를 수행한다.
  6. value를 반환한다.
ClassDeclaration : class ClassTail
  1. ClassDeclaration이 매칭한 소스 텍스트를 sourceText로 둔다.
  2. ClassTail에 대해 undefined, "default", sourceText를 인수로 하여 ClassDefinitionEvaluation의 결과를 반환한다.
Note

ClassDeclaration : class ClassTail ExportDeclaration의 일부로만 나타나며, 바인딩 생성은 해당 생성물의 평가 동작에서 처리된다. 16.2.3.7 참고.

15.7.16 런타임 의미론: Evaluation

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

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

ClassExpression : class ClassTail
  1. ClassExpression이 매칭한 소스 텍스트를 sourceText로 둔다.
  2. ClassTail에 대해 undefined, "", sourceText를 인수로 하여 ClassDefinitionEvaluation의 결과를 반환한다.
ClassExpression : class BindingIdentifier ClassTail
  1. BindingIdentifier의 StringValue를 className으로 둔다.
  2. ClassExpression이 매칭한 소스 텍스트를 sourceText로 둔다.
  3. ClassTail에 대해 className, className, sourceText를 인수로 하여 ClassDefinitionEvaluation의 결과를 반환한다.
ClassElementName : PrivateIdentifier
  1. PrivateIdentifier의 StringValue를 privateIdentifier로 둔다.
  2. 실행 컨텍스트의 PrivateEnvironment를 privateEnvRec로 둔다.
  3. privateEnvRec.[[Names]]names로 둔다.
  4. 단언: names의 정확히 하나의 요소가 [[Description]]privateIdentifierPrivate Name임.
  5. privateNamenames[[Description]]privateIdentifierPrivate Name으로 둔다.
  6. privateName을 반환한다.
ClassStaticBlockStatementList : [empty]
  1. undefined를 반환한다.

15.8 Async 함수 정의

구문

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[Await] 파라미터가 있을 때 AwaitExpression의 키워드로 파싱된다. [Await] 파라미터는 아래 문맥의 최상위에 있지만, FunctionBody 같은 비단말에 따라 부재할 수 있다:

Script가 구문 목표 기호일 때, [Await] 파라미터가 없으면 await는 식별자로 파싱될 수 있다. 해당 문맥은 다음과 같다:

Note 2

YieldExpression과 달리 AwaitExpression의 피연산자를 생략하면 문법 오류이다. 반드시 await할 대상이 있어야 한다.

15.8.1 정적 의미론: 조기 오류

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

15.8.2 런타임 의미론: InstantiateAsyncFunctionObject: ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifier의 StringValue로 둔다.
  2. sourceTextAsyncFunctionDeclaration이 매칭한 소스 텍스트로 둔다.
  3. FOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  4. SetFunctionName(F, name)을 수행한다.
  5. F를 반환한다.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclaration이 매칭한 소스 텍스트로 둔다.
  2. FOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv)로 둔다.
  3. SetFunctionName(F, "default")를 수행한다.
  4. F를 반환한다.

15.8.3 런타임 의미론: InstantiateAsyncFunctionExpression: ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name이 없다면 name = ""로 설정한다.
  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. 단언: name은 없다.
  2. nameBindingIdentifier의 StringValue로 둔다.
  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

AsyncFunctionExpressionBindingIdentifier는 그 AsyncFunctionBody 내부에서 참조되어 함수가 재귀적으로 자신을 호출할 수 있게 한다. 하지만 FunctionDeclaration과 달리 AsyncFunctionExpressionBindingIdentifier는 외부 스코프에서 참조할 수 없고 영향을 주지 않는다.

15.8.4 런타임 의미론: EvaluateAsyncFunctionBody: return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.8.5 런타임 의미론: 평가

AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. AsyncFunctionExpression의 InstantiateAsyncFunctionExpression을 반환한다.
AwaitExpression : await UnaryExpression
  1. exprRefUnaryExpression 평가 결과(?)로 둔다.
  2. value를 ? GetValue(exprRef)로 둔다.
  3. Await(value)를 반환한다.

15.9 Async 화살표 함수 정의

구문

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 정적 의미론: 조기 오류

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

15.9.2 정적 의미론: AsyncConciseBodyContainsUseStrict: Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. false를 반환한다.
AsyncConciseBody : { AsyncFunctionBody }
  1. FunctionBodyContainsUseStrict(AsyncFunctionBody)를 반환한다.

15.9.3 런타임 의미론: EvaluateAsyncConciseBody: return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.9.4 런타임 의미론: InstantiateAsyncArrowFunctionExpression: ECMAScript 함수 객체

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name이 없으면 name = ""로 설정한다.
  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 = ""로 설정한다.
  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 런타임 의미론: 평가

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

15.10 꼬리 위치 호출

15.10.1 정적 의미론: IsInTailPosition( call: CallExpression Parse Node 또는 MemberExpression Parse Node 또는 OptionalChain Parse Node, ): Boolean

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. body의 HasCallInTailPosition 결과를 call 인수로 반환한다.
Note

꼬리 위치 호출은 엄격 모드 코드에서만 정의된다. 이는 비표준 언어 확장( 10.2.4 참조 )으로 인해 호출자 컨텍스트 체인을 관찰할 수 있게 되기 때문이다.

15.10.2 정적 의미론: HasCallInTailPosition: Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

Note 1

call은 소스 텍스트의 특정 범위를 나타내는 Parse Node이다. 아래 알고리즘에서 call을 다른 Parse Node와 비교할 때는 둘이 동일한 소스 텍스트를 나타내는지 여부를 검사한다.

Note 2

return GetValue로 바로 이어지는 잠재적 꼬리 위치 호출도 꼬리 위치 호출이 될 수 있다. 함수 호출은 Reference Record를 반환할 수 없으므로, 이런 GetValue 연산은 항상 실제 함수 호출 결과와 동일한 값을 반환한다.

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. StatementList의 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  2. hastrue이면 true를 반환한다.
  3. StatementListItem의 HasCallInTailPosition 결과를 call 인수로 반환한다.
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. 첫 번째 Statement의 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  2. hastrue이면 true를 반환한다.
  3. 두 번째 Statement의 HasCallInTailPosition 결과를 call 인수로 반환한다.
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. Statement의 HasCallInTailPosition 결과를 call 인수로 반환한다.
LabelledStatement : LabelIdentifier : LabelledItem
  1. LabelledItem의 HasCallInTailPosition 결과를 call 인수로 반환한다.
ReturnStatement : return Expression ;
  1. Expression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
SwitchStatement : switch ( Expression ) CaseBlock
  1. CaseBlock의 HasCallInTailPosition 결과를 call 인수로 반환한다.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalse로 둔다.
  2. 첫 번째 CaseClauses가 있으면, 그 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  3. hastrue이면 true를 반환한다.
  4. DefaultClause의 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  5. hastrue이면 true를 반환한다.
  6. 두 번째 CaseClauses가 있으면, 그 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  7. has를 반환한다.
CaseClauses : CaseClauses CaseClause
  1. CaseClauses의 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  2. hastrue이면 true를 반환한다.
  3. CaseClause의 HasCallInTailPosition 결과를 call 인수로 반환한다.
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList가 있으면 그 HasCallInTailPosition 결과를 call 인수로 반환한다.
  2. false를 반환한다.
TryStatement : try Block Catch
  1. Catch의 HasCallInTailPosition 결과를 call 인수로 반환한다.
TryStatement : try Block Finally try Block Catch Finally
  1. Finally의 HasCallInTailPosition 결과를 call 인수로 반환한다.
Catch : catch ( CatchParameter ) Block
  1. Block의 HasCallInTailPosition 결과를 call 인수로 반환한다.
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. AssignmentExpression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. 첫 번째 AssignmentExpression의 HasCallInTailPosition 결과를 call 인수로 has로 둔다.
  2. hastrue이면 true를 반환한다.
  3. 두 번째 AssignmentExpression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. BitwiseORExpression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. LogicalANDExpression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. BitwiseORExpression의 HasCallInTailPosition 결과를 call 인수로 반환한다.
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. CallExpressioncall이면 true를 반환한다.
  2. false를 반환한다.
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. OptionalChain의 HasCallInTailPosition 결과를 call 인수로 반환한다.
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. expr의 HasCallInTailPosition 결과를 call 인수로 반환한다.
ParenthesizedExpression : ( Expression )
  1. Expression의 HasCallInTailPosition 결과를 call 인수로 반환한다.

15.10.3 PrepareForTailCall ( )

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

  1. 현재 실행 컨텍스트는 이후 ECMAScript 코드 또는 내장 함수의 평가에 사용되지 않을 것임을 단언한다. 이 추상 연산 이후 Call을 호출하면 해당 평가 전에 새 실행 컨텍스트가 생성되고 push된다.
  2. 현재 실행 컨텍스트와 관련된 모든 리소스를 폐기한다.
  3. unused를 반환한다.

꼬리 위치 호출은 현재 실행 중인 함수 실행 컨텍스트와 관련된 임시 내부 리소스를 호출 대상 함수 전에 해제하거나, 해당 함수에 재사용해야 한다.

Note

예를 들어, 꼬리 위치 호출은 대상 함수의 activation record가 호출 함수의 activation record보다 커지는 만큼만 스택 크기를 증가시켜야 한다. 대상 함수의 activation record가 더 작다면, 전체 스택 크기는 줄어들어야 한다.