14 ECMAScript 언어: 문장과 선언

구문

Statement[Yield, Await, Return] : BlockStatement[?Yield, ?Await, ?Return] VariableStatement[?Yield, ?Await] EmptyStatement ExpressionStatement[?Yield, ?Await] IfStatement[?Yield, ?Await, ?Return] BreakableStatement[?Yield, ?Await, ?Return] ContinueStatement[?Yield, ?Await] BreakStatement[?Yield, ?Await] [+Return] ReturnStatement[?Yield, ?Await] WithStatement[?Yield, ?Await, ?Return] LabelledStatement[?Yield, ?Await, ?Return] ThrowStatement[?Yield, ?Await] TryStatement[?Yield, ?Await, ?Return] DebuggerStatement Declaration[Yield, Await] : HoistableDeclaration[?Yield, ?Await, ~Default] ClassDeclaration[?Yield, ?Await, ~Default] LexicalDeclaration[+In, ?Yield, ?Await] HoistableDeclaration[Yield, Await, Default] : FunctionDeclaration[?Yield, ?Await, ?Default] GeneratorDeclaration[?Yield, ?Await, ?Default] AsyncFunctionDeclaration[?Yield, ?Await, ?Default] AsyncGeneratorDeclaration[?Yield, ?Await, ?Default] BreakableStatement[Yield, Await, Return] : IterationStatement[?Yield, ?Await, ?Return] SwitchStatement[?Yield, ?Await, ?Return]

14.1 문장 의미론

14.1.1 Runtime Semantics: Evaluation

HoistableDeclaration : GeneratorDeclaration AsyncFunctionDeclaration AsyncGeneratorDeclaration
  1. empty를 반환한다.
HoistableDeclaration : FunctionDeclaration
  1. FunctionDeclarationEvaluation을 ? 반환한다.
BreakableStatement : IterationStatement SwitchStatement
  1. newLabelSet을 새로운 빈 List라고 하자.
  2. 인수 newLabelSet을 사용한 this BreakableStatementLabelledEvaluation을 ? 반환한다.

14.2 블록

구문

BlockStatement[Yield, Await, Return] : Block[?Yield, ?Await, ?Return] Block[Yield, Await, Return] : { StatementList[?Yield, ?Await, ?Return]opt } StatementList[Yield, Await, Return] : StatementListItem[?Yield, ?Await, ?Return] StatementList[?Yield, ?Await, ?Return] StatementListItem[?Yield, ?Await, ?Return] StatementListItem[Yield, Await, Return] : Statement[?Yield, ?Await, ?Return] Declaration[?Yield, ?Await]

14.2.1 Static Semantics: Early Errors

Block : { StatementList }

14.2.2 Runtime Semantics: Evaluation

Block : { }
  1. empty를 반환한다.
Block : { StatementList }
  1. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  2. blockEnvNewDeclarativeEnvironment(oldEnv)라고 하자.
  3. BlockDeclarationInstantiation(StatementList, blockEnv)를 수행한다.
  4. 현재 실행 중인 execution context의 LexicalEnvironment를 blockEnv로 설정한다.
  5. blockValueCompletion(Evaluation of StatementList)라고 하자.
  6. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  7. blockValue를 반환한다.
Note 1

제어가 Block을 어떤 방식으로 떠나더라도 LexicalEnvironment는 항상 이전 상태로 복원된다.

StatementList : StatementList StatementListItem
  1. slStatementListEvaluation 결과 ?라고 하자.
  2. sCompletion(Evaluation of StatementListItem)라고 하자.
  3. UpdateEmpty(s, sl)를 반환한다.
Note 2

StatementList의 값은 StatementList 안에서 마지막으로 값을 생성하는 항목의 값이다. 예를 들어, 다음의 eval 함수 호출들은 모두 값 1을 반환한다:

eval("1;;;;;")
eval("1;{}")
eval("1;var a;")

14.2.3 BlockDeclarationInstantiation ( code, env )

The abstract operation BlockDeclarationInstantiation takes arguments code (a Parse Node) and env (a Declarative Environment Record) and returns unused. code는 블록 본문에 대응하는 Parse Node이다. env는 바인딩이 생성될 Environment Record이다.

Note

Block 또는 CaseBlock이 평가될 때 새로운 Declarative Environment Record가 생성되고, 블록에서 선언된 각 블록 스코프 변수, 상수, 함수, 또는 클래스에 대한 바인딩이 그 Environment Record 안에 구체화된다.

호출되면 다음 단계를 수행한다:

  1. declarationscodeLexicallyScopedDeclarations라고 하자.
  2. privateEnv를 현재 실행 중인 execution context의 PrivateEnvironment라고 하자.
  3. declarations의 각 요소 decl에 대해, 다음을 수행한다
    1. declBoundNames의 각 요소 dn에 대해, 다음을 수행한다
      1. declIsConstantDeclarationtrue이면,
        1. env.CreateImmutableBinding(dn, true)를 수행한다.
      2. 그렇지 않으면,
        1. Normative Optional
          호스트가 웹 브라우저이거나 또는 Block-Level Function Declaration 웹 Legacy 호환성 의미론를 지원하면,
          1. env.HasBinding(dn)이 false이면,
            1. env.CreateMutableBinding(dn, false)를 수행한다.
        2. 그렇지 않으면,
          1. env.CreateMutableBinding(dn, false)를 수행한다.
    2. declFunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration 중 하나이면,
      1. fndeclBoundNames의 유일한 요소라고 하자.
      2. fo를 인수 envprivateEnv를 사용한 declInstantiateFunctionObject라고 하자.
      3. Normative Optional
        호스트가 웹 브라우저이거나 또는 Block-Level Function Declaration 웹 Legacy 호환성 의미론를 지원하면,
        1. env 안의 fn에 대한 바인딩이 초기화되지 않은 바인딩이면,
          1. env.InitializeBinding(fn, fo)를 수행한다.
        2. 그렇지 않으면,
          1. Assert: declFunctionDeclaration이다.
          2. env.SetMutableBinding(fn, fo, false)를 수행한다.
      4. 그렇지 않으면,
        1. env.InitializeBinding(fn, fo)를 수행한다.
  4. unused를 반환한다.

14.3 선언과 변수 문장

14.3.1 Let 및 Const 선언

Note

letconst 선언은 현재 실행 중인 execution context의 LexicalEnvironment에 스코프를 가지는 변수를 정의한다. 변수들은 자신을 포함하는 Environment Record가 구체화될 때 생성되지만, 변수의 LexicalBinding이 평가되기 전까지는 어떤 방식으로도 접근할 수 없다. Initializer를 가진 LexicalBinding에 의해 정의된 변수는 변수가 생성될 때가 아니라 LexicalBinding이 평가될 때 자신의 InitializerAssignmentExpression 값을 할당받는다. let 선언 안의 LexicalBindingInitializer가 없으면, 그 변수는 LexicalBinding이 평가될 때 값 undefined를 할당받는다.

구문

LexicalDeclaration[In, Yield, Await] : LetOrConst BindingList[?In, ?Yield, ?Await] ; LetOrConst : let const BindingList[In, Yield, Await] : LexicalBinding[?In, ?Yield, ?Await] BindingList[?In, ?Yield, ?Await] , LexicalBinding[?In, ?Yield, ?Await] LexicalBinding[In, Yield, Await] : BindingIdentifier[?Yield, ?Await] Initializer[?In, ?Yield, ?Await]opt BindingPattern[?Yield, ?Await] Initializer[?In, ?Yield, ?Await]

14.3.1.1 Static Semantics: Early Errors

LexicalDeclaration : LetOrConst BindingList ; LexicalBinding : BindingIdentifier Initializeropt

14.3.1.2 Runtime Semantics: Evaluation

LexicalDeclaration : LetOrConst BindingList ;
  1. BindingListEvaluation을 ? 수행한다.
  2. empty를 반환한다.
BindingList : BindingList , LexicalBinding
  1. BindingListEvaluation을 ? 수행한다.
  2. LexicalBindingEvaluation을 ? 반환한다.
LexicalBinding : BindingIdentifier
  1. lhs를 ! ResolveBinding(StringValue of BindingIdentifier) 라고 하자.
  2. InitializeReferencedBinding(lhs, undefined)를 수행한다.
  3. empty를 반환한다.
Note

정적 의미론 규칙에 의해, 이 형태의 LexicalBindingconst 선언에서는 결코 나타나지 않음이 보장된다.

LexicalBinding : BindingIdentifier Initializer
  1. bindingIdBindingIdentifierStringValue라고 하자.
  2. lhs를 ! ResolveBinding(bindingId)라고 하자.
  3. IsAnonymousFunctionDefinition(Initializer)가 true이면,
    1. value를 인수 bindingId를 사용한 InitializerNamedEvaluation 결과 ?라고 하자.
  4. 그렇지 않으면,
    1. rhsInitializerEvaluation 결과 ?라고 하자.
    2. value를 ? GetValue(rhs)라고 하자.
  5. InitializeReferencedBinding(lhs, value)를 수행한다.
  6. empty를 반환한다.
LexicalBinding : BindingPattern Initializer
  1. rhsInitializerEvaluation 결과 ?라고 하자.
  2. value를 ? GetValue(rhs)라고 하자.
  3. env를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  4. 인수 valueenv를 사용한 BindingPatternBindingInitialization을 ? 반환한다.

14.3.2 변수 문장

Note

var 문장은 현재 실행 중인 execution context의 VariableEnvironment에 스코프를 가지는 변수를 선언한다. Var 변수는 자신을 포함하는 Environment Record가 구체화될 때 생성되며, 생성될 때 undefined로 초기화된다. 어떤 VariableEnvironment의 스코프 안에서는 동일한 BindingIdentifier가 둘 이상의 VariableDeclaration에 나타날 수 있지만, 그 선언들은 합쳐서 오직 하나의 변수만을 정의한다. Initializer를 가진 VariableDeclaration에 의해 정의된 변수는 변수가 생성될 때가 아니라 VariableDeclaration이 실행될 때 자신의 InitializerAssignmentExpression 값을 할당받는다.

구문

VariableStatement[Yield, Await] : var VariableDeclarationList[+In, ?Yield, ?Await] ; VariableDeclarationList[In, Yield, Await] : VariableDeclaration[?In, ?Yield, ?Await] VariableDeclarationList[?In, ?Yield, ?Await] , VariableDeclaration[?In, ?Yield, ?Await] VariableDeclaration[In, Yield, Await] : BindingIdentifier[?Yield, ?Await] Initializer[?In, ?Yield, ?Await]opt BindingPattern[?Yield, ?Await] Initializer[?In, ?Yield, ?Await]

14.3.2.1 Runtime Semantics: Evaluation

VariableStatement : var VariableDeclarationList ;
  1. VariableDeclarationListEvaluation을 ? 수행한다.
  2. empty를 반환한다.
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. VariableDeclarationListEvaluation을 ? 수행한다.
  2. VariableDeclarationEvaluation을 ? 반환한다.
VariableDeclaration : BindingIdentifier
  1. empty를 반환한다.
VariableDeclaration : BindingIdentifier Initializer
  1. bindingIdBindingIdentifierStringValue라고 하자.
  2. lhs를 ? ResolveBinding(bindingId)이라고 하자.
  3. IsAnonymousFunctionDefinition(Initializer)가 true이면,
    1. value를 인수 bindingId를 사용한 InitializerNamedEvaluation 결과 ?라고 하자.
  4. 그렇지 않으면,
    1. rhsInitializerEvaluation 결과 ?라고 하자.
    2. value를 ? GetValue(rhs)라고 하자.
  5. PutValue(lhs, value)를 수행한다.
  6. empty를 반환한다.
Note

VariableDeclaration이 with 문 안에 중첩되어 있고, VariableDeclaration 안의 BindingIdentifier가 with 문의 Object Environment Record의 바인딩 객체의 프로퍼티 이름과 같다면, 단계 5valueIdentifier의 VariableEnvironment 바인딩에 할당하는 대신 그 프로퍼티에 할당한다.

VariableDeclaration : BindingPattern Initializer
  1. rhsInitializerEvaluation 결과 ?라고 하자.
  2. rVal를 ? GetValue(rhs)라고 하자.
  3. 인수 rValundefined를 사용한 BindingPatternBindingInitialization을 ? 반환한다.

14.3.3 구조 분해 바인딩 패턴

구문

BindingPattern[Yield, Await] : ObjectBindingPattern[?Yield, ?Await] ArrayBindingPattern[?Yield, ?Await] ObjectBindingPattern[Yield, Await] : { } { BindingRestProperty[?Yield, ?Await] } { BindingPropertyList[?Yield, ?Await] } { BindingPropertyList[?Yield, ?Await] , BindingRestProperty[?Yield, ?Await]opt } ArrayBindingPattern[Yield, Await] : [ Elisionopt BindingRestElement[?Yield, ?Await]opt ] [ BindingElementList[?Yield, ?Await] ] [ BindingElementList[?Yield, ?Await] , Elisionopt BindingRestElement[?Yield, ?Await]opt ] BindingRestProperty[Yield, Await] : ... BindingIdentifier[?Yield, ?Await] BindingPropertyList[Yield, Await] : BindingProperty[?Yield, ?Await] BindingPropertyList[?Yield, ?Await] , BindingProperty[?Yield, ?Await] BindingElementList[Yield, Await] : BindingElisionElement[?Yield, ?Await] BindingElementList[?Yield, ?Await] , BindingElisionElement[?Yield, ?Await] BindingElisionElement[Yield, Await] : Elisionopt BindingElement[?Yield, ?Await] BindingProperty[Yield, Await] : SingleNameBinding[?Yield, ?Await] PropertyName[?Yield, ?Await] : BindingElement[?Yield, ?Await] BindingElement[Yield, Await] : SingleNameBinding[?Yield, ?Await] BindingPattern[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt SingleNameBinding[Yield, Await] : BindingIdentifier[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt BindingRestElement[Yield, Await] : ... BindingIdentifier[?Yield, ?Await] ... BindingPattern[?Yield, ?Await]

14.3.3.1 Runtime Semantics: PropertyBindingInitialization

The syntax-directed operation PropertyBindingInitialization takes arguments value (an ECMAScript language value) and environment (an Environment Record or undefined) and returns either a normal completion containing a List of property keys or an abrupt completion. 이것은 바인딩된 모든 프로퍼티 이름의 리스트를 수집한다. It is defined piecewise over the following productions:

BindingPropertyList : BindingPropertyList , BindingProperty
  1. boundNames를 인수 valueenvironment를 사용한 BindingPropertyListPropertyBindingInitialization 결과 ?라고 하자.
  2. nextNames를 인수 valueenvironment를 사용한 BindingPropertyPropertyBindingInitialization 결과 ?라고 하자.
  3. boundNamesnextNameslist-concatenation을 반환한다.
BindingProperty : SingleNameBinding
  1. nameSingleNameBindingBoundNames의 유일한 요소라고 하자.
  2. 인수 value, environment, name을 사용한 SingleNameBindingKeyedBindingInitialization을 ? 수행한다.
  3. « name »를 반환한다.
BindingProperty : PropertyName : BindingElement
  1. propertyKeyPropertyNameEvaluation 결과 ?라고 하자.
  2. 인수 value, environment, propertyKey를 사용한 BindingElementKeyedBindingInitialization을 ? 수행한다.
  3. « propertyKey »를 반환한다.

14.3.3.2 Runtime Semantics: RestBindingInitialization

The syntax-directed operation RestBindingInitialization takes arguments value (an ECMAScript language value), environment (an Environment Record or undefined), and excludedNames (a List of property keys) and returns either a normal completion containing unused or an abrupt completion. It is defined piecewise over the following productions:

BindingRestProperty : ... BindingIdentifier
  1. lhs를 ? ResolveBinding(StringValue of BindingIdentifier, environment)라고 하자.
  2. restObjOrdinaryObjectCreate(%Object.prototype%)라고 하자.
  3. CopyDataProperties(restObj, value, excludedNames)를 수행한다.
  4. environmentundefined이면, ? PutValue(lhs, restObj)를 반환한다.
  5. InitializeReferencedBinding(lhs, restObj)를 반환한다.

14.3.3.3 Runtime Semantics: KeyedBindingInitialization

The syntax-directed operation KeyedBindingInitialization takes arguments value (an ECMAScript language value), environment (an Environment Record or undefined), and propertyName (a property key) and returns either a normal completion containing unused or an abrupt completion.

Note

environmentundefined가 전달되면, 초기화 값을 할당하기 위해 PutValue 연산을 사용해야 함을 나타낸다. 이것은 non-strict 함수의 형식 매개변수 목록의 경우이다. 그 경우, 같은 이름을 가진 여러 매개변수의 가능성을 처리하기 위해 형식 매개변수 바인딩은 미리 초기화된다.

It is defined piecewise over the following productions:

BindingElement : BindingPattern Initializeropt
  1. v를 ? GetV(value, propertyName)라고 하자.
  2. Initializer가 존재하고 vundefined이면,
    1. defaultValueInitializerEvaluation 결과 ?라고 하자.
    2. v를 ? GetValue(defaultValue)로 설정한다.
  3. 인수 venvironment를 사용한 BindingPatternBindingInitialization을 ? 반환한다.
SingleNameBinding : BindingIdentifier Initializeropt
  1. bindingIdBindingIdentifierStringValue라고 하자.
  2. lhs를 ? ResolveBinding(bindingId, environment)라고 하자.
  3. v를 ? GetV(value, propertyName)라고 하자.
  4. Initializer가 존재하고 vundefined이면,
    1. IsAnonymousFunctionDefinition(Initializer)가 true이면,
      1. v를 인수 bindingId를 사용한 InitializerNamedEvaluation 결과 ?로 설정한다.
    2. 그렇지 않으면,
      1. defaultValueInitializerEvaluation 결과 ?라고 하자.
      2. v를 ? GetValue(defaultValue)로 설정한다.
  5. environmentundefined이면, ? PutValue(lhs, v)를 반환한다.
  6. InitializeReferencedBinding(lhs, v)를 반환한다.

14.4 빈 문장

구문

EmptyStatement : ;

14.4.1 Runtime Semantics: Evaluation

EmptyStatement : ;
  1. empty를 반환한다.

14.5 표현식 문장

구문

ExpressionStatement[Yield, Await] : [lookahead ∉ { {, function, async [no LineTerminator here] function, class, let [ }] Expression[+In, ?Yield, ?Await] ; Note

ExpressionStatement는 U+007B (LEFT CURLY BRACKET)로 시작할 수 없는데, 그러면 Block과 모호해질 수 있기 때문이다. ExpressionStatementfunction 또는 class 키워드로 시작할 수 없는데, 그러면 FunctionDeclaration, GeneratorDeclaration, 또는 ClassDeclaration과 모호해지기 때문이다. ExpressionStatementasync function으로 시작할 수 없는데, 그러면 AsyncFunctionDeclaration 또는 AsyncGeneratorDeclaration과 모호해지기 때문이다. ExpressionStatement는 두 토큰 시퀀스 let [로 시작할 수 없는데, 그러면 첫 번째 LexicalBindingArrayBindingPatternlet LexicalDeclaration과 모호해지기 때문이다.

14.5.1 Runtime Semantics: Evaluation

ExpressionStatement : Expression ;
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. GetValue(exprRef)를 반환한다.

14.6 if

구문

IfStatement[Yield, Await, Return] : if ( Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] else Statement[?Yield, ?Await, ?Return] if ( Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] [lookahead ≠ else] Note
[lookahead ≠ else] 선행탐색 제한은 고전적인 "dangling else" 문제를 통상적인 방식으로 해결한다. 즉, 연관된 if의 선택이 달리 모호할 때, else는 후보 if들 중 가장 가까운(가장 안쪽의) 것과 연관된다

14.6.1 Static Semantics: Early Errors

IfStatement : if ( Expression ) Statement else Statement IfStatement : if ( Expression ) Statement Note

이 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

14.6.2 Runtime Semantics: Evaluation

IfStatement : if ( Expression ) Statement else Statement
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. exprValueToBoolean(? GetValue(exprRef))라고 하자.
  3. exprValuetrue이면,
    1. stmtCompletion을 첫 번째 StatementEvaluationCompletion이라고 하자.
  4. 그렇지 않으면,
    1. stmtCompletion을 두 번째 StatementEvaluationCompletion이라고 하자.
  5. UpdateEmpty(stmtCompletion, undefined)를 반환한다.
IfStatement : if ( Expression ) Statement
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. exprValueToBoolean(? GetValue(exprRef))라고 하자.
  3. exprValuefalse이면 undefined를 반환한다.
  4. stmtCompletionStatementEvaluationCompletion이라고 하자.
  5. UpdateEmpty(stmtCompletion, undefined)를 반환한다.

14.7 반복 문

구문

IterationStatement[Yield, Await, Return] : DoWhileStatement[?Yield, ?Await, ?Return] WhileStatement[?Yield, ?Await, ?Return] ForStatement[?Yield, ?Await, ?Return] ForInOfStatement[?Yield, ?Await, ?Return]

14.7.1 의미론

14.7.1.1 LoopContinues ( completion, labelSet )

The abstract operation LoopContinues takes arguments completion (a Completion Record) and labelSet (a List of Strings) and returns a Boolean. It performs the following steps when called:

  1. completionnormal completion이면 true를 반환한다.
  2. completioncontinue completion이 아니면 false를 반환한다.
  3. completion.[[Target]]empty이면 true를 반환한다.
  4. labelSetcompletion.[[Target]]을 포함하면 true를 반환한다.
  5. false를 반환한다.
Note

IterationStatementStatement 부분 안에서는 ContinueStatement를 사용해 새로운 반복을 시작할 수 있다.

14.7.1.2 Runtime Semantics: LoopEvaluation

The syntax-directed operation LoopEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

IterationStatement : DoWhileStatement
  1. 인수 labelSet을 사용한 DoWhileStatementDoWhileLoopEvaluation을 ? 반환한다.
IterationStatement : WhileStatement
  1. 인수 labelSet을 사용한 WhileStatementWhileLoopEvaluation을 ? 반환한다.
IterationStatement : ForStatement
  1. 인수 labelSet을 사용한 ForStatementForLoopEvaluation을 ? 반환한다.
IterationStatement : ForInOfStatement
  1. 인수 labelSet을 사용한 ForInOfStatementForInOfLoopEvaluation을 ? 반환한다.

14.7.2 do-while

구문

DoWhileStatement[Yield, Await, Return] : do Statement[?Yield, ?Await, ?Return] while ( Expression[+In, ?Yield, ?Await] ) ;

14.7.2.1 Static Semantics: Early Errors

DoWhileStatement : do Statement while ( Expression ) ; Note

이 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

14.7.2.2 Runtime Semantics: DoWhileLoopEvaluation

The syntax-directed operation DoWhileLoopEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

DoWhileStatement : do Statement while ( Expression ) ;
  1. iterationResultundefined라고 하자.
  2. 반복한다,
    1. stmtResultStatementEvaluationCompletion이라고 하자.
    2. LoopContinues(stmtResult, labelSet)가 false이면, ? UpdateEmpty(stmtResult, iterationResult)를 반환한다.
    3. stmtResult.[[Value]]empty가 아니면, iterationResultstmtResult.[[Value]]로 설정한다.
    4. exprRefExpressionEvaluation 결과 ?라고 하자.
    5. exprValue를 ? GetValue(exprRef)라고 하자.
    6. ToBoolean(exprValue)가 false이면, iterationResult를 반환한다.

14.7.3 while

구문

WhileStatement[Yield, Await, Return] : while ( Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return]

14.7.3.1 Static Semantics: Early Errors

WhileStatement : while ( Expression ) Statement Note

이 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

14.7.3.2 Runtime Semantics: WhileLoopEvaluation

The syntax-directed operation WhileLoopEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

WhileStatement : while ( Expression ) Statement
  1. iterationResultundefined라고 하자.
  2. 반복한다,
    1. exprRefExpressionEvaluation 결과 ?라고 하자.
    2. exprValue를 ? GetValue(exprRef)라고 하자.
    3. ToBoolean(exprValue)가 false이면, iterationResult를 반환한다.
    4. stmtResultStatementEvaluationCompletion이라고 하자.
    5. LoopContinues(stmtResult, labelSet)가 false이면, ? UpdateEmpty(stmtResult, iterationResult)를 반환한다.
    6. stmtResult.[[Value]]empty가 아니면, iterationResultstmtResult.[[Value]]로 설정한다.

14.7.4 for

구문

ForStatement[Yield, Await, Return] : for ( [lookahead ≠ let [] Expression[~In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ) Statement[?Yield, ?Await, ?Return] for ( var VariableDeclarationList[~In, ?Yield, ?Await] ; Expression[+In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ) Statement[?Yield, ?Await, ?Return] for ( LexicalDeclaration[~In, ?Yield, ?Await] Expression[+In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ) Statement[?Yield, ?Await, ?Return]

14.7.4.1 Static Semantics: Early Errors

ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement Note

이 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement

14.7.4.2 Runtime Semantics: ForLoopEvaluation

The syntax-directed operation ForLoopEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. 첫 번째 Expression이 존재하면,
    1. exprRef를 첫 번째 ExpressionEvaluation 결과 ?라고 하자.
    2. GetValue(exprRef)를 수행한다.
  2. 두 번째 Expression이 존재하면 test를 두 번째 Expression로 하자; 그렇지 않으면 testempty로 하자.
  3. 세 번째 Expression이 존재하면 increment를 세 번째 Expression로 하자; 그렇지 않으면 incrementempty로 하자.
  4. ForBodyEvaluation(test, increment, Statement, « », labelSet)를 반환한다.
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. VariableDeclarationListEvaluation을 ? 수행한다.
  2. 첫 번째 Expression이 존재하면 test를 첫 번째 Expression로 하자; 그렇지 않으면 testempty로 하자.
  3. 두 번째 Expression이 존재하면 increment를 두 번째 Expression로 하자; 그렇지 않으면 incrementempty로 하자.
  4. ForBodyEvaluation(test, increment, Statement, « », labelSet)를 반환한다.
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  2. loopEnvNewDeclarativeEnvironment(oldEnv)라고 하자.
  3. isConstLexicalDeclarationIsConstantDeclaration이라고 하자.
  4. boundNamesLexicalDeclarationBoundNames라고 하자.
  5. boundNames의 각 요소 dn에 대해, 다음을 수행한다
    1. isConsttrue이면,
      1. loopEnv.CreateImmutableBinding(dn, true)를 수행한다.
    2. 그렇지 않으면,
      1. loopEnv.CreateMutableBinding(dn, false)를 수행한다.
  6. 현재 실행 중인 execution context의 LexicalEnvironment를 loopEnv로 설정한다.
  7. forDclLexicalDeclarationEvaluationCompletion이라고 하자.
  8. forDclabrupt completion이면,
    1. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
    2. forDcl을 반환한다.
  9. isConstfalse이면 perIterationLetsboundNames로 하자; 그렇지 않으면 perIterationLets를 새로운 빈 List로 하자.
  10. 첫 번째 Expression이 존재하면 test를 첫 번째 Expression로 하자; 그렇지 않으면 testempty로 하자.
  11. 두 번째 Expression이 존재하면 increment를 두 번째 Expression로 하자; 그렇지 않으면 incrementempty로 하자.
  12. bodyResultCompletion(ForBodyEvaluation(test, increment, Statement, perIterationLets, labelSet))라고 하자.
  13. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  14. bodyResult를 반환한다.

14.7.4.3 ForBodyEvaluation ( test, increment, stmt, perIterationBindings, labelSet )

The abstract operation ForBodyEvaluation takes arguments test (an Expression Parse Node or empty), increment (an Expression Parse Node or empty), stmt (a Statement Parse Node), perIterationBindings (a List of Strings), and labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It performs the following steps when called:

  1. iterationResultundefined라고 하자.
  2. CreatePerIterationEnvironment(perIterationBindings)를 수행한다.
  3. 반복한다,
    1. testempty가 아니면,
      1. testReftestEvaluation 결과 ?라고 하자.
      2. testValue를 ? GetValue(testRef)라고 하자.
      3. ToBoolean(testValue)가 false이면, iterationResult를 반환한다.
    2. resultEvaluation of stmtCompletion이라고 하자.
    3. LoopContinues(result, labelSet)가 false이면, ? UpdateEmpty(result, iterationResult)를 반환한다.
    4. result.[[Value]]empty가 아니면, iterationResultresult.[[Value]]로 설정한다.
    5. CreatePerIterationEnvironment(perIterationBindings)를 수행한다.
    6. incrementempty가 아니면,
      1. incRefincrementEvaluation 결과 ?라고 하자.
      2. GetValue(incRef)를 수행한다.

14.7.4.4 CreatePerIterationEnvironment ( perIterationBindings )

The abstract operation CreatePerIterationEnvironment takes argument perIterationBindings (a List of Strings) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. perIterationBindings에 요소가 하나라도 있으면,
    1. lastIterationEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
    2. outerlastIterationEnv.[[OuterEnv]]라고 하자.
    3. Assert: outernull이 아니다.
    4. thisIterationEnvNewDeclarativeEnvironment(outer) 라고 하자.
    5. perIterationBindings의 각 요소 bn에 대해, 다음을 수행한다
      1. thisIterationEnv.CreateMutableBinding(bn, false) 를 수행한다.
      2. lastValue를 ? lastIterationEnv.GetBindingValue(bn, true)라고 하자.
      3. thisIterationEnv.InitializeBinding(bn, lastValue) 를 수행한다.
    6. 현재 실행 중인 execution context의 LexicalEnvironment를 thisIterationEnv로 설정한다.
  2. unused를 반환한다.

14.7.5 for-in, for-of, for-await-of

구문

ForInOfStatement[Yield, Await, Return] : for ( [lookahead ≠ let [] LeftHandSideExpression[?Yield, ?Await] in Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] for ( var ForBinding[?Yield, ?Await] in Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] for ( ForDeclaration[?Yield, ?Await] in Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] for ( [lookahead ∉ { let, async of }] LeftHandSideExpression[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] for ( var ForBinding[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] for ( ForDeclaration[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] [+Await] for await ( [lookahead ≠ let] LeftHandSideExpression[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] [+Await] for await ( var ForBinding[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] [+Await] for await ( ForDeclaration[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] ForDeclaration[Yield, Await] : LetOrConst ForBinding[?Yield, ?Await] ForBinding[Yield, Await] : BindingIdentifier[?Yield, ?Await] BindingPattern[?Yield, ?Await] Note

이 절은 부록 B.3.5에 의해 확장된다.

14.7.5.1 Static Semantics: Early Errors

ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement Note

이 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement ForInOfStatement : for ( ForDeclaration in Expression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement

14.7.5.2 Static Semantics: IsDestructuring

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

MemberExpression : PrimaryExpression
  1. PrimaryExpressionObjectLiteral 또는 ArrayLiteral 중 하나이면 true를 반환한다.
  2. false를 반환한다.
MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression
  1. false를 반환한다.
ForDeclaration : LetOrConst ForBinding
  1. ForBindingIsDestructuring을 반환한다.
ForBinding : BindingIdentifier
  1. false를 반환한다.
ForBinding : BindingPattern
  1. true를 반환한다.
Note

이 절은 부록 B.3.5에 의해 확장된다.

14.7.5.3 Runtime Semantics: ForDeclarationBindingInitialization

The syntax-directed operation ForDeclarationBindingInitialization takes arguments value (an ECMAScript language value) and environment (an Environment Record) and returns either a normal completion containing unused or an abrupt completion. It is defined piecewise over the following productions:

ForDeclaration : LetOrConst ForBinding
  1. 인수 valueenvironment를 사용한 ForBindingBindingInitialization을 ? 반환한다.

14.7.5.4 Runtime Semantics: ForDeclarationBindingInstantiation

The syntax-directed operation ForDeclarationBindingInstantiation takes argument environment (a Declarative Environment Record) and returns unused. It is defined piecewise over the following productions:

ForDeclaration : LetOrConst ForBinding
  1. ForBindingBoundNames의 각 요소 name에 대해, 다음을 수행한다
    1. LetOrConstIsConstantDeclarationtrue이면,
      1. environment.CreateImmutableBinding(name, true)를 수행한다.
    2. 그렇지 않으면,
      1. environment.CreateMutableBinding(name, false)를 수행한다.
  2. unused를 반환한다.

14.7.5.5 Runtime Semantics: ForInOfLoopEvaluation

The syntax-directed operation ForInOfLoopEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », Expression, enumerate)라고 하자.
  2. ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, keyResult, enumerate, assignment, labelSet)를 반환한다.
ForInOfStatement : for ( var ForBinding in Expression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », Expression, enumerate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, enumerate, var-binding, labelSet)를 반환한다.
ForInOfStatement : for ( ForDeclaration in Expression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, Expression, enumerate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, enumerate, lexical-binding, labelSet)를 반환한다.
ForInOfStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », AssignmentExpression, iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, keyResult, iterate, assignment, labelSet)를 반환한다.
ForInOfStatement : for ( var ForBinding of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », AssignmentExpression, iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, iterate, var-binding, labelSet)를 반환한다.
ForInOfStatement : for ( ForDeclaration of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, AssignmentExpression, iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, iterate, lexical-binding, labelSet)를 반환한다.
ForInOfStatement : for await ( LeftHandSideExpression of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », AssignmentExpression, async-iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, keyResult, iterate, assignment, labelSet, async)를 반환한다.
ForInOfStatement : for await ( var ForBinding of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(« », AssignmentExpression, async-iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, iterate, var-binding, labelSet, async)를 반환한다.
ForInOfStatement : for await ( ForDeclaration of AssignmentExpression ) Statement
  1. keyResult를 ? ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, AssignmentExpression, async-iterate)라고 하자.
  2. ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, iterate, lexical-binding, labelSet, async) 를 반환한다.
Note

이 절은 부록 B.3.5에 의해 확장된다.

14.7.5.6 ForIn/OfHeadEvaluation ( uninitializedBoundNames, expr, iterationKind )

The abstract operation ForIn/OfHeadEvaluation takes arguments uninitializedBoundNames (a List of Strings), expr (an Expression Parse Node or an AssignmentExpression Parse Node), and iterationKind (enumerate, iterate, or async-iterate) and returns either a normal completion containing an Iterator Record or an abrupt completion. It performs the following steps when called:

  1. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  2. uninitializedBoundNames가 비어 있지 않으면,
    1. Assert: uninitializedBoundNames는 중복 항목을 포함하지 않는다.
    2. newEnvNewDeclarativeEnvironment(oldEnv)라고 하자.
    3. uninitializedBoundNames의 각 String name에 대해, 다음을 수행한다
      1. newEnv.CreateMutableBinding(name, false)를 수행한다.
    4. 현재 실행 중인 execution context의 LexicalEnvironment를 newEnv로 설정한다.
  3. exprRefexprEvaluationCompletion이라고 하자.
  4. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  5. exprValue를 ? GetValue(? exprRef)라고 하자.
  6. iterationKindenumerate이면,
    1. exprValueundefined 또는 null 중 하나이면,
      1. Completion Record { [[Type]]: break, [[Value]]: empty, [[Target]]: empty }를 반환한다.
    2. obj를 ! ToObject(exprValue)라고 하자.
    3. iteratorEnumerateObjectProperties(obj)라고 하자.
    4. nextMethod를 ! GetV(iterator, "next")라고 하자.
    5. Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false }를 반환한다.
  7. Assert: iterationKinditerate 또는 async-iterate 중 하나이다.
  8. iterationKindasync-iterate이면 iteratorKindasync로 하자.
  9. 그렇지 않으면, iteratorKindsync로 하자.
  10. GetIterator(exprValue, iteratorKind)를 반환한다.

14.7.5.7 ForIn/OfBodyEvaluation ( lhs, stmt, iteratorRecord, iterationKind, lhsKind, labelSet [ , iteratorKind ] )

The abstract operation ForIn/OfBodyEvaluation takes arguments lhs (a Parse Node), stmt (a Statement Parse Node), iteratorRecord (an Iterator Record), iterationKind (enumerate or iterate), lhsKind (assignment, var-binding, or lexical-binding), and labelSet (a List of Strings) and optional argument iteratorKind (sync or async) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It performs the following steps when called:

  1. iteratorKind가 존재하지 않으면, iteratorKindsync로 설정한다.
  2. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  3. iterationResultundefined라고 하자.
  4. destructuringlhsIsDestructuring이라고 하자.
  5. destructuringtrue이고 lhsKindassignment이면,
    1. Assert: lhsLeftHandSideExpression이다.
    2. assignmentPatternlhs가 커버하는 AssignmentPattern 이라고 하자.
  6. 반복한다,
    1. nextResult를 ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]])라고 하자.
    2. iteratorKindasync이면, nextResult를 ? Await(nextResult)로 설정한다.
    3. nextResult가 Object가 아니면, TypeError 예외를 던진다.
    4. done을 ? IteratorComplete(nextResult)라고 하자.
    5. donetrue이면, iterationResult를 반환한다.
    6. nextValue를 ? IteratorValue(nextResult)라고 하자.
    7. lhsKindassignment 또는 var-binding 중 하나이면,
      1. destructuringtrue이면,
        1. lhsKindassignment이면,
          1. status를 인수 nextValue를 사용한 assignmentPatternDestructuringAssignmentEvaluationCompletion이라고 하자.
        2. 그렇지 않으면,
          1. Assert: lhsKindvar-binding이다.
          2. Assert: lhsForBinding이다.
          3. status를 인수 nextValueundefined를 사용한 lhsBindingInitializationCompletion이라고 하자.
      2. 그렇지 않으면,
        1. lhsReflhsEvaluationCompletion이라고 하자. (반복적으로 평가될 수 있다.)
        2. lhsKindassignment이고 lhsAssignmentTargetTypeweb-compat이면, ReferenceError 예외를 던진다.
        3. lhsRefabrupt completion이면,
          1. statuslhsRef라고 하자.
        4. 그렇지 않으면,
          1. statusCompletion(PutValue(lhsRef.[[Value]], nextValue))라고 하자.
    8. 그렇지 않으면,
      1. Assert: lhsKindlexical-binding이다.
      2. Assert: lhsForDeclaration이다.
      3. iterationEnvNewDeclarativeEnvironment(oldEnv) 라고 하자.
      4. 인수 iterationEnv를 사용한 lhsForDeclarationBindingInstantiation을 수행한다.
      5. 현재 실행 중인 execution context의 LexicalEnvironment를 iterationEnv로 설정한다.
      6. destructuringtrue이면,
        1. status를 인수 nextValueiterationEnv를 사용한 lhsForDeclarationBindingInitializationCompletion 이라고 하자.
      7. 그렇지 않으면,
        1. Assert: lhs는 하나의 이름만 바인딩한다.
        2. lhsNamelhsBoundNames의 유일한 요소라고 하자.
        3. lhsRef를 ! ResolveBinding(lhsName)이라고 하자.
        4. statusCompletion(InitializeReferencedBinding(lhsRef, nextValue))라고 하자.
    9. statusabrupt completion이면,
      1. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
      2. iterationKindenumerate이면, ? status를 반환한다.
      3. Assert: iterationKinditerate이다.
      4. iteratorKindasync이면, ? AsyncIteratorClose(iteratorRecord, status)를 반환한다.
      5. IteratorClose(iteratorRecord, status)를 반환한다.
    10. resultEvaluation of stmtCompletion이라고 하자.
    11. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
    12. LoopContinues(result, labelSet)가 false이면,
      1. statusCompletion(UpdateEmpty(result, iterationResult))로 설정한다.
      2. iterationKindenumerate이면, ? status를 반환한다.
      3. Assert: iterationKinditerate이다.
      4. iteratorKindasync이면, ? AsyncIteratorClose(iteratorRecord, status)를 반환한다.
      5. IteratorClose(iteratorRecord, status)를 반환한다.
    13. result.[[Value]]empty가 아니면, iterationResultresult.[[Value]]로 설정한다.

14.7.5.8 Runtime Semantics: Evaluation

BindingIdentifier : Identifier yield await
  1. bindingIdBindingIdentifierStringValue라고 하자.
  2. ResolveBinding(bindingId)를 반환한다.

14.7.5.9 EnumerateObjectProperties ( obj )

The abstract operation EnumerateObjectProperties takes argument obj (an Object) and returns an iterator object. It performs the following steps when called:

  1. 열거 가능한 obj의 모든 String 값 키의 프로퍼티를 순회하는 next 메서드를 가진 이터레이터 객체를 반환한다. 이터레이터 객체는 ECMAScript 코드에서 직접 접근할 수 없다. 프로퍼티를 열거하는 방식과 순서는 명시되지 않지만 아래에 명시된 규칙에는 부합해야 한다.

이 이터레이터의 throwreturn 메서드는 null이며 결코 호출되지 않는다. 이 이터레이터의 next 메서드는 프로퍼티 키가 이터레이터 값으로 반환되어야 하는지를 결정하기 위해 객체 프로퍼티를 처리한다. 반환되는 프로퍼티 키에는 Symbol인 키는 포함되지 않는다. 대상 객체의 프로퍼티는 열거 도중 삭제될 수 있다. 이터레이터의 next 메서드가 처리하기 전에 삭제된 프로퍼티는 무시된다. 열거 도중 대상 객체에 새 프로퍼티가 추가되더라도, 새로 추가된 프로퍼티가 현재 진행 중인 열거에서 처리된다는 보장은 없다. 어떤 프로퍼티 이름이든 한 번의 열거에서 이터레이터의 next 메서드에 의해 최대 한 번만 반환된다.

대상 객체의 프로퍼티 열거에는 그 프로토타입, 프로토타입의 프로토타입 등도 재귀적으로 포함된다; 하지만 프로토타입의 프로퍼티는, 이터레이터의 next 메서드에 의해 이미 처리된 프로퍼티와 같은 이름을 가지면 처리되지 않는다. 프로토타입 객체의 프로퍼티가 이미 처리되었는지 결정할 때 [[Enumerable]] 속성 값은 고려되지 않는다. 프로토타입 객체의 열거 가능한 프로퍼티 이름은 그 프로토타입 객체를 인수로 전달하여 EnumerateObjectProperties를 호출함으로써 얻어져야 한다. EnumerateObjectProperties는 대상 객체의 자체 프로퍼티 키를 [[OwnPropertyKeys]] 내부 메서드를 호출하여 얻어야 한다. 대상 객체의 프로퍼티 속성은 [[GetOwnProperty]] 내부 메서드를 호출하여 얻어야 한다.

추가로, obj와 그 프로토타입 체인 안의 어떤 객체도 Proxy 이색 객체, TypedArray, 모듈 네임스페이스 이색 객체, 또는 구현이 제공한 이색 객체가 아니라면, 이터레이터는 다음 중 하나가 발생할 때까지는 CreateForInIterator(obj)가 제공하는 이터레이터처럼 동작해야 한다:

  • obj 또는 그 프로토타입 체인 안의 객체의 [[Prototype]] 내부 슬롯 값이 바뀌거나,
  • obj 또는 그 프로토타입 체인 안의 객체에서 프로퍼티가 제거되거나,
  • obj의 프로토타입 체인 안의 객체에 프로퍼티가 추가되거나, 또는
  • obj 또는 그 프로토타입 체인 안의 객체의 프로퍼티의 [[Enumerable]] 속성 값이 바뀌는 경우.
Note 1

ECMAScript 구현은 14.7.5.10.2.1의 알고리즘을 직접 구현할 필요는 없다. 앞 단락의 제약 중 하나가 위반되지 않는 한, 그 알고리즘에서 벗어나지 않는 동작을 하는 임의의 구현을 선택할 수 있다.

다음은 이 규칙들에 부합하는 ECMAScript generator 함수의 정보성 정의이다:

function* EnumerateObjectProperties(obj) {
  const visited = new Set();
  for (const key of Reflect.ownKeys(obj)) {
    if (typeof key === "symbol") continue;
    const desc = Reflect.getOwnPropertyDescriptor(obj, key);
    if (desc) {
      visited.add(key);
      if (desc.enumerable) yield key;
    }
  }
  const proto = Reflect.getPrototypeOf(obj);
  if (proto === null) return;
  for (const protoKey of EnumerateObjectProperties(proto)) {
    if (!visited.has(protoKey)) yield protoKey;
  }
}
Note 2
구현이 CreateForInIterator와 일치할 필요가 없는 이색 객체들의 목록은, 역사적으로 구현들이 그러한 경우에는 동작이 달랐고 다른 모든 경우에는 일치했기 때문에 선택되었다.

14.7.5.10 For-In 이터레이터 객체

For-In Iterator 는 특정 객체에 대한 특정한 순회를 나타내는 객체이다. For-In Iterator 객체는 ECMAScript 코드에서 직접 접근할 수 없으며; EnumerateObjectProperties의 동작을 설명하기 위해서만 존재한다.

14.7.5.10.1 CreateForInIterator ( object )

The abstract operation CreateForInIterator takes argument object (an Object) and returns a For-In Iterator. 이것은 object의 자체 및 상속된 열거 가능한 문자열 프로퍼티를 특정 순서로 순회하는 For-In Iterator 객체를 생성하는 데 사용된다. It performs the following steps when called:

  1. iteratorOrdinaryObjectCreate(%ForInIteratorPrototype%, « [[Object]], [[ObjectWasVisited]], [[VisitedKeys]], [[RemainingKeys]] »)라고 하자.
  2. iterator.[[Object]]object로 설정한다.
  3. iterator.[[ObjectWasVisited]]false로 설정한다.
  4. iterator.[[VisitedKeys]]를 새로운 빈 List로 설정한다.
  5. iterator.[[RemainingKeys]]를 새로운 빈 List로 설정한다.
  6. iterator를 반환한다.

14.7.5.10.2 %ForInIteratorPrototype% 객체

%ForInIteratorPrototype% 객체는:

  • 모든 For-In Iterator 객체가 상속하는 프로퍼티를 가진다.
  • 일반 객체이다.
  • [[Prototype]] 내부 슬롯 값이 %Iterator.prototype%이다.
  • ECMAScript 코드에서 직접 접근할 수 없다.
  • 다음 프로퍼티를 가진다:

14.7.5.10.2.1 %ForInIteratorPrototype%.next ( )

  1. iterthis 값이라고 하자.
  2. Assert: iter는 Object이다.
  3. Assert: iterFor-In Iterator 인스턴스의 모든 내부 슬롯을 가진다 (14.7.5.10.3).
  4. objectiter.[[Object]]라고 하자.
  5. 반복한다,
    1. iter.[[ObjectWasVisited]]false이면,
      1. keys를 ? object.[[OwnPropertyKeys]]()라고 하자.
      2. keys의 각 요소 key에 대해, 다음을 수행한다
        1. key가 String이면,
          1. keyiter.[[RemainingKeys]]에 추가한다.
      3. iter.[[ObjectWasVisited]]true로 설정한다.
    2. iter.[[RemainingKeys]]가 비어 있지 않은 동안, 반복한다
      1. keyiter.[[RemainingKeys]]의 첫 번째 요소라고 하자.
      2. iter.[[RemainingKeys]]에서 첫 번째 요소를 제거한다.
      3. iter.[[VisitedKeys]]key를 포함하지 않으면,
        1. desc를 ? object.[[GetOwnProperty]](key)라고 하자.
        2. descundefined가 아니면,
          1. keyiter.[[VisitedKeys]]에 추가한다.
          2. desc.[[Enumerable]]true이면, CreateIteratorResultObject(key, false)를 반환한다.
    3. object를 ? object.[[GetPrototypeOf]]()로 설정한다.
    4. iter.[[Object]]object로 설정한다.
    5. iter.[[ObjectWasVisited]]false로 설정한다.
    6. objectnull이면, CreateIteratorResultObject(undefined, true)를 반환한다.

14.7.5.10.3 For-In Iterator 인스턴스의 프로퍼티

For-In Iterator 인스턴스는 %ForInIteratorPrototype% 내재 객체로부터 프로퍼티를 상속하는 일반 객체이다. For-In Iterator 인스턴스는 처음 생성될 때 Table 33 에 나열된 내부 슬롯들을 가진다.

Table 33: Internal Slots of For-In Iterator Instances
내부 슬롯 타입 설명
[[Object]] an Object 프로퍼티가 순회되고 있는 Object 값.
[[ObjectWasVisited]] a Boolean 이 이터레이터가 [[Object]]에 대해 [[OwnPropertyKeys]]를 호출했으면 true, 아니면 false.
[[VisitedKeys]] a List of Strings 지금까지 이 이터레이터에 의해 방출된 값들.
[[RemainingKeys]] a List of Strings 현재 객체에 대해 아직 방출되지 않은 값들. 이 값들은 그 프로토타입의 프로퍼티를 순회하기 전에 방출된다 (프로토타입이 null이 아닌 경우).

14.8 continue

구문

ContinueStatement[Yield, Await] : continue ; continue [no LineTerminator here] LabelIdentifier[?Yield, ?Await] ;

14.8.1 Static Semantics: Early Errors

ContinueStatement : continue ; continue LabelIdentifier ;
  • ContinueStatementIterationStatement 안에 직접 또는 간접적으로 중첩되어 있지 않다면(단 함수 또는 static 초기화 블록 경계를 넘지 않아야 함), Syntax Error이다.

14.8.2 Runtime Semantics: Evaluation

ContinueStatement : continue ;
  1. Completion Record { [[Type]]: continue, [[Value]]: empty, [[Target]]: empty }를 반환한다.
ContinueStatement : continue LabelIdentifier ;
  1. labelLabelIdentifierStringValue라고 하자.
  2. Completion Record { [[Type]]: continue, [[Value]]: empty, [[Target]]: label }를 반환한다.

14.9 break

구문

BreakStatement[Yield, Await] : break ; break [no LineTerminator here] LabelIdentifier[?Yield, ?Await] ;

14.9.1 Static Semantics: Early Errors

BreakStatement : break ;

14.9.2 Runtime Semantics: Evaluation

BreakStatement : break ;
  1. Completion Record { [[Type]]: break, [[Value]]: empty, [[Target]]: empty }를 반환한다.
BreakStatement : break LabelIdentifier ;
  1. labelLabelIdentifierStringValue라고 하자.
  2. Completion Record { [[Type]]: break, [[Value]]: empty, [[Target]]: label }를 반환한다.

14.10 return

구문

ReturnStatement[Yield, Await] : return ; return [no LineTerminator here] Expression[+In, ?Yield, ?Await] ; Note

return 문은 함수가 실행을 중단하게 하며, 대부분의 경우 호출자에게 값을 반환한다. Expression이 생략되면 반환값은 undefined이다. 그렇지 않으면 반환값은 Expression의 값이다. return 문은 주변 문맥에 따라 실제로 호출자에게 값을 반환하지 않을 수도 있다. 예를 들어 try 블록 안에서는 return 문의 Completion Recordfinally 블록 평가 중 다른 Completion Record로 대체될 수 있다.

14.10.1 Runtime Semantics: Evaluation

ReturnStatement : return ;
  1. ReturnCompletion(undefined)를 반환한다.
ReturnStatement : return Expression ;
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. exprValue를 ? GetValue(exprRef)라고 하자.
  3. GetGeneratorKind()가 async이면, exprValue를 ? Await(exprValue)로 설정한다.
  4. ReturnCompletion(exprValue)를 반환한다.
Legacy

14.11 with

Note 1

레거시 with 문의 사용은 새로운 ECMAScript 코드에서는 권장되지 않는다. 구조 분해 대입처럼 strict mode 코드non-strict 코드 모두에서 허용되는 대안을 고려하라.

구문

WithStatement[Yield, Await, Return] : with ( Expression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return] Note 2

with 문은 계산된 객체에 대한 Object Environment Record를 현재 실행 중인 execution context의 어휘 환경에 추가한다. 그런 다음 이 확장된 어휘 환경을 사용하여 문장을 실행한다. 마지막으로 원래의 어휘 환경을 복원한다.

14.11.1 Static Semantics: Early Errors

WithStatement : with ( Expression ) Statement Note

두 번째 규칙은 B.3.1에 명시된 확장이 구현된 경우에만 적용할 필요가 있다.

14.11.2 Runtime Semantics: Evaluation

WithStatement : with ( Expression ) Statement
  1. valExpressionEvaluation 결과 ?라고 하자.
  2. obj를 ? ToObject(? GetValue(val))라고 하자.
  3. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  4. newEnvNewObjectEnvironment(obj, true, oldEnv) 라고 하자.
  5. 현재 실행 중인 execution context의 LexicalEnvironment를 newEnv로 설정한다.
  6. stmtCompletionStatementEvaluationCompletion이라고 하자.
  7. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  8. UpdateEmpty(stmtCompletion, undefined)를 반환한다.
Note

제어가 포함된 Statement를 어떤 방식으로 떠나더라도, 정상적이든 어떤 형태의 abrupt completion이나 예외에 의하든, LexicalEnvironment는 항상 이전 상태로 복원된다.

14.12 switch

구문

SwitchStatement[Yield, Await, Return] : switch ( Expression[+In, ?Yield, ?Await] ) CaseBlock[?Yield, ?Await, ?Return] CaseBlock[Yield, Await, Return] : { CaseClauses[?Yield, ?Await, ?Return]opt } { CaseClauses[?Yield, ?Await, ?Return]opt DefaultClause[?Yield, ?Await, ?Return] CaseClauses[?Yield, ?Await, ?Return]opt } CaseClauses[Yield, Await, Return] : CaseClause[?Yield, ?Await, ?Return] CaseClauses[?Yield, ?Await, ?Return] CaseClause[?Yield, ?Await, ?Return] CaseClause[Yield, Await, Return] : case Expression[+In, ?Yield, ?Await] : StatementList[?Yield, ?Await, ?Return]opt DefaultClause[Yield, Await, Return] : default : StatementList[?Yield, ?Await, ?Return]opt

14.12.1 Static Semantics: Early Errors

SwitchStatement : switch ( Expression ) CaseBlock

14.12.2 Runtime Semantics: CaseBlockEvaluation

The syntax-directed operation CaseBlockEvaluation takes argument input (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or an abrupt completion. It is defined piecewise over the following productions:

CaseBlock : { }
  1. undefined를 반환한다.
CaseBlock : { CaseClauses }
  1. resultValueundefined라고 하자.
  2. caseClausesCaseClauses 안의 CaseClause 항목들의 List로, 소스 텍스트 순서대로라고 하자.
  3. foundfalse라고 하자.
  4. caseClauses의 각 CaseClause clause에 대해, 다음을 수행한다
    1. foundfalse이면,
      1. found를 ? CaseClauseIsSelected(clause, input)로 설정한다.
    2. foundtrue이면,
      1. completionEvaluation of clauseCompletion이라고 하자.
      2. completion.[[Value]]empty가 아니면, resultValuecompletion.[[Value]]로 설정한다.
      3. completionabrupt completion이면, ? UpdateEmpty(completion, resultValue)를 반환한다.
  5. resultValue를 반환한다.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. resultValueundefined라고 하자.
  2. 첫 번째 CaseClauses가 존재하면,
    1. caseClauses를 첫 번째 CaseClauses 안의 CaseClause 항목들의 List로, 소스 텍스트 순서대로라고 하자.
  3. 그렇지 않으면,
    1. caseClauses를 새로운 빈 List라고 하자.
  4. foundfalse라고 하자.
  5. caseClauses의 각 CaseClause clause에 대해, 다음을 수행한다
    1. foundfalse이면,
      1. found를 ? CaseClauseIsSelected(clause, input)로 설정한다.
    2. foundtrue이면,
      1. completionEvaluation of clauseCompletion이라고 하자.
      2. completion.[[Value]]empty가 아니면, resultValuecompletion.[[Value]]로 설정한다.
      3. completionabrupt completion이면, ? UpdateEmpty(completion, resultValue)를 반환한다.
  6. foundInBfalse라고 하자.
  7. 두 번째 CaseClauses가 존재하면,
    1. secondCaseClauses를 두 번째 CaseClauses 안의 CaseClause 항목들의 List로, 소스 텍스트 순서대로라고 하자.
  8. 그렇지 않으면,
    1. secondCaseClauses를 새로운 빈 List라고 하자.
  9. foundfalse이면,
    1. secondCaseClauses의 각 CaseClause clause에 대해, 다음을 수행한다
      1. foundInBfalse이면,
        1. foundInB를 ? CaseClauseIsSelected(clause, input)로 설정한다.
      2. foundInBtrue이면,
        1. completionEvaluation of CaseClause clauseCompletion이라고 하자.
        2. completion.[[Value]]empty가 아니면, resultValuecompletion.[[Value]]로 설정한다.
        3. completionabrupt completion이면, ? UpdateEmpty(completion, resultValue)를 반환한다.
  10. foundInBtrue이면, resultValue를 반환한다.
  11. defaultREvaluation of DefaultClauseCompletion이라고 하자.
  12. defaultR.[[Value]]empty가 아니면, resultValuedefaultR.[[Value]]로 설정한다.
  13. defaultRabrupt completion이면, ? UpdateEmpty(defaultR, resultValue)를 반환한다.
  14. NOTE: 다음은 두 번째 CaseClauses에 대한 또 하나의 완전한 반복이다.
  15. secondCaseClauses의 각 CaseClause clause에 대해, 다음을 수행한다
    1. completionEvaluation of CaseClause clauseCompletion이라고 하자.
    2. completion.[[Value]]empty가 아니면, resultValuecompletion.[[Value]]로 설정한다.
    3. completionabrupt completion이면, ? UpdateEmpty(completion, resultValue)를 반환한다.
  16. resultValue를 반환한다.

14.12.3 CaseClauseIsSelected ( constructor, input )

The abstract operation CaseClauseIsSelected takes arguments constructor (a CaseClause Parse Node) and input (an ECMAScript language value) and returns either a normal completion containing a Boolean or an abrupt completion. 이것은 constructorinput과 일치하는지를 결정한다. It performs the following steps when called:

  1. Assert: constructor는 production CaseClause : case Expression : StatementListopt 의 인스턴스이다.
  2. exprRefconstructorExpressionEvaluation 결과 ?라고 하자.
  3. clauseSelector를 ? GetValue(exprRef)라고 하자.
  4. IsStrictlyEqual(input, clauseSelector)를 반환한다.
Note

이 연산은 constructorStatementList(있다면)를 실행하지 않는다. CaseBlock 알고리즘은 그 반환값을 사용해 어느 StatementList 부터 실행할지 결정한다.

14.12.4 Runtime Semantics: Evaluation

SwitchStatement : switch ( Expression ) CaseBlock
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. switchValue를 ? GetValue(exprRef)라고 하자.
  3. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  4. blockEnvNewDeclarativeEnvironment(oldEnv)라고 하자.
  5. BlockDeclarationInstantiation(CaseBlock, blockEnv)를 수행한다.
  6. 현재 실행 중인 execution context의 LexicalEnvironment를 blockEnv로 설정한다.
  7. blockResult를 인수 switchValue를 사용한 CaseBlockCaseBlockEvaluationCompletion이라고 하자.
  8. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  9. blockResult를 반환한다.
Note

제어가 SwitchStatement를 어떤 방식으로 떠나더라도 LexicalEnvironment는 항상 이전 상태로 복원된다.

CaseClause : case Expression :
  1. empty를 반환한다.
CaseClause : case Expression : StatementList
  1. StatementListEvaluation을 ? 반환한다.
DefaultClause : default :
  1. empty를 반환한다.
DefaultClause : default : StatementList
  1. StatementListEvaluation을 ? 반환한다.

14.13 레이블된 문

구문

LabelledStatement[Yield, Await, Return] : LabelIdentifier[?Yield, ?Await] : LabelledItem[?Yield, ?Await, ?Return] LabelledItem[Yield, Await, Return] : Statement[?Yield, ?Await, ?Return] FunctionDeclaration[?Yield, ?Await, ~Default] Note

Statement는 레이블로 접두될 수 있다. 레이블된 문은 오직 레이블된 breakcontinue 문과 함께만 사용된다. ECMAScript에는 goto 문이 없다. StatementLabelledStatement의 일부가 될 수 있고, 그것은 다시 LabelledStatement의 일부가 될 수 있으며, 이런 식으로 계속될 수 있다. 이렇게 도입된 레이블들은 개별 문장의 의미론을 설명할 때 집합적으로 “현재 레이블 집합”이라고 불린다.

14.13.1 Static Semantics: Early Errors

LabelledItem : FunctionDeclaration

14.13.2 Static Semantics: IsLabelledFunction ( stmt )

The abstract operation IsLabelledFunction takes argument stmt (a Statement Parse Node) and returns a Boolean. It performs the following steps when called:

  1. stmtLabelledStatement가 아니면, false를 반환한다.
  2. itemstmtLabelledItem이라고 하자.
  3. item LabelledItem : FunctionDeclaration 이면, true를 반환한다.
  4. subStmtitemStatement라고 하자.
  5. IsLabelledFunction(subStmt)를 반환한다.

14.13.3 Runtime Semantics: Evaluation

LabelledStatement : LabelIdentifier : LabelledItem
  1. 인수 « »를 사용한 this LabelledStatementLabelledEvaluation을 ? 반환한다.

14.13.4 Runtime Semantics: LabelledEvaluation

The syntax-directed operation LabelledEvaluation takes argument labelSet (a List of Strings) and returns either a normal completion containing either an ECMAScript language value or empty, or an abrupt completion. It is defined piecewise over the following productions:

BreakableStatement : IterationStatement
  1. stmtResult를 인수 labelSet을 사용한 IterationStatementLoopEvaluationCompletion이라고 하자.
  2. stmtResultbreak completion이면,
    1. stmtResult.[[Target]]empty이면,
      1. stmtResult.[[Value]]empty이면, stmtResultNormalCompletion(undefined)로 설정한다.
      2. 그렇지 않으면, stmtResultNormalCompletion(stmtResult.[[Value]])로 설정한다.
  3. stmtResult를 반환한다.
BreakableStatement : SwitchStatement
  1. stmtResultSwitchStatementEvaluationCompletion이라고 하자.
  2. stmtResultbreak completion이면,
    1. stmtResult.[[Target]]empty이면,
      1. stmtResult.[[Value]]empty이면, stmtResultNormalCompletion(undefined)로 설정한다.
      2. 그렇지 않으면, stmtResultNormalCompletion(stmtResult.[[Value]])로 설정한다.
  3. stmtResult를 반환한다.
Note 1

BreakableStatement는 레이블 없는 BreakStatement로 빠져나올 수 있는 문이다.

LabelledStatement : LabelIdentifier : LabelledItem
  1. labelLabelIdentifierStringValue라고 하자.
  2. newLabelSetlabelSet과 « label »의 list-concatenation 이라고 하자.
  3. stmtResult를 인수 newLabelSet을 사용한 LabelledItemLabelledEvaluationCompletion이라고 하자.
  4. stmtResultbreak completion이고 stmtResult.[[Target]]label이면,
    1. stmtResultNormalCompletion(stmtResult.[[Value]])로 설정한다.
  5. stmtResult를 반환한다.
LabelledItem : FunctionDeclaration
  1. FunctionDeclarationEvaluation을 ? 반환한다.
Statement : BlockStatement VariableStatement EmptyStatement ExpressionStatement IfStatement ContinueStatement BreakStatement ReturnStatement WithStatement ThrowStatement TryStatement DebuggerStatement
  1. StatementEvaluation을 ? 반환한다.
Note 2

Statement의 두 production만이 LabelledEvaluation에 대해 특별한 의미론을 가진다: BreakableStatementLabelledStatement이다.

14.14 throw

구문

ThrowStatement[Yield, Await] : throw [no LineTerminator here] Expression[+In, ?Yield, ?Await] ;

14.14.1 Runtime Semantics: Evaluation

ThrowStatement : throw Expression ;
  1. exprRefExpressionEvaluation 결과 ?라고 하자.
  2. exprValue를 ? GetValue(exprRef)라고 하자.
  3. exprValue를 던진다.

14.15 try

구문

TryStatement[Yield, Await, Return] : try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] try Block[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] try Block[?Yield, ?Await, ?Return] Catch[?Yield, ?Await, ?Return] Finally[?Yield, ?Await, ?Return] Catch[Yield, Await, Return] : catch ( CatchParameter[?Yield, ?Await] ) Block[?Yield, ?Await, ?Return] catch Block[?Yield, ?Await, ?Return] Finally[Yield, Await, Return] : finally Block[?Yield, ?Await, ?Return] CatchParameter[Yield, Await] : BindingIdentifier[?Yield, ?Await] BindingPattern[?Yield, ?Await] Note

try 문은 런타임 오류나 throw 문처럼 예외적인 조건이 발생할 수 있는 코드 블록을 둘러싼다. catch 절은 예외 처리 코드를 제공한다. catch 절이 예외를 포착하면, 그 CatchParameter는 그 예외에 바인딩된다.

14.15.1 Static Semantics: Early Errors

Catch : catch ( CatchParameter ) Block

14.15.2 Runtime Semantics: CatchClauseEvaluation

The syntax-directed operation CatchClauseEvaluation takes argument thrownValue (an ECMAScript language value) and returns either a normal completion containing either an ECMAScript language value or empty, or an abrupt completion. It is defined piecewise over the following productions:

Catch : catch ( CatchParameter ) Block
  1. oldEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
  2. catchEnvNewDeclarativeEnvironment(oldEnv)라고 하자.
  3. CatchParameterBoundNames의 각 요소 argName에 대해, 다음을 수행한다
    1. catchEnv.CreateMutableBinding(argName, false)를 수행한다.
  4. 현재 실행 중인 execution context의 LexicalEnvironment를 catchEnv로 설정한다.
  5. status를 인수 thrownValuecatchEnv를 사용한 CatchParameterBindingInitializationCompletion이라고 하자.
  6. statusabrupt completion이면,
    1. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
    2. status를 반환한다.
  7. blockCompletionBlockEvaluationCompletion이라고 하자.
  8. 현재 실행 중인 execution context의 LexicalEnvironment를 oldEnv로 설정한다.
  9. blockCompletion을 반환한다.
Catch : catch Block
  1. BlockEvaluation을 ? 반환한다.
Note

제어가 Block을 어떤 방식으로 떠나더라도 LexicalEnvironment는 항상 이전 상태로 복원된다.

14.15.3 Runtime Semantics: Evaluation

TryStatement : try Block Catch
  1. blockResultBlockEvaluationCompletion이라고 하자.
  2. blockResultthrow completion이면, catchResult를 인수 blockResult.[[Value]]를 사용한 CatchCatchClauseEvaluationCompletion이라고 하자.
  3. 그렇지 않으면, catchResultblockResult라고 하자.
  4. UpdateEmpty(catchResult, undefined)를 반환한다.
TryStatement : try Block Finally
  1. blockResultBlockEvaluationCompletion이라고 하자.
  2. finallyResultFinallyEvaluationCompletion이라고 하자.
  3. finallyResultnormal completion이면, finallyResultblockResult로 설정한다.
  4. UpdateEmpty(finallyResult, undefined)를 반환한다.
TryStatement : try Block Catch Finally
  1. blockResultBlockEvaluationCompletion이라고 하자.
  2. blockResultthrow completion이면, catchResult를 인수 blockResult.[[Value]]를 사용한 CatchCatchClauseEvaluationCompletion이라고 하자.
  3. 그렇지 않으면, catchResultblockResult라고 하자.
  4. finallyResultFinallyEvaluationCompletion이라고 하자.
  5. finallyResultnormal completion이면, finallyResultcatchResult로 설정한다.
  6. UpdateEmpty(finallyResult, undefined)를 반환한다.

14.16 debugger

구문

DebuggerStatement : debugger ;

14.16.1 Runtime Semantics: Evaluation

Note

DebuggerStatement를 평가하면 구현이 디버거 아래에서 실행될 때 중단점을 발생시킬 수 있다. 디버거가 존재하지 않거나 활성화되어 있지 않으면 이 문장은 관찰 가능한 효과를 가지지 않는다.

DebuggerStatement : debugger ;
  1. 구현 정의된 디버깅 기능이 사용 가능하고 활성화되어 있으면,
    1. 구현 정의된 디버깅 동작을 수행한다.
    2. 새로운 구현 정의 Completion Record를 반환한다.
  2. empty를 반환한다.