페이지 표시 설정

15 ECMAScript 언어: 함수와 클래스

참고

다양한 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 참고

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

15.1.2 Static Semantics: ContainsExpression

구문 지향 연산 ContainsExpression. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

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. has를 BindingElementList의 ContainsExpression으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. BindingRestElement의 ContainsExpression을 반환합니다.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. has를 BindingPropertyList의 ContainsExpression으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. BindingProperty의 ContainsExpression을 반환합니다.
BindingElementList : BindingElementList , BindingElisionElement
  1. has를 BindingElementList의 ContainsExpression으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. BindingElisionElement의 ContainsExpression을 반환합니다.
BindingElisionElement : Elisionopt BindingElement
  1. BindingElement의 ContainsExpression을 반환합니다.
BindingProperty : PropertyName : BindingElement
  1. has를 PropertyName의 IsComputedPropertyKey로 둡니다.
  2. has가 true이면 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. formals를 CoverParenthesizedExpressionAndArrowParameterList가 포괄하는 ArrowFormalParameters로 둡니다.
  2. formals의 ContainsExpression을 반환합니다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false를 반환합니다.

15.1.3 Static Semantics: IsSimpleParameterList

구문 지향 연산 IsSimpleParameterList. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

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. FormalParameterList의 IsSimpleParameterList가 false이면 false를 반환합니다.
  2. FormalParameter의 IsSimpleParameterList를 반환합니다.
FormalParameter : BindingElement
  1. BindingElement의 IsSimpleParameterList를 반환합니다.
ArrowParameters : BindingIdentifier
  1. true를 반환합니다.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formals를 CoverParenthesizedExpressionAndArrowParameterList가 포괄하는 ArrowFormalParameters로 둡니다.
  2. formals의 IsSimpleParameterList를 반환합니다.
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true를 반환합니다.
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. head를 CoverCallExpressionAndAsyncArrowHead가 포괄하는 AsyncArrowHead로 둡니다.
  2. head의 IsSimpleParameterList를 반환합니다.

15.1.4 Static Semantics: HasInitializer

구문 지향 연산 HasInitializer. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

BindingElement : BindingPattern
  1. false를 반환합니다.
BindingElement : BindingPattern Initializer
  1. true를 반환합니다.
SingleNameBinding : BindingIdentifier
  1. false를 반환합니다.
SingleNameBinding : BindingIdentifier Initializer
  1. true를 반환합니다.
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterList의 HasInitializer가 true이면 true를 반환합니다.
  2. FormalParameter의 HasInitializer를 반환합니다.

15.1.5 Static Semantics: ExpectedArgumentCount

구문 지향 연산 ExpectedArgumentCount. 인수 없음. 반환값: 음이 아닌 정수. 다음 생성 규칙별로 정의된다.

FormalParameters : [empty] FunctionRestParameter
  1. 0을 반환합니다.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterList의 ExpectedArgumentCount를 반환합니다.
참고

FormalParameterList의 ExpectedArgumentCount는 나머지 매개변수 또는 Initializer가 있는 첫 번째 FormalParameter 왼쪽에 있는 FormalParameters의 수입니다. 이니셜라이저가 없는 FormalParameter는 이니셜라이저가 있는 첫 번째 매개변수 뒤에 나타날 수 있지만, 이러한 매개변수는 기본값이 undefined인 선택적 매개변수로 간주됩니다.

FormalParameterList : FormalParameter
  1. FormalParameter의 HasInitializer가 true이면 0을 반환합니다.
  2. 1을 반환합니다.
FormalParameterList : FormalParameterList , FormalParameter
  1. count를 FormalParameterList의 ExpectedArgumentCount로 둡니다.
  2. FormalParameterList의 HasInitializer가 true이거나 FormalParameter의 HasInitializer가 true이면 count를 반환합니다.
  3. count + 1을 반환합니다.
ArrowParameters : BindingIdentifier
  1. 1을 반환합니다.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formals를 CoverParenthesizedExpressionAndArrowParameterList가 포괄하는 ArrowFormalParameters로 둡니다.
  2. formals의 ExpectedArgumentCount를 반환합니다.
PropertySetParameterList : FormalParameter
  1. FormalParameter의 HasInitializer가 true이면 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 } 참고

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

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

구문 지향 연산 FunctionBodyContainsUseStrict. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

FunctionBody : FunctionStatementList
  1. FunctionBody의 Directive Prologue에 Use Strict Directive가 포함되어 있으면 true를 반환합니다.
  2. false를 반환합니다.

15.2.3 Runtime Semantics: EvaluateFunctionBody

구문 지향 연산 EvaluateFunctionBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: (return 완료 또는 throw 완료). 다음 생성 규칙별로 정의된다.

FunctionBody : FunctionStatementList
  1. ? FunctionDeclarationInstantiation(funcObj, argList)을 수행합니다.
  2. FunctionStatementList의 ? Evaluation을 수행합니다.
  3. 참고: 이전 단계가 정상 완료를 생성했다면 평가는 FunctionStatementList의 끝을 지나 진행하여 완료된 것입니다.
  4. ReturnCompletion(undefined)을 반환합니다.

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

구문 지향 연산 InstantiateOrdinaryFunctionObject. 인수 envRecord (Environment 레코드) 및 privateEnv ((PrivateEnvironment 레코드 또는 null)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. name을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 FunctionDeclaration과 일치하는 소스 텍스트로 둡니다.
  3. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  4. SetFunctionName(closure, name)을 수행합니다.
  5. MakeConstructor(closure)를 수행합니다.
  6. closure를 반환합니다.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceText를 FunctionDeclaration과 일치하는 소스 텍스트로 둡니다.
  2. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  3. SetFunctionName(closure, "default")를 수행합니다.
  4. MakeConstructor(closure)를 수행합니다.
  5. closure를 반환합니다.
참고

익명 FunctionDeclaration은 export default 선언의 일부로만 나타날 수 있으므로 해당 함수 코드는 항상 엄격 모드 코드입니다.

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

구문 지향 연산 InstantiateOrdinaryFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 FunctionExpression과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. SetFunctionName(closure, name)을 수행합니다.
  7. MakeConstructor(closure)를 수행합니다.
  8. closure를 반환합니다.
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. 단언: name은 존재하지 않습니다.
  2. name을 BindingIdentifier의 StringValue로 설정합니다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  4. funcEnv를 NewDeclarativeEnvironment(outerEnv)로 둡니다.
  5. ! funcEnv.CreateImmutableBinding(name, false)를 수행합니다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  7. sourceText를 FunctionExpression과 일치하는 소스 텍스트로 둡니다.
  8. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, funcEnv, privateEnv)로 둡니다.
  9. SetFunctionName(closure, name)을 수행합니다.
  10. MakeConstructor(closure)를 수행합니다.
  11. ! funcEnv.InitializeBinding(name, closure)를 수행합니다.
  12. closure를 반환합니다.
참고

FunctionExpression의 BindingIdentifier는 함수가 자기 자신을 재귀적으로 호출할 수 있도록 FunctionExpression의 FunctionBody 내부에서 참조할 수 있습니다. 그러나 FunctionDeclaration과 달리 FunctionExpression의 BindingIdentifier는 FunctionExpression을 둘러싸는 스코프에서 참조할 수 없으며 해당 스코프에도 영향을 주지 않습니다.

15.2.6 Runtime Semantics: 평가

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. empty를 반환합니다.
참고 1 FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. empty를 반환합니다.
FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
  1. FunctionExpression의 InstantiateOrdinaryFunctionExpression을 반환합니다.
참고 2

FunctionDeclaration 또는 FunctionExpression을 사용하여 정의된 모든 함수에는 해당 함수가 생성자로 사용될 가능성을 허용하기 위해 "prototype" 프로퍼티가 자동으로 생성됩니다.

FunctionStatementList : [empty]
  1. undefined를 반환합니다.
FunctionStatementList : StatementList
  1. result를 Completion(StatementList의 Evaluation)으로 둡니다.
  2. env를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. 단언: env는 Declarative Environment Record입니다.
  4. ? DisposeResources(env.[[DisposableResourceStack]], result)를 반환합니다.

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

구문 지향 연산 ConciseBodyContainsUseStrict. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

ConciseBody : ExpressionBody
  1. false를 반환합니다.
ConciseBody : { FunctionBody }
  1. FunctionBody의 FunctionBodyContainsUseStrict를 반환합니다.

15.3.3 Runtime Semantics: EvaluateConciseBody

구문 지향 연산 EvaluateConciseBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: (return 완료 또는 throw 완료). 다음 생성 규칙별로 정의된다.

ConciseBody : ExpressionBody
  1. ? FunctionDeclarationInstantiation(funcObj, argList)을 수행합니다.
  2. ExpressionBody의 ? Evaluation을 반환합니다.

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

구문 지향 연산 InstantiateArrowFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

ArrowFunction : ArrowParameters => ConciseBody
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 ArrowFunction과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, envRecord, privateEnv)로 둡니다.
  6. SetFunctionName(closure, name)을 수행합니다.
  7. closure를 반환합니다.
참고

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

15.3.5 Runtime Semantics: 평가

ArrowFunction : ArrowParameters => ConciseBody
  1. ArrowFunction의 InstantiateArrowFunctionExpression을 반환합니다.
ExpressionBody : AssignmentExpression
  1. exprRef를 AssignmentExpression의 ? 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

구문 지향 연산 HasDirectSuper. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

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

15.4.3 Static Semantics: SpecialMethod

구문 지향 연산 SpecialMethod. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

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

구문 지향 연산 DefineMethod. 인수 obj (Object) 및 선택적 인수 proto (Object). 반환값: (정상 완료 (값: 레코드 (필드: [[Key]] (프로퍼티 키), [[Closure]] (ECMAScript 함수 객체))) 또는 중도 완료). 다음 생성 규칙별로 정의된다.

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. proto가 존재하지 않으면 proto를 %Function.prototype%로 설정합니다.
  5. sourceText를 MethodDefinition과 일치하는 소스 텍스트로 둡니다.
  6. closure를 OrdinaryFunctionCreate(proto, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  7. MakeMethod(closure, obj)을 수행합니다.
  8. Record { [[Key]]: propertyKey, [[Closure]]: closure }를 반환합니다.

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

구문 지향 연산 MethodDefinitionEvaluation. 인수 obj (Object) 및 enumerable (Boolean). 반환값: (정상 완료 (값: (PrivateElement 또는 empty)) 또는 중도 완료). 다음 생성 규칙별로 정의된다.

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDef를 인수 obj를 사용한 MethodDefinition의 ? DefineMethod로 둡니다.
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]])을 수행합니다.
  3. ? DefineMethodProperty(obj, methodDef.[[Key]], methodDef.[[Closure]], enumerable)을 반환합니다.
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 MethodDefinition과 일치하는 소스 텍스트로 둡니다.
  5. formalParamList를 생성 규칙 FormalParameters : [empty] 의 인스턴스로 둡니다.
  6. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  7. MakeMethod(closure, obj)을 수행합니다.
  8. SetFunctionName(closure, propertyKey, "get")을 수행합니다.
  9. propertyKey가 Private Name이면, 다음을 수행합니다.
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Getter]]: closure, [[Setter]]: undefined }를 반환합니다.
  10. propertyDesc를 PropertyDescriptor { [[Getter]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둡니다.
  11. ? DefinePropertyOrThrow(obj, propertyKey, propertyDesc)를 수행합니다.
  12. empty를 반환합니다.
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 MethodDefinition과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. MakeMethod(closure, obj)을 수행합니다.
  7. SetFunctionName(closure, propertyKey, "set")을 수행합니다.
  8. propertyKey가 Private Name이면, 다음을 수행합니다.
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Getter]]: undefined, [[Setter]]: closure }를 반환합니다.
  9. propertyDesc를 PropertyDescriptor { [[Setter]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }로 둡니다.
  10. ? DefinePropertyOrThrow(obj, propertyKey, propertyDesc)를 수행합니다.
  11. empty를 반환합니다.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 GeneratorMethod와 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. MakeMethod(closure, obj)을 수행합니다.
  7. SetFunctionName(closure, propertyKey)을 수행합니다.
  8. proto를 OrdinaryObjectCreate(%GeneratorPrototype%)로 둡니다.
  9. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  10. ? DefineMethodProperty(obj, propertyKey, closure, enumerable)을 반환합니다.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncGeneratorMethod와 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. MakeMethod(closure, obj)을 수행합니다.
  7. SetFunctionName(closure, propertyKey)을 수행합니다.
  8. proto를 OrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둡니다.
  9. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  10. ? DefineMethodProperty(obj, propertyKey, closure, enumerable)을 반환합니다.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKey를 ClassElementName의 ? Evaluation으로 둡니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncMethod와 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. MakeMethod(closure, obj)을 수행합니다.
  7. SetFunctionName(closure, propertyKey)을 수행합니다.
  8. ? DefineMethodProperty(obj, propertyKey, closure, enumerable)을 반환합니다.

15.5 제너레이터 함수 정의

구문

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] 참고 1

yield 바로 뒤의 구문 문맥에서는 InputElementRegExpOrTemplateTail 어휘 목표를 사용해야 합니다.

참고 2

FormalParameters의 일부인 표현식은 결과 Generator가 재개 가능한 상태가 되기 전에 평가되므로 제너레이터 함수의 FormalParameters 안에서는 YieldExpression을 사용할 수 없습니다.

참고 3

Generator와 관련된 추상 연산은 27.8.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

구문 지향 연산 EvaluateGeneratorBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: (throw 완료 또는 return 완료). 다음 생성 규칙별로 정의된다.

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

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

구문 지향 연산 InstantiateGeneratorFunctionObject. 인수 envRecord (Environment 레코드) 및 privateEnv ((PrivateEnvironment 레코드 또는 null)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. name을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 GeneratorDeclaration과 일치하는 소스 텍스트로 둡니다.
  3. closure를 OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  4. SetFunctionName(closure, name)을 수행합니다.
  5. proto를 OrdinaryObjectCreate(%GeneratorPrototype%)로 둡니다.
  6. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  7. closure를 반환합니다.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceText를 GeneratorDeclaration과 일치하는 소스 텍스트로 둡니다.
  2. closure를 OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  3. SetFunctionName(closure, "default")를 수행합니다.
  4. proto를 OrdinaryObjectCreate(%GeneratorPrototype%)로 둡니다.
  5. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  6. closure를 반환합니다.
참고

익명 GeneratorDeclaration은 export default 선언의 일부로만 나타날 수 있으므로 해당 함수 코드는 항상 엄격 모드 코드입니다.

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

구문 지향 연산 InstantiateGeneratorFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 GeneratorExpression과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. SetFunctionName(closure, name)을 수행합니다.
  7. proto를 OrdinaryObjectCreate(%GeneratorPrototype%)로 둡니다.
  8. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  9. closure를 반환합니다.
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. 단언: name은 존재하지 않습니다.
  2. name을 BindingIdentifier의 StringValue로 설정합니다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  4. funcEnv를 NewDeclarativeEnvironment(outerEnv)로 둡니다.
  5. ! funcEnv.CreateImmutableBinding(name, false)를 수행합니다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  7. sourceText를 GeneratorExpression과 일치하는 소스 텍스트로 둡니다.
  8. closure를 OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateEnv)로 둡니다.
  9. SetFunctionName(closure, name)을 수행합니다.
  10. proto를 OrdinaryObjectCreate(%GeneratorPrototype%)로 둡니다.
  11. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  12. ! funcEnv.InitializeBinding(name, closure)를 수행합니다.
  13. closure를 반환합니다.
참고

GeneratorExpression의 BindingIdentifier는 제너레이터 코드가 자기 자신을 재귀적으로 호출할 수 있도록 GeneratorExpression의 FunctionBody 내부에서 참조할 수 있습니다. 그러나 GeneratorDeclaration과 달리 GeneratorExpression의 BindingIdentifier는 GeneratorExpression을 둘러싸는 스코프에서 참조할 수 없으며 해당 스코프에도 영향을 주지 않습니다.

15.5.5 Runtime Semantics: 평가

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpression의 InstantiateGeneratorFunctionExpression을 반환합니다.
YieldExpression : yield
  1. ? Yield(undefined)를 반환합니다.
YieldExpression : yield AssignmentExpression
  1. exprRef를 AssignmentExpression의 ? Evaluation으로 둡니다.
  2. value를 ? GetValue(exprRef)로 둡니다.
  3. ? Yield(value)를 반환합니다.
YieldExpression : yield * AssignmentExpression
  1. genKind를 GetGeneratorKind()로 둡니다.
  2. 단언: genKind는 sync 또는 async입니다.
  3. exprRef를 AssignmentExpression의 ? Evaluation으로 둡니다.
  4. value를 ? GetValue(exprRef)로 둡니다.
  5. iteratorRecord를 ? GetIterator(value, genKind)로 둡니다.
  6. iterator를 iteratorRecord.[[Iterator]]로 둡니다.
  7. received를 NormalCompletion(undefined)로 둡니다.
  8. 다음을 반복합니다.
    1. received가 정상 완료이면, 다음을 수행합니다.
      1. innerResult를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »)로 둡니다.
      2. genKind가 async이면 innerResult를 ? Await(innerResult)로 설정합니다.
      3. innerResult가 Object가 아니면 TypeError 예외를 던집니다.
      4. done을 ? IteratorComplete(innerResult)로 둡니다.
      5. done이 true이면, 다음을 수행합니다.
        1. ? IteratorValue(innerResult)를 반환합니다.
      6. genKind가 async이면 received를 Completion(AsyncGeneratorYield(? IteratorValue(innerResult)))으로 설정합니다.
      7. 그렇지 않으면 received를 Completion(GeneratorYield(innerResult))으로 설정합니다.
    2. 그렇지 않고 received가 throw 완료이면, 다음을 수행합니다.
      1. throw를 ? GetMethod(iterator, "throw")로 둡니다.
      2. throw가 undefined가 아니면, 다음을 수행합니다.
        1. innerResult를 ? Call(throw, iterator, « received.[[Value]] »)로 둡니다.
        2. genKind가 async이면 innerResult를 ? Await(innerResult)로 설정합니다.
        3. 참고: 내부 반복자의 throw 메서드에서 발생한 예외는 전파됩니다. 내부 throw 메서드의 정상 완료는 내부 next와 유사하게 처리됩니다.
        4. innerResult가 Object가 아니면 TypeError 예외를 던집니다.
        5. done을 ? IteratorComplete(innerResult)로 둡니다.
        6. done이 true이면, 다음을 수행합니다.
          1. ? IteratorValue(innerResult)를 반환합니다.
        7. genKind가 async이면 received를 Completion(AsyncGeneratorYield(? IteratorValue(innerResult)))으로 설정합니다.
        8. 그렇지 않으면 received를 Completion(GeneratorYield(innerResult))으로 설정합니다.
      3. 그렇지 않으면,
        1. 참고: iterator에 throw 메서드가 없으면 이 throw는 yield* 반복을 종료합니다. 그러나 먼저 iterator가 정리할 기회를 제공해야 합니다.
        2. closeCompletion을 NormalCompletion(empty)으로 둡니다.
        3. genKind가 async이면 ? AsyncIteratorClose(iteratorRecord, closeCompletion)를 수행합니다.
        4. 그렇지 않으면 ? IteratorClose(iteratorRecord, closeCompletion)를 수행합니다.
        5. 참고: 다음 단계는 yield* 프로토콜 위반, 즉 iterator에 throw 메서드가 없음을 나타내기 위해 TypeError를 던집니다.
        6. TypeError 예외를 던집니다.
    3. 그렇지 않으면,
      1. 단언: received는 return 완료입니다.
      2. return을 ? GetMethod(iterator, "return")으로 둡니다.
      3. return이 undefined이면, 다음을 수행합니다.
        1. receivedValue를 received.[[Value]]로 둡니다.
        2. genKind가 async이면, 다음을 수행합니다.
          1. receivedValue를 ? Await(receivedValue)로 설정합니다.
        3. ReturnCompletion(receivedValue)을 반환합니다.
      4. innerReturnResult를 ? Call(return, iterator, « received.[[Value]] »)로 둡니다.
      5. genKind가 async이면 innerReturnResult를 ? Await(innerReturnResult)로 설정합니다.
      6. innerReturnResult가 Object가 아니면 TypeError 예외를 던집니다.
      7. done을 ? IteratorComplete(innerReturnResult)로 둡니다.
      8. done이 true이면, 다음을 수행합니다.
        1. returnedValue를 ? IteratorValue(innerReturnResult)로 둡니다.
        2. ReturnCompletion(returnedValue)을 반환합니다.
      9. genKind가 async이면 received를 Completion(AsyncGeneratorYield(? IteratorValue(innerReturnResult)))으로 설정합니다.
      10. 그렇지 않으면 received를 Completion(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] 참고 1

FormalParameters의 일부인 표현식은 결과 AsyncGenerator가 재개 가능한 상태가 되기 전에 평가되므로 비동기 제너레이터 함수의 FormalParameters 안에서는 YieldExpression 및 AwaitExpression을 사용할 수 없습니다.

참고 2

AsyncGenerator와 관련된 추상 연산은 27.9.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

구문 지향 연산 EvaluateAsyncGeneratorBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: (throw 완료 또는 return 완료). 다음 생성 규칙별로 정의된다.

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

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

구문 지향 연산 InstantiateAsyncGeneratorFunctionObject. 인수 envRecord (Environment 레코드) 및 privateEnv ((PrivateEnvironment 레코드 또는 null)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. name을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 AsyncGeneratorDeclaration과 일치하는 소스 텍스트로 둡니다.
  3. closure를 OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  4. SetFunctionName(closure, name)을 수행합니다.
  5. proto를 OrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둡니다.
  6. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  7. closure를 반환합니다.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceText를 AsyncGeneratorDeclaration과 일치하는 소스 텍스트로 둡니다.
  2. closure를 OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  3. SetFunctionName(closure, "default")를 수행합니다.
  4. proto를 OrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둡니다.
  5. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  6. closure를 반환합니다.
참고

익명 AsyncGeneratorDeclaration은 export default 선언의 일부로만 나타날 수 있습니다.

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

구문 지향 연산 InstantiateAsyncGeneratorFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncGeneratorExpression과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. SetFunctionName(closure, name)을 수행합니다.
  7. proto를 OrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둡니다.
  8. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[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. proto를 OrdinaryObjectCreate(%AsyncGeneratorPrototype%)로 둡니다.
  11. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행합니다.
  12. ! funcEnv.InitializeBinding(name, closure)를 수행합니다.
  13. closure를 반환합니다.
참고

AsyncGeneratorExpression의 BindingIdentifier는 제너레이터 코드가 자기 자신을 재귀적으로 호출할 수 있도록 AsyncGeneratorExpression의 AsyncGeneratorBody 내부에서 참조할 수 있습니다. 그러나 AsyncGeneratorDeclaration과 달리 AsyncGeneratorExpression의 BindingIdentifier는 AsyncGeneratorExpression을 둘러싸는 스코프에서 참조할 수 없으며 해당 스코프에도 영향을 주지 않습니다.

15.6.5 Runtime Semantics: 평가

AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }
  1. AsyncGeneratorExpression의 InstantiateAsyncGeneratorFunctionExpression을 반환합니다.

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 참고

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

15.7.1 Static Semantics: 조기 오류

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList
  • ClassElementList의 PrototypePropertyNameList에 "constructor"가 두 번 이상 나타나면 Syntax Error입니다.
  • ClassElementList의 PrivateBoundIdentifiers에 중복 항목이 하나라도 포함되어 있으면 Syntax Error입니다. 단, 해당 이름이 getter에 한 번, setter에 한 번 사용되고 그 밖의 어떤 항목에서도 사용되지 않으며 getter와 setter가 둘 다 static이거나 둘 다 non-static이면 예외입니다.
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ; FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 Static Semantics: ClassElementKind

구문 지향 연산 ClassElementKind. 인수 없음. 반환값: (constructor-method, non-constructor-method 또는 empty). 다음 생성 규칙별로 정의된다.

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 Static Semantics: ConstructorMethod

구문 지향 연산 ConstructorMethod. 인수 없음. 반환값: (a ClassElement Parse Node 또는 empty). 다음 생성 규칙별로 정의된다.

ClassElementList : ClassElement
  1. ClassElement의 ClassElementKind가 constructor-method이면 ClassElement를 반환합니다.
  2. empty를 반환합니다.
ClassElementList : ClassElementList ClassElement
  1. head를 ClassElementList의 ConstructorMethod로 둡니다.
  2. head가 empty가 아니면 head를 반환합니다.
  3. ClassElement의 ClassElementKind가 constructor-method이면 ClassElement를 반환합니다.
  4. empty를 반환합니다.
참고

조기 오류 규칙은 이름이 "constructor"인 메서드 정의가 하나만 존재하고 접근자 프로퍼티 또는 제너레이터 정의가 아니도록 보장합니다.

15.7.4 Static Semantics: IsStatic

구문 지향 연산 IsStatic. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

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

구문 지향 연산 NonConstructorElements. 인수 없음. 반환값: 리스트 (요소: ClassElement Parse Nodes). 다음 생성 규칙별로 정의된다.

ClassElementList : ClassElement
  1. ClassElement의 ClassElementKind가 non-constructor-method이면, 다음을 수행합니다.
    1. « ClassElement »을 반환합니다.
  2. 새로운 빈 List를 반환합니다.
ClassElementList : ClassElementList ClassElement
  1. list를 ClassElementList의 NonConstructorElements로 둡니다.
  2. ClassElement의 ClassElementKind가 non-constructor-method이면, 다음을 수행합니다.
    1. ClassElement를 list에 추가합니다.
  3. list를 반환합니다.

15.7.6 Static Semantics: PrototypePropertyNameList

구문 지향 연산 PrototypePropertyNameList. 인수 없음. 반환값: 리스트 (요소: 프로퍼티 키). 다음 생성 규칙별로 정의된다.

ClassElementList : ClassElement
  1. propertyName을 ClassElement의 PropName으로 둡니다.
  2. propertyName이 empty이면 새로운 빈 List를 반환합니다.
  3. ClassElement의 IsStatic이 true이면 새로운 빈 List를 반환합니다.
  4. « propertyName »을 반환합니다.
ClassElementList : ClassElementList ClassElement
  1. list를 ClassElementList의 PrototypePropertyNameList로 둡니다.
  2. propertyName을 ClassElement의 PropName으로 둡니다.
  3. propertyName이 empty이면 list를 반환합니다.
  4. ClassElement의 IsStatic이 true이면 list를 반환합니다.
  5. list와 « propertyName »의 목록 연결을 반환합니다.

15.7.7 Static Semantics: AllPrivateIdentifiersValid

구문 지향 연산 AllPrivateIdentifiersValid. 인수 names (리스트 (요소: String)). 반환값: Boolean.

아래에 나열되지 않은 이 명세의 모든 문법 생성 규칙 대안은 암묵적으로 다음과 같은 AllPrivateIdentifiersValid 기본 정의를 갖습니다:

  1. 이 Parse Node의 각 자식 노드 child에 대해 다음을 수행합니다.
    1. child가 비단말 기호의 인스턴스이면, 다음을 수행합니다.
      1. 인수 names를 사용한 child의 AllPrivateIdentifiersValid가 false이면 false를 반환합니다.
  2. true를 반환합니다.
MemberExpression : MemberExpression . PrivateIdentifier
  1. names에 PrivateIdentifier의 StringValue가 포함되어 있으면, 다음을 수행합니다.
    1. 인수 names를 사용한 MemberExpression의 AllPrivateIdentifiersValid를 반환합니다.
  2. false를 반환합니다.
CallExpression : CallExpression . PrivateIdentifier
  1. names에 PrivateIdentifier의 StringValue가 포함되어 있으면, 다음을 수행합니다.
    1. 인수 names를 사용한 CallExpression의 AllPrivateIdentifiersValid를 반환합니다.
  2. false를 반환합니다.
OptionalChain : ?. PrivateIdentifier
  1. names에 PrivateIdentifier의 StringValue가 포함되어 있으면 true를 반환합니다.
  2. false를 반환합니다.
OptionalChain : OptionalChain . PrivateIdentifier
  1. names에 PrivateIdentifier의 StringValue가 포함되어 있으면, 다음을 수행합니다.
    1. 인수 names를 사용한 OptionalChain의 AllPrivateIdentifiersValid를 반환합니다.
  2. false를 반환합니다.
ClassBody : ClassElementList
  1. newNames를 names와 ClassBody의 PrivateBoundIdentifiers의 목록 연결로 둡니다.
  2. 인수 newNames를 사용한 ClassElementList의 AllPrivateIdentifiersValid를 반환합니다.
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. names에 PrivateIdentifier의 StringValue가 포함되어 있으면, 다음을 수행합니다.
    1. 인수 names를 사용한 ShiftExpression의 AllPrivateIdentifiersValid를 반환합니다.
  2. false를 반환합니다.

15.7.8 Static Semantics: PrivateBoundIdentifiers

구문 지향 연산 PrivateBoundIdentifiers. 인수 없음. 반환값: 리스트 (요소: String). 다음 생성 규칙별로 정의된다.

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementName의 PrivateBoundIdentifiers를 반환합니다.
ClassElementName : PrivateIdentifier
  1. 유일한 요소가 PrivateIdentifier의 StringValue인 List를 반환합니다.
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 새로운 빈 List를 반환합니다.
ClassElementList : ClassElementList ClassElement
  1. names1을 ClassElementList의 PrivateBoundIdentifiers로 둡니다.
  2. names2를 ClassElement의 PrivateBoundIdentifiers로 둡니다.
  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. ClassElementName의 PrivateBoundIdentifiers를 반환합니다.

15.7.9 Static Semantics: ContainsArguments

구문 지향 연산 ContainsArguments. 인수 없음. 반환값: Boolean.

아래에 나열되지 않은 이 명세의 모든 문법 생성 규칙 대안은 암묵적으로 다음과 같은 ContainsArguments 기본 정의를 갖습니다:

  1. 이 Parse Node의 각 자식 노드 child에 대해 다음을 수행합니다.
    1. child가 비단말 기호의 인스턴스이면, 다음을 수행합니다.
      1. child의 ContainsArguments가 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. ClassElementName의 ContainsArguments를 반환합니다.

15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation

구문 지향 연산 ClassFieldDefinitionEvaluation. 인수 homeObj (Object). 반환값: (정상 완료 (값: ClassFieldDefinition 레코드) 또는 중도 완료). 다음 생성 규칙별로 정의된다.

FieldDefinition : ClassElementName Initializeropt
  1. name을 ClassElementName의 ? Evaluation으로 둡니다.
  2. Initializer가 존재하면, 다음을 수행합니다.
    1. formalParamList를 생성 규칙 FormalParameters : [empty] 의 인스턴스로 둡니다.
    2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
    3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
    4. sourceText를 빈 유니코드 코드 포인트 시퀀스로 둡니다.
    5. initializer를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, Initializer, non-lexical-this, envRecord, privateEnv)로 둡니다.
    6. MakeMethod(initializer, homeObj)을 수행합니다.
    7. initializer.[[ClassFieldInitializerName]]을 name으로 설정합니다.
  3. 그렇지 않으면,
    1. initializer를 empty로 둡니다.
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer }를 반환합니다.
참고
initializer를 위해 생성된 함수는 ECMAScript 코드에서 절대로 직접 접근할 수 없습니다.

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

구문 지향 연산 ClassStaticBlockDefinitionEvaluation. 인수 homeObj (Object). 반환값: ClassStaticBlockDefinition 레코드. 다음 생성 규칙별로 정의된다.

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lexicalEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  2. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  3. sourceText를 빈 유니코드 코드 포인트 시퀀스로 둡니다.
  4. formalParams를 생성 규칙 FormalParameters : [empty] 의 인스턴스로 둡니다.
  5. bodyFunc를 OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParams, ClassStaticBlockBody, non-lexical-this, lexicalEnv, privateEnv)로 둡니다.
  6. MakeMethod(bodyFunc, homeObj)을 수행합니다.
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunc }를 반환합니다.
참고
함수 bodyFunc는 ECMAScript 코드에서 절대로 직접 접근할 수 없습니다.

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

구문 지향 연산 EvaluateClassStaticBlockBody. 인수 funcObj (ECMAScript 함수 객체). 반환값: (return 완료 또는 throw 완료). 다음 생성 규칙별로 정의된다.

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. 단언: funcObj는 ClassStaticBlockDefinitionEvaluation의 5 단계에서 생성된 합성 함수입니다.
  2. ! FunctionDeclarationInstantiation(funcObj, « »)을 수행합니다.
  3. result를 Completion(ClassStaticBlockStatementList의 Evaluation)으로 둡니다.
  4. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  5. 단언: envRecord는 Declarative Environment Record입니다.
  6. ? DisposeResources(envRecord.[[DisposableResourceStack]], result)를 수행합니다.
  7. ReturnCompletion(undefined)을 반환합니다.

15.7.13 Runtime Semantics: ClassElementEvaluation

구문 지향 연산 ClassElementEvaluation. 인수 obj (Object). 반환값: (정상 완료 (값: (ClassFieldDefinition 레코드, ClassStaticBlockDefinition 레코드, PrivateElement 또는 empty)) 또는 중도 완료). 다음 생성 규칙별로 정의된다.

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. 인수 obj를 사용한 FieldDefinition의 ? ClassFieldDefinitionEvaluation을 반환합니다.
ClassElement : MethodDefinition static MethodDefinition
  1. 인수 obj 및 false를 사용한 MethodDefinition의 ? MethodDefinitionEvaluation을 반환합니다.
ClassElement : ClassStaticBlock
  1. 인수 obj를 사용한 ClassStaticBlock의 ClassStaticBlockDefinitionEvaluation을 반환합니다.
ClassElement : ;
  1. empty를 반환합니다.

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

구문 지향 연산 ClassDefinitionEvaluation. 인수 classBinding ((String 또는 undefined)), className ((프로퍼티 키 또는 비공개 이름)) 및 sourceText (ECMAScript 소스 텍스트). 반환값: (정상 완료 (값: 함수 객체) 또는 중도 완료).

참고

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

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

이는 비공개 필드와 다릅니다. 필드 이니셜라이저는 클래스 인스턴스화 중에 예외를 던질 수 있으므로 개별 객체에는 특정 클래스의 비공개 필드 중 일부만 존재할 수 있으며, 따라서 비공개 필드는 일반적으로 개별적으로 추적해야 합니다.

다음 생성 규칙별로 정의된다.

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  2. classEnv를 NewDeclarativeEnvironment(envRecord)로 둡니다.
  3. classBinding이 undefined가 아니면, 다음을 수행합니다.
    1. ! classEnv.CreateImmutableBinding(classBinding, true)를 수행합니다.
  4. outerPrivateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  5. classPrivateEnv를 NewPrivateEnvironment(outerPrivateEnv)로 둡니다.
  6. ClassBody가 존재하면, 다음을 수행합니다.
    1. ClassBody의 PrivateBoundIdentifiers에 있는 각 String description에 대해 다음을 수행합니다.
      1. classPrivateEnv.[[Names]]에 privateName.[[Description]]이 description인 Private Name privateName이 포함되어 있으면, 다음을 수행합니다.
        1. 단언: 이는 getter/setter 쌍에 대해서만 가능합니다.
      2. 그렇지 않으면,
        1. name을 [[Description]]이 description인 새로운 Private Name으로 둡니다.
        2. name을 classPrivateEnv.[[Names]]에 추가합니다.
  7. ClassHeritage가 존재하지 않으면, 다음을 수행합니다.
    1. protoParent를 %Object.prototype%으로 둡니다.
    2. ctorParent를 %Function.prototype%으로 둡니다.
  8. 그렇지 않으면,
    1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정합니다.
    2. 참고: ClassHeritage를 평가할 때 실행 중인 실행 컨텍스트의 PrivateEnvironment는 outerPrivateEnv입니다.
    3. superclassRef를 Completion(Evaluation of ClassHeritage)으로 둡니다.
    4. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정합니다.
    5. superclass를 ? GetValue(? superclassRef)로 둡니다.
    6. superclass가 null이면, 다음을 수행합니다.
      1. protoParent를 null로 둡니다.
      2. ctorParent를 %Function.prototype%으로 둡니다.
    7. 그렇지 않고 IsConstructor(superclass)가 false이면, 다음을 수행합니다.
      1. TypeError 예외를 던집니다.
    8. 그렇지 않으면,
      1. protoParent를 ? Get(superclass, "prototype")로 둡니다.
      2. protoParent가 Object가 아니고 protoParent가 null도 아니면 TypeError 예외를 던집니다.
      3. ctorParent를 superclass로 둡니다.
  9. proto를 OrdinaryObjectCreate(protoParent)로 둡니다.
  10. ClassBody가 존재하지 않으면 ctor를 empty로 둡니다.
  11. 그렇지 않으면 ctor를 ClassBody의 ConstructorMethod로 둡니다.
  12. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 classEnv로 설정합니다.
  13. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 classPrivateEnv로 설정합니다.
  14. ctor가 empty이면, 다음을 수행합니다.
    1. defaultCtor를 매개변수가 없고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 수행하는 새로운 Abstract Closure로 둡니다:
      1. args를 [[Call]] 또는 [[Construct]]가 이 함수에 전달한 인수의 List로 둡니다.
      2. NewTarget이 undefined이면 TypeError 예외를 던집니다.
      3. ctorFunc를 활성 함수 객체로 둡니다.
      4. ctorFunc.[[ConstructorKind]]가 derived이면, 다음을 수행합니다.
        1. 참고: 이 분기는 constructor(...args) { super(...args); }와 유사하게 동작합니다. 가장 주목할 만한 차이는 앞서 언급한 ECMAScript 소스 텍스트가 %Array.prototype%의 %Symbol.iterator% 메서드를 관찰 가능하게 호출하는 반면 이 함수는 호출하지 않는다는 점입니다.
        2. func를 ! ctorFunc.[[GetPrototypeOf]]()로 둡니다.
        3. IsConstructor(func)가 false이면 TypeError 예외를 던집니다.
        4. result를 ? Construct(func, args, NewTarget)로 둡니다.
      5. 그렇지 않으면,
        1. 참고: 이 분기는 constructor() {}와 유사하게 동작합니다.
        2. result를 ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%")로 둡니다.
      6. ? InitializeInstanceElements(result, ctorFunc)를 수행합니다.
      7. NormalCompletion(result)을 반환합니다.
    2. ctorFunc를 CreateBuiltinFunction(defaultCtor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », the current Realm Record, ctorParent)로 둡니다.
  15. 그렇지 않으면,
    1. ctorInfo를 ! DefineMethod of ctor with arguments proto and ctorParent로 둡니다.
    2. ctorFunc를 ctorInfo.[[Closure]]로 둡니다.
    3. MakeClassConstructor(ctorFunc)를 수행합니다.
    4. SetFunctionName(ctorFunc, className)을 수행합니다.
  16. ctorFunc.[[SourceText]]를 sourceText로 설정합니다.
  17. MakeConstructor(ctorFunc, false, proto)를 수행합니다.
  18. ClassHeritage가 존재하면 ctorFunc.[[ConstructorKind]]를 derived로 설정합니다.
  19. ! DefineMethodProperty(proto, "constructor", ctorFunc, false)를 수행합니다.
  20. ClassBody가 존재하지 않으면 classElements를 새로운 빈 List로 둡니다.
  21. 그렇지 않으면 classElements를 ClassBody의 NonConstructorElements로 둡니다.
  22. instancePrivateMethods를 새로운 빈 List로 둡니다.
  23. staticPrivateMethods를 새로운 빈 List로 둡니다.
  24. instanceFields를 새로운 빈 List로 둡니다.
  25. staticElements를 새로운 빈 List로 둡니다.
  26. classElements의 각 ClassElement classElement에 대해 다음을 수행합니다.
    1. classElement의 IsStatic이 false이면, 다음을 수행합니다.
      1. element를 Completion(ClassElementEvaluation of classElement with argument proto)로 둡니다.
    2. 그렇지 않으면,
      1. element를 Completion(ClassElementEvaluation of classElement with argument ctorFunc)로 둡니다.
    3. element가 abrupt completion이면, 다음을 수행합니다.
      1. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정합니다.
      2. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정합니다.
      3. ? element를 반환합니다.
    4. element를 ! element로 설정합니다.
    5. element가 PrivateElement이면, 다음을 수행합니다.
      1. 단언: element.[[Kind]]는 method 또는 accessor 중 하나입니다.
      2. classElement의 IsStatic이 false이면 container를 instancePrivateMethods로 둡니다.
      3. 그렇지 않으면 container를 staticPrivateMethods로 둡니다.
      4. container에 existingElement.[[Key]]가 element.[[Key]]인 PrivateElement existingElement가 포함되어 있으면, 다음을 수행합니다.
        1. 단언: element.[[Kind]]와 existingElement.[[Kind]]는 모두 accessor입니다.
        2. element.[[Getter]]가 undefined이면, 다음을 수행합니다.
          1. combined를 PrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Getter]]: existingElement.[[Getter]], [[Setter]]: element.[[Setter]] }로 둡니다.
        3. 그렇지 않으면,
          1. combined를 PrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Getter]]: element.[[Getter]], [[Setter]]: existingElement.[[Setter]] }로 둡니다.
        4. container의 existingElement를 combined로 대체합니다.
      5. 그렇지 않으면,
        1. element를 container에 추가합니다.
    6. 그렇지 않고 element가 ClassFieldDefinition Record이면, 다음을 수행합니다.
      1. classElement의 IsStatic이 false이면 element를 instanceFields에 추가합니다.
      2. 그렇지 않으면 element를 staticElements에 추가합니다.
    7. 그렇지 않고 element가 ClassStaticBlockDefinition Record이면, 다음을 수행합니다.
      1. element를 staticElements에 추가합니다.
    8. 그렇지 않으면,
      1. 단언: element는 empty입니다.
  27. 실행 중인 실행 컨텍스트의 LexicalEnvironment를 envRecord로 설정합니다.
  28. classBinding이 undefined가 아니면, 다음을 수행합니다.
    1. ! classEnv.InitializeBinding(classBinding, ctorFunc)을 수행합니다.
  29. ctorFunc.[[PrivateMethods]]를 instancePrivateMethods로 설정합니다.
  30. ctorFunc.[[Fields]]를 instanceFields로 설정합니다.
  31. staticPrivateMethods의 각 PrivateElement method에 대해 다음을 수행합니다.
    1. ! PrivateMethodOrAccessorAdd(ctorFunc, method)를 수행합니다.
  32. staticElements의 각 요소 elementRecord에 대해 다음을 수행합니다.
    1. elementRecord가 ClassFieldDefinition Record이면, 다음을 수행합니다.
      1. result를 Completion(DefineField(ctorFunc, elementRecord))로 둡니다.
    2. 그렇지 않으면,
      1. 단언: elementRecord는 ClassStaticBlockDefinition Record입니다.
      2. result를 Completion(Call(elementRecord.[[BodyFunction]], ctorFunc))로 둡니다.
    3. result가 abrupt completion이면, 다음을 수행합니다.
      1. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정합니다.
      2. ? result를 반환합니다.
  33. 실행 중인 실행 컨텍스트의 PrivateEnvironment를 outerPrivateEnv로 설정합니다.
  34. ctorFunc를 반환합니다.

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

구문 지향 연산 BindingClassDeclarationEvaluation. 인수 없음. 반환값: (정상 완료 (값: 함수 객체) 또는 중도 완료). 다음 생성 규칙별로 정의된다.

ClassDeclaration : class BindingIdentifier ClassTail
  1. className을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 ClassDeclaration과 일치하는 소스 텍스트로 둡니다.
  3. value를 인수 className, className 및 sourceText를 사용한 ClassTail의 ? ClassDefinitionEvaluation으로 둡니다.
  4. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  5. ? InitializeBoundName(className, value, envRecord)를 수행합니다.
  6. value를 반환합니다.
ClassDeclaration : class ClassTail
  1. sourceText를 ClassDeclaration과 일치하는 소스 텍스트로 둡니다.
  2. 인수 undefined, "default" 및 sourceText를 사용한 ClassTail의 ? ClassDefinitionEvaluation을 반환합니다.
참고

ClassDeclaration : class ClassTail 은 ExportDeclaration의 일부로만 나타나며 그 바인딩 설정은 해당 생성 규칙의 평가 동작의 일부로 처리됩니다. 16.2.3.7를 참조하시기 바랍니다.

15.7.16 Runtime Semantics: 평가

ClassDeclaration : class BindingIdentifier ClassTail
  1. 이 ClassDeclaration의 ? BindingClassDeclarationEvaluation을 수행합니다.
  2. empty를 반환합니다.
참고

ClassDeclaration : class ClassTail 은 ExportDeclaration의 일부로만 나타나며 절대로 직접 평가되지 않습니다.

ClassExpression : class ClassTail
  1. sourceText를 ClassExpression과 일치하는 소스 텍스트로 둡니다.
  2. 인수 undefined, 빈 String 및 sourceText를 사용한 ClassTail의 ? ClassDefinitionEvaluation을 반환합니다.
ClassExpression : class BindingIdentifier ClassTail
  1. className을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 ClassExpression과 일치하는 소스 텍스트로 둡니다.
  3. 인수 className, className 및 sourceText를 사용한 ClassTail의 ? ClassDefinitionEvaluation을 반환합니다.
ClassElementName : PrivateIdentifier
  1. privateIdentifier를 PrivateIdentifier의 StringValue로 둡니다.
  2. privateEnvRecord를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  3. names를 privateEnvRecord.[[Names]]로 둡니다.
  4. 단언: names에는 [[Description]]이 privateIdentifier인 Private Name 요소가 정확히 하나 있습니다.
  5. privateName을 names에서 [[Description]]이 privateIdentifier인 Private 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] 참고 1

[Await] 매개변수가 존재하면 await는 AwaitExpression의 키워드로 파싱됩니다. 다음 문맥의 최상위에서는 [Await] 매개변수가 존재하지만 FunctionBody와 같은 비단말 기호에 따라 일부 문맥에서는 매개변수가 존재하지 않을 수 있습니다:

Script가 구문 목표 기호이면 [Await] 매개변수가 존재하지 않을 때 await를 식별자로 파싱할 수 있습니다. 여기에는 다음 문맥이 포함됩니다:

참고 2

YieldExpression과 달리 AwaitExpression의 피연산자를 생략하면 Syntax Error입니다. 반드시 무언가를 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

구문 지향 연산 InstantiateAsyncFunctionObject. 인수 envRecord (Environment 레코드) 및 privateEnv ((PrivateEnvironment 레코드 또는 null)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. name을 BindingIdentifier의 StringValue로 둡니다.
  2. sourceText를 AsyncFunctionDeclaration과 일치하는 소스 텍스트로 둡니다.
  3. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  4. SetFunctionName(closure, name)을 수행합니다.
  5. closure를 반환합니다.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceText를 AsyncFunctionDeclaration과 일치하는 소스 텍스트로 둡니다.
  2. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  3. SetFunctionName(closure, "default")를 수행합니다.
  4. closure를 반환합니다.

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

구문 지향 연산 InstantiateAsyncFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncFunctionExpression과 일치하는 소스 텍스트로 둡니다.
  5. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)로 둡니다.
  6. SetFunctionName(closure, name)을 수행합니다.
  7. closure를 반환합니다.
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 단언: name은 존재하지 않습니다.
  2. name을 BindingIdentifier의 StringValue로 설정합니다.
  3. outerEnv를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  4. funcEnv를 NewDeclarativeEnvironment(outerEnv)로 둡니다.
  5. ! funcEnv.CreateImmutableBinding(name, false)를 수행합니다.
  6. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  7. sourceText를 AsyncFunctionExpression과 일치하는 소스 텍스트로 둡니다.
  8. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateEnv)로 둡니다.
  9. SetFunctionName(closure, name)을 수행합니다.
  10. ! funcEnv.InitializeBinding(name, closure)를 수행합니다.
  11. closure를 반환합니다.
참고

AsyncFunctionExpression의 BindingIdentifier는 함수가 자기 자신을 재귀적으로 호출할 수 있도록 AsyncFunctionExpression의 AsyncFunctionBody 내부에서 참조할 수 있습니다. 그러나 FunctionDeclaration과 달리 AsyncFunctionExpression의 BindingIdentifier는 AsyncFunctionExpression을 둘러싸는 스코프에서 참조할 수 없으며 해당 스코프에도 영향을 주지 않습니다.

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

구문 지향 연산 EvaluateAsyncFunctionBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: return 완료. 다음 생성 규칙별로 정의된다.

AsyncFunctionBody : FunctionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둡니다.
  2. completion을 Completion(FunctionDeclarationInstantiation(funcObj, argList))으로 둡니다.
  3. completion이 비정상 완료이면, 다음을 수행합니다.
    1. ! Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)를 수행합니다.
  4. 그렇지 않으면,
    1. AsyncFunctionStart(promiseCapability, FunctionBody)를 수행합니다.
  5. ReturnCompletion(promiseCapability.[[Promise]])을 반환합니다.

15.8.5 Runtime Semantics: 평가

AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. AsyncFunctionExpression의 InstantiateAsyncFunctionExpression을 반환합니다.
UnaryExpression : CoverAwaitExpressionAndAwaitUsingDeclarationHead
  1. expr을 CoverAwaitExpressionAndAwaitUsingDeclarationHead가 포괄하는 AwaitExpression로 둡니다.
  2. expr의 ? Evaluation을 반환합니다.
AwaitExpression : await UnaryExpression
  1. exprRef를 UnaryExpression의 ? 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

구문 지향 연산 AsyncConciseBodyContainsUseStrict. 인수 없음. 반환값: Boolean. 다음 생성 규칙별로 정의된다.

AsyncConciseBody : ExpressionBody
  1. false를 반환합니다.
AsyncConciseBody : { AsyncFunctionBody }
  1. AsyncFunctionBody의 FunctionBodyContainsUseStrict를 반환합니다.

15.9.3 Runtime Semantics: EvaluateAsyncConciseBody

구문 지향 연산 EvaluateAsyncConciseBody. 인수 funcObj (ECMAScript 함수 객체) 및 argList (리스트 (요소: ECMAScript 언어 값)). 반환값: return 완료. 다음 생성 규칙별로 정의된다.

AsyncConciseBody : ExpressionBody
  1. promiseCapability를 ! NewPromiseCapability(%Promise%)로 둡니다.
  2. completion을 Completion(FunctionDeclarationInstantiation(funcObj, argList))으로 둡니다.
  3. completion이 비정상 완료이면, 다음을 수행합니다.
    1. ! Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)를 수행합니다.
  4. 그렇지 않으면,
    1. AsyncFunctionStart(promiseCapability, ExpressionBody)를 수행합니다.
  5. ReturnCompletion(promiseCapability.[[Promise]])을 반환합니다.

15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression

구문 지향 연산 InstantiateAsyncArrowFunctionExpression. 선택적 인수 name ((프로퍼티 키 또는 비공개 이름)). 반환값: ECMAScript 함수 객체. 다음 생성 규칙별로 정의된다.

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncArrowFunction과 일치하는 소스 텍스트로 둡니다.
  5. params를 AsyncArrowBindingIdentifier로 둡니다.
  6. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)로 둡니다.
  7. SetFunctionName(closure, name)을 수행합니다.
  8. closure를 반환합니다.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. name이 존재하지 않으면 name을 빈 String으로 설정합니다.
  2. envRecord를 실행 중인 실행 컨텍스트의 LexicalEnvironment로 둡니다.
  3. privateEnv를 실행 중인 실행 컨텍스트의 PrivateEnvironment로 둡니다.
  4. sourceText를 AsyncArrowFunction과 일치하는 소스 텍스트로 둡니다.
  5. head를 CoverCallExpressionAndAsyncArrowHead가 포괄하는 AsyncArrowHead로 둡니다.
  6. params를 head의 ArrowFormalParameters로 둡니다.
  7. closure를 OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)로 둡니다.
  8. SetFunctionName(closure, name)을 수행합니다.
  9. closure를 반환합니다.

15.9.5 Runtime Semantics: 평가

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

15.10 꼬리 위치 호출

15.10.1 Static Semantics: IsInTailPosition ( call )

추상 연산 IsInTailPosition. 인수 call ((a CallExpression Parse Node, a MemberExpression Parse Node 또는 an OptionalChain Parse Node)). 반환값: Boolean. 호출되면 다음 단계를 수행한다.

  1. IsStrict(call)이 false이면 false를 반환합니다.
  2. call이 FunctionBody, ConciseBody 또는 AsyncConciseBody 안에 포함되어 있지 않으면 false를 반환합니다.
  3. body를 call을 가장 가깝게 포함하는 FunctionBody, ConciseBody 또는 AsyncConciseBody로 둡니다.
  4. body가 GeneratorBody의 FunctionBody이면 false를 반환합니다.
  5. body가 AsyncFunctionBody의 FunctionBody이면 false를 반환합니다.
  6. body가 AsyncGeneratorBody의 FunctionBody이면 false를 반환합니다.
  7. body가 AsyncConciseBody이면 false를 반환합니다.
  8. 인수 call을 사용한 body의 HasCallInTailPosition 결과를 반환합니다.
참고

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

15.10.2 Static Semantics: HasCallInTailPosition

구문 지향 연산 HasCallInTailPosition. 인수 call ((a CallExpression Parse Node, a MemberExpression Parse Node 또는 an OptionalChain Parse Node)). 반환값: Boolean.

참고 1

call은 특정 소스 텍스트 범위를 나타내는 Parse Node입니다. 다음 알고리즘에서 call을 다른 Parse Node와 비교하는 것은 이들이 동일한 소스 텍스트를 나타내는지 검사하는 것입니다.

참고 2

잠재적인 꼬리 위치 호출 바로 뒤에 해당 호출 결과의 GetValue를 반환하는 동작이 있으면 역시 가능한 꼬리 위치 호출입니다. 함수 호출은 Reference Record를 반환할 수 없으므로 이러한 GetValue 연산은 항상 실제 함수 호출 결과와 동일한 값을 반환합니다.

참고 3

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

다음 생성 규칙별로 정의된다.

StatementList : StatementList StatementListItem
  1. has를 인수 call을 사용한 파생된 StatementList의 HasCallInTailPosition으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. 파생된 StatementList의 ContainsUsing이 true이면 false를 반환합니다.
  4. 인수 call을 사용한 StatementListItem의 HasCallInTailPosition을 반환합니다.
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을 사용한 첫 번째 Statement의 HasCallInTailPosition으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. 인수 call을 사용한 두 번째 Statement의 HasCallInTailPosition을 반환합니다.
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을 사용한 Statement의 HasCallInTailPosition을 반환합니다.
LabelledStatement : LabelIdentifier : LabelledItem
  1. 인수 call을 사용한 LabelledItem의 HasCallInTailPosition을 반환합니다.
ReturnStatement : return Expression ;
  1. 인수 call을 사용한 Expression의 HasCallInTailPosition을 반환합니다.
SwitchStatement : switch ( Expression ) CaseBlock
  1. 인수 call을 사용한 CaseBlock의 HasCallInTailPosition을 반환합니다.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. has를 false로 둡니다.
  2. 첫 번째 CaseClauses가 존재하면 has를 인수 call을 사용한 첫 번째 CaseClauses의 HasCallInTailPosition으로 설정합니다.
  3. has가 true이면 true를 반환합니다.
  4. has를 인수 call을 사용한 DefaultClause의 HasCallInTailPosition으로 설정합니다.
  5. has가 true이면 true를 반환합니다.
  6. 두 번째 CaseClauses가 존재하면 has를 인수 call을 사용한 두 번째 CaseClauses의 HasCallInTailPosition으로 설정합니다.
  7. has를 반환합니다.
CaseClauses : CaseClauses CaseClause
  1. has를 인수 call을 사용한 CaseClauses의 HasCallInTailPosition으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. 인수 call을 사용한 CaseClause의 HasCallInTailPosition을 반환합니다.
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList가 존재하면 인수 call을 사용한 StatementList의 HasCallInTailPosition을 반환합니다.
  2. false를 반환합니다.
TryStatement : try Block Catch
  1. 인수 call을 사용한 Catch의 HasCallInTailPosition을 반환합니다.
TryStatement : try Block Finally try Block Catch Finally
  1. 인수 call을 사용한 Finally의 HasCallInTailPosition을 반환합니다.
Catch : catch ( CatchParameter ) Block
  1. 인수 call을 사용한 Block의 HasCallInTailPosition을 반환합니다.
AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression PrivateIdentifier in ShiftExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression CoverAwaitExpressionAndAwaitUsingDeclarationHead CallExpression : SuperCall ImportCall CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier NewExpression : new NewExpression MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral
  1. false를 반환합니다.
Expression : AssignmentExpression Expression , AssignmentExpression
  1. 인수 call을 사용한 AssignmentExpression의 HasCallInTailPosition을 반환합니다.
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has를 인수 call을 사용한 첫 번째 AssignmentExpression의 HasCallInTailPosition으로 둡니다.
  2. has가 true이면 true를 반환합니다.
  3. 인수 call을 사용한 두 번째 AssignmentExpression의 HasCallInTailPosition을 반환합니다.
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. 인수 call을 사용한 BitwiseORExpression의 HasCallInTailPosition을 반환합니다.
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. 인수 call을 사용한 LogicalANDExpression의 HasCallInTailPosition을 반환합니다.
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. 인수 call을 사용한 BitwiseORExpression의 HasCallInTailPosition을 반환합니다.
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. 이 CallExpression이 call이면 true를 반환합니다.
  2. false를 반환합니다.
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. 인수 call을 사용한 OptionalChain의 HasCallInTailPosition을 반환합니다.
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. false를 반환합니다.
OptionalChain : ?. Arguments OptionalChain Arguments
  1. 이 OptionalChain이 call이면 true를 반환합니다.
  2. false를 반환합니다.
MemberExpression : MemberExpression TemplateLiteral
  1. 이 MemberExpression이 call이면 true를 반환합니다.
  2. false를 반환합니다.
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. expr을 CoverParenthesizedExpressionAndArrowParameterList가 포괄하는 ParenthesizedExpression로 둡니다.
  2. 인수 call을 사용한 expr의 HasCallInTailPosition을 반환합니다.
ParenthesizedExpression : ( Expression )
  1. 인수 call을 사용한 Expression의 HasCallInTailPosition을 반환합니다.

15.10.3 PrepareForTailCall ( )

추상 연산 PrepareForTailCall. 인수 없음. 반환값: unused. 호출되면 다음 단계를 수행한다.

  1. 단언: 현재 실행 컨텍스트는 이후 어떤 ECMAScript 코드 또는 내장 함수의 평가에도 사용되지 않습니다. 이 추상 연산 호출 이후의 Call 호출은 그러한 평가를 수행하기 전에 새로운 실행 컨텍스트를 생성하고 푸시합니다.
  2. 현재 실행 컨텍스트와 연결된 모든 리소스를 폐기합니다.
  3. unused를 반환합니다.

꼬리 위치 호출은 대상 함수를 호출하기 전에 현재 실행 중인 함수 실행 컨텍스트와 연결된 모든 일시적 내부 리소스를 해제하거나, 대상 함수를 지원하기 위해 해당 리소스를 재사용해야 합니다.

참고

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