9 Executable Code and Execution Contexts

9.1 Environment Records

Environment Record는 ECMAScript code의 lexical nesting structure에 기반하여 Identifier를 특정 variable 및 function과 associate하는 것을 define하는 데 사용되는 specification type입니다. 보통 Environment Record는 FunctionDeclaration, BlockStatement 또는 TryStatementCatch clause 같은 ECMAScript code의 특정 syntactic structure와 associated됩니다. 그러한 code가 evaluate될 때마다, 그 code가 생성하는 identifier binding을 record하기 위해 새 Environment Record가 생성됩니다.

모든 Environment Record는 [[OuterEnv]] field를 가지며, 이는 null이거나 outer Environment Record에 대한 reference입니다. 이는 Environment Record value의 logical nesting을 model하는 데 사용됩니다. (inner) Environment Record의 outer reference는 inner Environment Record를 logically surround하는 Environment Record에 대한 reference입니다. 물론 outer Environment Record는 자체 outer Environment Record를 가질 수 있습니다. 하나의 Environment Record가 여러 inner Environment Record의 outer environment 역할을 할 수 있습니다. 예를 들어, FunctionDeclaration이 두 개의 nested FunctionDeclaration을 포함하면, 각 nested function의 Environment Record는 surrounding function의 current evaluation의 Environment Record를 outer Environment Record로 갖게 됩니다.

Environment Record는 순수하게 specification mechanism이며 ECMAScript implementation의 특정 artefact에 대응할 필요가 없습니다. ECMAScript program이 이러한 value에 직접 access하거나 manipulate하는 것은 불가능합니다.

9.1.1 The Environment Record Type Hierarchy

Environment RecordEnvironment Record가 abstract class이고 Declarative Environment Record, Object Environment Record, Global Environment Record라는 세 concrete subclass를 가진 simple object-oriented hierarchy에 존재하는 것으로 생각할 수 있습니다. Function Environment RecordModule Environment RecordDeclarative Environment Record의 subclass입니다.

Environment Record abstract class는 Table 15에 정의된 abstract specification method를 포함합니다. 이러한 abstract method는 각 concrete subclass에 대해 distinct concrete algorithm을 가집니다.

Table 15: Abstract Methods of Environment Records
Method Purpose Definitions
HasBinding ( name )

The abstract method HasBinding takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion.

Environment Recordname에 대한 binding을 가지는지 determine합니다.
다음 type에 concrete definition이 있습니다:
CreateMutableBinding ( name, deletable )

The abstract method CreateMutableBinding takes arguments name (a String) and deletable (a Boolean) and returns either a normal completion containing unused or a throw completion.

Environment Record 안에 새롭지만 uninitialized인 mutable binding을 생성합니다. name은 bound name의 text입니다. deletabletrue이면 binding은 subsequently deleted될 수 있습니다.
다음 type에 concrete definition이 있습니다:
CreateImmutableBinding ( name, strict )

The abstract method CreateImmutableBinding takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing unused or a throw completion.

Environment Record 안에 새롭지만 uninitialized인 immutable binding을 생성합니다. name은 bound name의 text입니다. stricttrue이면 initialized된 후 이를 set하려는 attempt는 그 binding을 reference하는 operation의 strict mode setting과 관계없이 항상 exception을 throw합니다.
다음 type에 concrete definition이 있습니다:
InitializeBinding ( name, value )

The abstract method InitializeBinding takes arguments name (a String) and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion.

Environment Record 안에 already existing하지만 uninitialized인 binding의 value를 set합니다. name은 bound name의 text입니다. value는 binding에 대한 value입니다.
다음 type에 concrete definition이 있습니다:
SetMutableBinding ( name, value, strict )

The abstract method SetMutableBinding takes arguments name (a String), value (an ECMAScript language value), and strict (a Boolean) and returns either a normal completion containing unused or a throw completion.

Environment Record 안에 already existing인 mutable binding의 value를 set합니다. name은 bound name의 text입니다. value는 binding에 대한 value입니다. stricttrue이고 binding을 set할 수 없으면, 이는 TypeError exception을 throw합니다.
다음 type에 concrete definition이 있습니다:
GetBindingValue ( name, strict )

The abstract method GetBindingValue takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion.

Environment Record에서 already existing인 binding의 value를 반환합니다. name은 bound name의 text입니다. strictstrict mode code에서 originating한 reference 또는 그 밖에 strict mode reference semantics를 require하는 reference를 identify하는 데 사용됩니다. stricttrue이고 binding이 존재하지 않으면, 이는 ReferenceError exception을 throw합니다. binding이 존재하지만 uninitialized이면 strict의 value와 관계없이 ReferenceError가 thrown됩니다.
다음 type에 concrete definition이 있습니다:
DeleteBinding ( name )

The abstract method DeleteBinding takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion.

Environment Record에서 binding을 delete합니다. name은 bound name의 text입니다. name에 대한 binding이 존재하면, 이는 binding을 remove하고 true를 반환합니다. binding이 존재하지만 remove할 수 없으면, 이는 false를 반환합니다. binding이 존재하지 않으면, 이는 true를 반환합니다.
다음 type에 concrete definition이 있습니다:
HasThisBinding ( )

The abstract method HasThisBinding takes no arguments and returns a Boolean.

Environment Recordthis binding을 establish하는지 determine합니다. establish하면 true를 반환하고 그렇지 않으면 false를 반환합니다.
다음 type에 concrete definition이 있습니다:
GetThisBinding ( )

The abstract method GetThisBinding takes no arguments and returns either a normal completion containing an ECMAScript language value or a throw completion.

Environment Recordthis binding value를 반환합니다. this binding이 initialized되지 않았으면 ReferenceError를 throw합니다.
다음 type에 concrete definition이 있습니다:
HasSuperBinding ( )

The abstract method HasSuperBinding takes no arguments and returns a Boolean.

Environment Recordsuper method binding을 establish하는지 determine합니다. establish하면 true를 반환하고 그렇지 않으면 false를 반환합니다. true를 반환하면 Environment RecordFunction Environment Record임을 imply하지만, reverse implication은 성립하지 않습니다.
다음 type에 concrete definition이 있습니다:
WithBaseObject ( )

The abstract method WithBaseObject takes no arguments and returns an Object or undefined.

Environment Recordwith statement와 associated되면, with object를 반환합니다. 그렇지 않으면 undefined를 반환합니다.
다음 type에 concrete definition이 있습니다:

9.1.1.1 Declarative Environment Records

Declarative Environment Record는 variable, constant, let, class, module, import 및/또는 function declaration을 포함하는 ECMAScript program scope와 associated됩니다. Declarative Environment Record는 그 scope 안에 contained된 declaration이 정의하는 identifier의 set을 bind합니다.

모든 Declarative Environment Record에는 DisposableResource 레코드List를 포함하는 [[DisposableResourceStack]] 필드도 있다. 이 목록의 요소는 Environment Record를 구성한 Evaluation 단계가 완료되었을 때 폐기되어야 하는 using 선언과 await using 선언에 의해 추적된다.

9.1.1.1.1 HasBinding ( name )

The HasBinding concrete method of a Declarative Environment Record envRecord takes argument name (a String) and returns a normal completion containing a Boolean. argument identifier가 record에 의해 bound된 identifier 중 하나인지 determine합니다. It performs the following steps when called:

  1. envRecordname에 대한 binding을 가지면, true를 반환한다.
  2. false를 반환한다.

9.1.1.1.2 CreateMutableBinding ( name, deletable )

The CreateMutableBinding concrete method of a Declarative Environment Record envRecord takes arguments name (a String) and deletable (a Boolean) and returns a normal completion containing unused. uninitialized인 name name에 대한 새 mutable binding을 생성합니다. 이 Environment Record 안에는 name에 대한 binding이 already exist하지 않아야 합니다. deletabletrue이면, 새 binding은 deletion subject로 marked됩니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 binding을 already have하지 않는다.
  2. envRecord 안에 name에 대한 mutable binding을 생성하고 그것이 uninitialized임을 record한다. deletabletrue이면, newly created binding이 subsequent DeleteBinding call에 의해 deleted될 수 있음을 record한다.
  3. unused를 반환한다.

9.1.1.1.3 CreateImmutableBinding ( name, strict )

The CreateImmutableBinding concrete method of a Declarative Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns a normal completion containing unused. uninitialized인 name name에 대한 새 immutable binding을 생성합니다. 이 Environment Record 안에는 name에 대한 binding이 already exist하지 않아야 합니다. stricttrue이면, 새 binding은 strict binding으로 marked됩니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 binding을 already have하지 않는다.
  2. envRecord 안에 name에 대한 immutable binding을 생성하고 그것이 uninitialized임을 record한다. stricttrue이면, newly created binding이 strict binding임을 record한다.
  3. unused를 반환한다.

9.1.1.1.4 InitializeBinding ( name, value )

The InitializeBinding concrete method of a Declarative Environment Record envRecord takes arguments name (a String) and value (an ECMAScript language value) and returns a normal completion containing unused. name이 name인 identifier의 current binding의 bound value를 value value로 set하는 데 사용됩니다. name에 대한 uninitialized binding이 already exist해야 합니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 uninitialized binding을 가져야 한다.
  2. envRecord 안의 name에 대한 bound value를 value로 설정한다.
  3. envRecord 안의 name에 대한 binding이 initialized되었음을 Record한다.
  4. unused를 반환한다.

9.1.1.1.5 SetMutableBinding ( name, value, strict )

The SetMutableBinding concrete method of a Declarative Environment Record envRecord takes arguments name (a String), value (an ECMAScript language value), and strict (a Boolean) and returns either a normal completion containing unused or a throw completion. name이 name인 identifier의 current binding의 bound value를 value value로 change하려고 attempt합니다. name에 대한 binding은 normally already exist하지만, rare case에는 그렇지 않을 수 있습니다. binding이 immutable binding이면 stricttrue일 때 TypeError가 thrown됩니다. It performs the following steps when called:

  1. envRecordname에 대한 binding을 가지지 않으면, 다음을 수행한다.
    1. stricttrue이면, ReferenceError exception을 throw한다.
    2. envRecord.CreateMutableBinding(name, true)를 수행한다.
    3. envRecord.InitializeBinding(name, value)를 수행한다.
    4. unused를 반환한다.
  2. envRecord 안의 name에 대한 binding이 strict binding이면, stricttrue로 설정한다.
  3. envRecord 안의 name에 대한 binding이 아직 initialized되지 않았으면, 다음을 수행한다.
    1. ReferenceError exception을 throw한다.
  4. 그렇지 않고 envRecord 안의 name에 대한 binding이 mutable binding이면, 다음을 수행한다.
    1. 그 bound value를 value로 change한다.
  5. 그렇지 않으면,
    1. Assert: 이는 immutable binding의 value를 change하려는 attempt이다.
    2. stricttrue이면, TypeError exception을 throw한다.
  6. unused를 반환한다.
Note

step 1에서 missing binding을 result하는 ECMAScript code의 example은 다음과 같습니다:

function f() { eval("var x; x = (delete x, 0);"); }

9.1.1.1.6 GetBindingValue ( name, strict )

The GetBindingValue concrete method of a Declarative Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion. name이 name인 bound identifier의 value를 반환합니다. binding이 존재하지만 uninitialized이면 strict의 value와 관계없이 ReferenceError가 thrown됩니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 binding을 가진다.
  2. envRecord 안의 name에 대한 binding이 uninitialized binding이면, ReferenceError exception을 throw한다.
  3. envRecord 안에서 현재 name에 bound된 value를 반환한다.

9.1.1.1.7 DeleteBinding ( name )

The DeleteBinding concrete method of a Declarative Environment Record envRecord takes argument name (a String) and returns a normal completion containing a Boolean. deletion subject로 명시적으로 designated된 binding만 delete할 수 있습니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 binding을 가진다.
  2. envRecord 안의 name에 대한 binding을 deleted할 수 없으면, false를 반환한다.
  3. envRecord에서 name에 대한 binding을 remove한다.
  4. true를 반환한다.

9.1.1.1.8 HasThisBinding ( )

The HasThisBinding concrete method of a Declarative Environment Record envRecord takes no arguments and returns false. It performs the following steps when called:

  1. false를 반환한다.
Note

regular Declarative Environment Record(즉, Function Environment RecordModule Environment Record도 아닌 것)는 this binding을 제공하지 않습니다.

9.1.1.1.9 GetThisBinding ( )

Declarative Environment RecordGetThisBinding concrete method는 이 명세 안에서 결코 사용되지 않습니다.

9.1.1.1.10 HasSuperBinding ( )

The HasSuperBinding concrete method of a Declarative Environment Record envRecord takes no arguments and returns false. It performs the following steps when called:

  1. false를 반환한다.
Note

regular Declarative Environment Record(즉, Function Environment RecordModule Environment Record도 아닌 것)는 super binding을 제공하지 않습니다.

9.1.1.1.11 WithBaseObject ( )

The WithBaseObject concrete method of a Declarative Environment Record envRecord takes no arguments and returns undefined. It performs the following steps when called:

  1. undefined를 반환한다.

9.1.1.2 Object Environment Records

Object Environment Record는 그 binding object라고 불리는 object와 associated됩니다. Object Environment Record는 그 binding object의 property name에 직접 corresponding하는 string identifier name의 set을 bind합니다. IdentifierName form의 string이 아닌 property key는 bound identifier의 set에 포함되지 않습니다. own property와 inherited property는 [[Enumerable]] attribute의 setting과 관계없이 set에 포함됩니다. property는 object에서 dynamically added되고 deleted될 수 있으므로, Object Environment Record에 의해 bound된 identifier의 set은 property를 add하거나 delete하는 모든 operation의 side-effect로 potentially change될 수 있습니다. 그러한 side-effect의 결과로 created되는 binding은 corresponding property의 Writable attribute가 false이더라도 mutable binding으로 considered됩니다. Immutable binding은 Object Environment Record에는 존재하지 않습니다.

with statement(14.11)에 대해 created된 Object Environment Record는 function call에서 사용하기 위한 implicit this value로 그 binding object를 제공할 수 있습니다. 이 capability는 Boolean [[IsWithEnvironment]] field에 의해 controlled됩니다.

Object Environment Record는 Table 16에 listed된 additional state field를 가집니다.

Table 16: Additional Fields of Object Environment Records
Field Name Value Meaning
[[BindingObject]] Object Environment Record의 binding object입니다.
[[IsWithEnvironment]] Boolean Environment Recordwith statement에 대해 created되었는지 여부를 나타냅니다.

9.1.1.2.1 HasBinding ( name )

The HasBinding concrete method of an Object Environment Record envRecord takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion. associated binding object가 name이라는 name의 property를 가지는지 determine합니다. It performs the following steps when called:

  1. bindingObjenvRecord.[[BindingObject]]로 둔다.
  2. foundBinding을 ? HasProperty(bindingObj, name)으로 둔다.
  3. foundBindingfalse이면, false를 반환한다.
  4. envRecord.[[IsWithEnvironment]]false이면, true를 반환한다.
  5. unscopables를 ? Get(bindingObj, %Symbol.unscopables%)로 둔다.
  6. unscopables가 Object이면, 다음을 수행한다.
    1. blockedToBoolean(? Get(unscopables, name))으로 둔다.
    2. blockedtrue이면, false를 반환한다.
  7. true를 반환한다.

9.1.1.2.2 CreateMutableBinding ( name, deletable )

The CreateMutableBinding concrete method of an Object Environment Record envRecord takes arguments name (a String) and deletable (a Boolean) and returns either a normal completion containing unused or a throw completion. Environment Record의 associated binding object 안에 name이라는 name의 property를 생성하고 이를 value undefined로 initialize합니다. deletabletrue이면, 새 property의 [[Configurable]] attribute는 true로 set됩니다. 그렇지 않으면 false로 set됩니다. It performs the following steps when called:

  1. bindingObjenvRecord.[[BindingObject]]로 둔다.
  2. DefinePropertyOrThrow(bindingObj, name, PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: deletable })를 수행한다.
  3. unused를 반환한다.
Note

Normally envRecordname에 대한 binding을 가지지 않지만, 만약 가진다면 DefinePropertyOrThrow의 semantics는 existing binding이 replaced되거나 shadowed되게 하거나 abrupt completion을 returned하게 할 수 있습니다.

9.1.1.2.3 CreateImmutableBinding ( name, strict )

Object Environment RecordCreateImmutableBinding concrete method는 이 명세 안에서 결코 사용되지 않습니다.

9.1.1.2.4 InitializeBinding ( name, value )

The InitializeBinding concrete method of an Object Environment Record envRecord takes arguments name (a String) and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. name이 name인 identifier의 current binding의 bound value를 value value로 set하는 데 사용됩니다. It performs the following steps when called:

  1. envRecord.SetMutableBinding(name, value, false)를 수행한다.
  2. unused를 반환한다.
Note

이 명세에서 Object Environment Record에 대한 CreateMutableBinding의 모든 use는 즉시 같은 name에 대한 InitializeBinding call을 뒤따릅니다. 따라서 이 명세는 Object Environment Record 안의 binding의 initialization state를 명시적으로 track하지 않습니다.

9.1.1.2.5 SetMutableBinding ( name, value, strict )

The SetMutableBinding concrete method of an Object Environment Record envRecord takes arguments name (a String), value (an ECMAScript language value), and strict (a Boolean) and returns either a normal completion containing unused or a throw completion. Environment Record의 associated binding object's property 중 name이 name인 것의 value를 value value로 set하려고 attempt합니다. name이라는 name의 property는 normally already exist하지만, 존재하지 않거나 현재 writable하지 않으면 error handling은 strict에 의해 determined됩니다. It performs the following steps when called:

  1. bindingObjenvRecord.[[BindingObject]]로 둔다.
  2. stillExists를 ? HasProperty(bindingObj, name)으로 둔다.
  3. stillExistsfalse이고 stricttrue이면, ReferenceError exception을 throw한다.
  4. Set(bindingObj, name, value, strict)를 수행한다.
  5. unused를 반환한다.

9.1.1.2.6 GetBindingValue ( name, strict )

The GetBindingValue concrete method of an Object Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion. associated binding object's property 중 name이 name인 것의 value를 반환합니다. property는 already exist해야 하지만, 존재하지 않으면 result는 strict에 depend합니다. It performs the following steps when called:

  1. bindingObjenvRecord.[[BindingObject]]로 둔다.
  2. value를 ? HasProperty(bindingObj, name)으로 둔다.
  3. valuefalse이면, 다음을 수행한다.
    1. strictfalse이면, undefined를 반환한다.
    2. ReferenceError exception을 throw한다.
  4. Get(bindingObj, name)을 반환한다.

9.1.1.2.7 DeleteBinding ( name )

The DeleteBinding concrete method of an Object Environment Record envRecord takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion. environment object의 property에 대응하고 [[Configurable]] attribute의 value가 true인 binding만 delete할 수 있습니다. It performs the following steps when called:

  1. bindingObjenvRecord.[[BindingObject]]로 둔다.
  2. bindingObj.[[Delete]](name)를 반환한다.

9.1.1.2.8 HasThisBinding ( )

The HasThisBinding concrete method of an Object Environment Record envRecord takes no arguments and returns false. It performs the following steps when called:

  1. false를 반환한다.
Note

Object Environment Recordthis binding을 제공하지 않습니다.

9.1.1.2.9 GetThisBinding ( )

Object Environment RecordGetThisBinding concrete method는 이 명세 안에서 결코 사용되지 않습니다.

9.1.1.2.10 HasSuperBinding ( )

The HasSuperBinding concrete method of an Object Environment Record envRecord takes no arguments and returns false. It performs the following steps when called:

  1. false를 반환한다.
Note

Object Environment Recordsuper binding을 제공하지 않습니다.

9.1.1.2.11 WithBaseObject ( )

The WithBaseObject concrete method of an Object Environment Record envRecord takes no arguments and returns an Object or undefined. It performs the following steps when called:

  1. envRecord.[[IsWithEnvironment]]true이면, envRecord.[[BindingObject]]를 반환한다.
  2. undefined를 반환한다.

9.1.1.3 Function Environment Records

Function Environment Record는 function의 top-level scope를 represent하는 데 사용되는 Declarative Environment Record이며, function이 ArrowFunction function이나 AsyncArrowFunction function이 아니면 this binding을 제공합니다. function이 ArrowFunction function이나 AsyncArrowFunction function이 아니고 super를 reference하면, 그 Function Environment Record는 function 내부에서 super method invocation을 수행하는 데 사용되는 state도 포함합니다.

Function Environment Record는 Table 17에 listed된 additional state field를 가집니다.

Table 17: Additional Fields of Function Environment Records
Field Name Value Meaning
[[ThisValue]] ECMAScript language value 이는 function의 이 invocation에 사용되는 this value입니다.
[[ThisBindingStatus]] lexical, initialized, or uninitialized value가 lexical이면, 이는 ArrowFunction 또는 AsyncArrowFunction이며 local this value를 가지지 않습니다.
[[FunctionObject]] ECMAScript function object 그 invocation으로 인해 이 Environment Record가 created된 function object입니다.
[[NewTarget]] a constructor or undefined Environment Record[[Construct]] internal method에 의해 created되었다면, [[NewTarget]][[Construct]] newTarget parameter의 value입니다. 그렇지 않으면 그 value는 undefined입니다.

Function Environment Record는 Table 15에 listed된 모든 Declarative Environment Record method를 support하며, HasThisBinding, GetThisBinding, HasSuperBinding을 제외한 모든 method에 대해 같은 specification을 share합니다.

9.1.1.3.1 BindThisValue ( envRecord, value )

The abstract operation BindThisValue takes arguments envRecord (a Function Environment Record) and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. envRecord.[[ThisValue]]를 set하고 그것이 initialized되었음을 record합니다. It performs the following steps when called:

  1. Assert: envRecord.[[ThisBindingStatus]]lexical이 아니다.
  2. envRecord.[[ThisBindingStatus]]initialized이면, ReferenceError exception을 throw한다.
  3. envRecord.[[ThisValue]]value로 설정한다.
  4. envRecord.[[ThisBindingStatus]]initialized로 설정한다.
  5. unused를 반환한다.

9.1.1.3.2 HasThisBinding ( )

The HasThisBinding concrete method of a Function Environment Record envRecord takes no arguments and returns a Boolean. It performs the following steps when called:

  1. envRecord.[[ThisBindingStatus]]lexical이면, false를 반환한다.
  2. true를 반환한다.

9.1.1.3.3 GetThisBinding ( )

The GetThisBinding concrete method of a Function Environment Record envRecord takes no arguments and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. Assert: envRecord.[[ThisBindingStatus]]lexical이 아니다.
  2. envRecord.[[ThisBindingStatus]]uninitialized이면, ReferenceError exception을 throw한다.
  3. envRecord.[[ThisValue]]를 반환한다.

9.1.1.3.4 HasSuperBinding ( )

The HasSuperBinding concrete method of a Function Environment Record envRecord takes no arguments and returns a Boolean. It performs the following steps when called:

  1. envRecord.[[ThisBindingStatus]]lexical이면, false를 반환한다.
  2. envRecord.[[FunctionObject]].[[HomeObject]]undefined이면, false를 반환한다.
  3. true를 반환한다.

9.1.1.3.5 GetSuperBase ( envRecord )

The abstract operation GetSuperBase takes argument envRecord (a Function Environment Record) and returns an Object, null, or undefined. envRecord에 bound된 super property access의 base인 object를 반환합니다. value undefined는 그러한 access가 runtime error를 produce함을 나타냅니다. It performs the following steps when called:

  1. homeenvRecord.[[FunctionObject]].[[HomeObject]]로 둔다.
  2. homeundefined이면, undefined를 반환한다.
  3. Assert: homeordinary object이다.
  4. home.[[GetPrototypeOf]]()를 반환한다.

9.1.1.4 Global Environment Records

Global Environment Record는 common realm에서 processed되는 모든 ECMAScript Script element가 shared하는 outer most scope를 represent하는 데 사용됩니다. Global Environment Record는 built-in global(clause 19), global object의 property, 그리고 Script 안에서 occur하는 모든 top-level declaration(8.2.11, 8.2.13)에 대한 binding을 제공합니다.

Global Environment Record는 logically single record이지만, Object Environment RecordDeclarative Environment Record를 encapsulate하는 composite로 specified됩니다. Object Environment Record는 associated Realm Recordglobal object를 base object로 가집니다. 이 global object는 Global Environment Record의 GetThisBinding concrete method가 반환하는 value입니다. Global Environment Record의 Object Environment Record component는 모든 built-in global(clause 19) 및 global code 안에 contained된 FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration 또는 VariableStatement에 의해 introduced된 모든 binding을 포함합니다. global code 안의 다른 모든 ECMAScript declaration에 대한 binding은 Global Environment Record의 Declarative Environment Record component에 포함됩니다.

Property는 global object 위에 직접 created될 수 있습니다. 따라서 Global Environment Record의 Object Environment Record component는 FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration 또는 VariableDeclaration declaration에 의해 explicitly created된 binding과 global object의 property로 implicitly created된 binding을 모두 포함할 수 있습니다.

Global Environment Record는 Table 18에 listed된 additional field를 가집니다.

Table 18: Additional Fields of Global Environment Records
Field Name Value Meaning
[[ObjectRecord]] Object Environment Record Binding object는 global object입니다. 이는 associated realm에 대한 global code 안의 FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration, VariableDeclaration binding뿐 아니라 global built-in binding도 포함합니다.
[[GlobalThisValue]] Object global scope에서 this에 의해 returned되는 value입니다. Host는 어떤 ECMAScript Object value든 provide할 수 있습니다.
[[DeclarativeRecord]] Declarative Environment Record associated realm code에 대한 global code 안의 모든 declaration에 대한 binding을 Contains하지만, FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration, VariableDeclaration binding은 제외합니다.

9.1.1.4.1 HasBinding ( name )

The HasBinding concrete method of a Global Environment Record envRecord takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion. argument identifier가 record에 의해 bound된 identifier 중 하나인지 determine합니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, true를 반환한다.
  3. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  4. objRecord.HasBinding(name)을 반환한다.

9.1.1.4.2 CreateMutableBinding ( name, deletable )

The CreateMutableBinding concrete method of a Global Environment Record envRecord takes arguments name (a String) and deletable (a Boolean) and returns either a normal completion containing unused or a throw completion. uninitialized인 name name에 대한 새 mutable binding을 생성합니다. binding은 associated DeclarativeRecord 안에 created됩니다. name에 대한 binding은 DeclarativeRecord 안에 already exist하지 않아야 합니다. deletabletrue이면, 새 binding은 deletion subject로 marked됩니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, TypeError exception을 throw한다.
  3. declRecord.CreateMutableBinding(name, deletable)를 반환한다.

9.1.1.4.3 CreateImmutableBinding ( name, strict )

The CreateImmutableBinding concrete method of a Global Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing unused or a throw completion. uninitialized인 name name에 대한 새 immutable binding을 생성합니다. 이 Environment Record 안에는 name에 대한 binding이 already exist하지 않아야 합니다. stricttrue이면, 새 binding은 strict binding으로 marked됩니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, TypeError exception을 throw한다.
  3. declRecord.CreateImmutableBinding(name, strict)를 반환한다.

9.1.1.4.4 InitializeBinding ( name, value )

The InitializeBinding concrete method of a Global Environment Record envRecord takes arguments name (a String) and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. name이 name인 identifier의 current binding의 bound value를 value value로 set하는 데 사용됩니다. name에 대한 uninitialized binding이 already exist해야 합니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, 다음을 수행한다.
    1. declRecord.InitializeBinding(name, value)를 반환한다.
  3. Assert: binding이 존재한다면, 그것은 Object Environment Record 안에 있어야 한다.
  4. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  5. objRecord.InitializeBinding(name, value)를 반환한다.

9.1.1.4.5 SetMutableBinding ( name, value, strict )

The SetMutableBinding concrete method of a Global Environment Record envRecord takes arguments name (a String), value (an ECMAScript language value), and strict (a Boolean) and returns either a normal completion containing unused or a throw completion. name이 name인 identifier의 current binding의 bound value를 value value로 change하려고 attempt합니다. binding이 immutable binding이고 stricttrue이면, TypeError가 thrown됩니다. name이라는 binding은 normally already exist하지만, 존재하지 않거나 currently writable하지 않으면 error handling은 strict에 의해 determined됩니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, 다음을 수행한다.
    1. declRecord.SetMutableBinding(name, value, strict)를 반환한다.
  3. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  4. objRecord.SetMutableBinding(name, value, strict)를 반환한다.

9.1.1.4.6 GetBindingValue ( name, strict )

The GetBindingValue concrete method of a Global Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion. name이 name인 bound identifier의 value를 반환합니다. binding이 uninitialized binding이면, ReferenceError exception을 throw합니다. name이라는 binding은 normally already exist하지만, 존재하지 않거나 currently writable하지 않으면 error handling은 strict에 의해 determined됩니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, 다음을 수행한다.
    1. declRecord.GetBindingValue(name, strict)를 반환한다.
  3. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  4. objRecord.GetBindingValue(name, strict)를 반환한다.

9.1.1.4.7 DeleteBinding ( name )

The DeleteBinding concrete method of a Global Environment Record envRecord takes argument name (a String) and returns either a normal completion containing a Boolean or a throw completion. deletion subject로 명시적으로 designated된 binding만 delete할 수 있습니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)이 true이면, 다음을 수행한다.
    1. declRecord.DeleteBinding(name)를 반환한다.
  3. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  4. globalObjobjRecord.[[BindingObject]]로 둔다.
  5. existingProperty를 ? HasOwnProperty(globalObj, name)로 둔다.
  6. existingPropertytrue이면, 다음을 수행한다.
    1. objRecord.DeleteBinding(name)를 반환한다.
  7. true를 반환한다.

9.1.1.4.8 HasThisBinding ( )

The HasThisBinding concrete method of a Global Environment Record envRecord takes no arguments and returns true. It performs the following steps when called:

  1. true를 반환한다.
Note

Global Environment Record는 항상 this binding을 제공합니다.

9.1.1.4.9 GetThisBinding ( )

The GetThisBinding concrete method of a Global Environment Record envRecord takes no arguments and returns a normal completion containing an Object. It performs the following steps when called:

  1. envRecord.[[GlobalThisValue]]를 반환한다.

9.1.1.4.10 HasSuperBinding ( )

The HasSuperBinding concrete method of a Global Environment Record envRecord takes no arguments and returns false. It performs the following steps when called:

  1. false를 반환한다.
Note

Global Environment Recordsuper binding을 제공하지 않습니다.

9.1.1.4.11 WithBaseObject ( )

The WithBaseObject concrete method of a Global Environment Record envRecord takes no arguments and returns undefined. It performs the following steps when called:

  1. undefined를 반환한다.

9.1.1.4.12 HasLexicalDeclaration ( envRecord, name )

The abstract operation HasLexicalDeclaration takes arguments envRecord (a Global Environment Record) and name (a String) and returns a Boolean. argument identifier가 LexicalDeclaration 또는 ClassDeclaration 같은 lexical declaration을 사용하여 created된 envRecord 안의 binding을 가지는지 determine합니다. It performs the following steps when called:

  1. declRecordenvRecord.[[DeclarativeRecord]]로 둔다.
  2. declRecord.HasBinding(name)를 반환한다.

9.1.1.4.13 HasRestrictedGlobalProperty ( envRecord, name )

The abstract operation HasRestrictedGlobalProperty takes arguments envRecord (a Global Environment Record) and name (a String) and returns either a normal completion containing a Boolean or a throw completion. argument identifier가 global lexical binding에 의해 shadowed되어서는 안 되는 global objectproperty name인지 determine합니다. It performs the following steps when called:

  1. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  2. globalObjobjRecord.[[BindingObject]]로 둔다.
  3. existingProperty를 ? globalObj.[[GetOwnProperty]](name)로 둔다.
  4. existingPropertyundefined이면, false를 반환한다.
  5. existingProperty.[[Configurable]]true이면, false를 반환한다.
  6. true를 반환한다.
Note

var 또는 function declaration을 사용하여 declared된 것이 아니라 directly created된 property가 global object 위에 존재할 수 있습니다. global lexical binding은 global object의 non-configurable property와 같은 name으로 created될 수 없습니다. global property "undefined"는 그러한 property의 example입니다.

9.1.1.4.14 CanDeclareGlobalVar ( envRecord, name )

The abstract operation CanDeclareGlobalVar takes arguments envRecord (a Global Environment Record) and name (a String) and returns either a normal completion containing a Boolean or a throw completion. same argument name에 대해 corresponding CreateGlobalVarBinding call이 called된다면 succeed할지 determine합니다. Redundant var declaration과 pre-existing global object property에 대한 var declaration은 allowed됩니다. It performs the following steps when called:

  1. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  2. globalObjobjRecord.[[BindingObject]]로 둔다.
  3. hasProperty를 ? HasOwnProperty(globalObj, name)로 둔다.
  4. hasPropertytrue이면, true를 반환한다.
  5. IsExtensible(globalObj)를 반환한다.

9.1.1.4.15 CanDeclareGlobalFunction ( envRecord, name )

The abstract operation CanDeclareGlobalFunction takes arguments envRecord (a Global Environment Record) and name (a String) and returns either a normal completion containing a Boolean or a throw completion. same argument name에 대해 corresponding CreateGlobalFunctionBinding call이 called된다면 succeed할지 determine합니다. It performs the following steps when called:

  1. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  2. globalObjobjRecord.[[BindingObject]]로 둔다.
  3. existingProperty를 ? globalObj.[[GetOwnProperty]](name)로 둔다.
  4. existingPropertyundefined이면, ? IsExtensible(globalObj)를 반환한다.
  5. existingProperty.[[Configurable]]true이면, true를 반환한다.
  6. IsDataDescriptor(existingProperty)가 true이고 existingProperty가 attribute values { [[Writable]]: true, [[Enumerable]]: true }를 가지면, true를 반환한다.
  7. false를 반환한다.

9.1.1.4.16 CreateGlobalVarBinding ( envRecord, name, deletable )

The abstract operation CreateGlobalVarBinding takes arguments envRecord (a Global Environment Record), name (a String), and deletable (a Boolean) and returns either a normal completion containing unused or a throw completion. associated Object Environment Record 안에 mutable binding을 create하고 initialize합니다. binding이 already exist하면, 재사용되며 initialized된 것으로 assumed됩니다. It performs the following steps when called:

  1. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  2. globalObjobjRecord.[[BindingObject]]로 둔다.
  3. hasProperty를 ? HasOwnProperty(globalObj, name)로 둔다.
  4. extensible을 ? IsExtensible(globalObj)로 둔다.
  5. hasPropertyfalse이고 extensibletrue이면, 다음을 수행한다.
    1. objRecord.CreateMutableBinding(name, deletable)를 수행한다.
    2. objRecord.InitializeBinding(name, undefined)를 수행한다.
  6. unused를 반환한다.

9.1.1.4.17 CreateGlobalFunctionBinding ( envRecord, name, value, deletable )

The abstract operation CreateGlobalFunctionBinding takes arguments envRecord (a Global Environment Record), name (a String), value (an ECMAScript function object), and deletable (a Boolean) and returns either a normal completion containing unused or a throw completion. associated Object Environment Record 안에 mutable binding을 create하고 initialize합니다. binding이 already exist하면, replaced됩니다. It performs the following steps when called:

  1. objRecordenvRecord.[[ObjectRecord]]로 둔다.
  2. globalObjobjRecord.[[BindingObject]]로 둔다.
  3. existingProperty를 ? globalObj.[[GetOwnProperty]](name)로 둔다.
  4. existingPropertyundefined이거나 existingProperty.[[Configurable]]true이면, 다음을 수행한다.
    1. propertyDesc를 PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: deletable }로 둔다.
  5. 그렇지 않으면,
    1. propertyDesc를 PropertyDescriptor { [[Value]]: value }로 둔다.
  6. DefinePropertyOrThrow(globalObj, name, propertyDesc)를 수행한다.
  7. Set(globalObj, name, value, false)를 수행한다.
  8. unused를 반환한다.
Note

Global function declaration은 항상 global object의 own property로 represented됩니다. 가능하면, existing own property는 standard set of attribute values를 가지도록 reconfigured됩니다. Step 7InitializeBinding concrete method를 calling하는 것이 수행할 것과 equivalent하며 globalObj가 Proxy이면 같은 sequence의 Proxy trap call을 produce합니다.

9.1.1.5 Module Environment Records

Module Environment Record는 ECMAScript Module의 outer scope를 represent하는 데 사용되는 Declarative Environment Record입니다. normal mutable 및 immutable binding에 더해, Module Environment Record는 다른 Environment Record에 존재하는 target binding에 대한 indirect access를 제공하는 binding인 immutable import binding도 제공합니다.

Module Environment Record는 Table 15에 listed된 모든 Declarative Environment Record method를 support하며, GetBindingValue, DeleteBinding, HasThisBinding, GetThisBinding을 제외한 모든 method에 대해 같은 specification을 share합니다.

9.1.1.5.1 GetBindingValue ( name, strict )

The GetBindingValue concrete method of a Module Environment Record envRecord takes arguments name (a String) and strict (a Boolean) and returns either a normal completion containing an ECMAScript language value or a throw completion. name이 name인 bound identifier의 value를 반환합니다. 그러나 binding이 indirect binding이면 target binding의 value가 returned됩니다. binding이 존재하지만 uninitialized이면 ReferenceError가 thrown됩니다. It performs the following steps when called:

  1. Assert: stricttrue이다.
  2. Assert: envRecordname에 대한 binding을 가진다.
  3. name에 대한 binding이 indirect binding이면, 다음을 수행한다.
    1. moduletargetNamename에 대한 이 binding이 created될 때 provided된 indirection value로 둔다.
    2. targetEnvmodule.[[Environment]]로 둔다.
    3. targetEnvempty이면, ReferenceError exception을 throw한다.
    4. targetEnv.GetBindingValue(targetName, true)를 반환한다.
  4. envRecord 안의 name에 대한 binding이 uninitialized binding이면, ReferenceError exception을 throw한다.
  5. envRecord 안에서 현재 name에 bound된 value를 반환한다.
Note

Module은 항상 strict mode code이므로 strict는 항상 true입니다.

9.1.1.5.2 DeleteBinding ( name )

Module Environment RecordDeleteBinding concrete method는 이 명세 안에서 결코 사용되지 않습니다.

Note

Module Environment Record는 strict code 안에서만 사용되고, early error rule은 strict code에서 delete operator가 Module Environment Record binding으로 resolve될 Reference Record에 applied되는 것을 prevent합니다. 13.5.1.1를 참조하십시오.

9.1.1.5.3 HasThisBinding ( )

The HasThisBinding concrete method of a Module Environment Record envRecord takes no arguments and returns true. It performs the following steps when called:

  1. true를 반환한다.
Note

Module Environment Record는 항상 this binding을 제공합니다.

9.1.1.5.4 GetThisBinding ( )

The GetThisBinding concrete method of a Module Environment Record envRecord takes no arguments and returns a normal completion containing undefined. It performs the following steps when called:

  1. undefined를 반환한다.

9.1.1.5.5 CreateImportBinding ( envRecord, name, targetModule, targetName )

The abstract operation CreateImportBinding takes arguments envRecord (a Module Environment Record), name (a String), targetModule (a Module Record), and targetName (a String) and returns unused. name name에 대한 새 initialized immutable indirect binding을 생성합니다. envRecord 안에는 name에 대한 binding이 already exist하지 않아야 합니다. targetNametargetModuleModule Environment Record에 존재하는 binding의 name입니다. 새 binding의 value에 대한 access는 target binding의 bound value에 indirectly access합니다. It performs the following steps when called:

  1. Assert: envRecordname에 대한 binding을 already have하지 않는다.
  2. Assert: targetModule.[[Environment]]가 instantiated되면, 이는 targetName에 대한 direct binding을 가질 것이다.
  3. envRecord 안에 targetModuletargetName을 target binding으로 reference하는 name에 대한 immutable indirect binding을 생성하고, 그 binding이 initialized되었음을 record한다.
  4. unused를 반환한다.

9.1.2 Environment Record Operations

다음 abstract operation은 이 명세에서 Environment Record에 대해 operate하는 데 사용됩니다:

9.1.2.1 GetIdentifierReference ( envRecord, name, strict )

The abstract operation GetIdentifierReference takes arguments envRecord (an Environment Record or null), name (a String), and strict (a Boolean) and returns either a normal completion containing a Reference Record or a throw completion. It performs the following steps when called:

  1. envRecordnull이면, 다음을 수행한다.
    1. Reference Record { [[Base]]: unresolvable, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]: empty }를 반환한다.
  2. exists를 ? envRecord.HasBinding(name)로 둔다.
  3. existstrue이면, 다음을 수행한다.
    1. Reference Record { [[Base]]: envRecord, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]: empty }를 반환한다.
  4. outerenvRecord.[[OuterEnv]]로 둔다.
  5. GetIdentifierReference(outer, name, strict)를 반환한다.

9.1.2.2 NewDeclarativeEnvironment ( outerEnv )

The abstract operation NewDeclarativeEnvironment takes argument outerEnv (an Environment Record or null) and returns a Declarative Environment Record. It performs the following steps when called:

  1. 바인딩을 포함하지 않는 새 Declarative Environment RecordenvRecord로 둔다.
  2. envRecord.[[OuterEnv]]outerEnv로 설정한다.
  3. envRecord.[[DisposableResourceStack]]을 새 빈 List로 설정한다.
  4. envRecord를 반환한다.

9.1.2.3 NewObjectEnvironment ( obj, isWithEnv, outerEnv )

The abstract operation NewObjectEnvironment takes arguments obj (an Object), isWithEnv (a Boolean), and outerEnv (an Environment Record or null) and returns an Object Environment Record. It performs the following steps when called:

  1. Object Environment Record envRecord를 둔다.
  2. envRecord.[[BindingObject]]obj로 설정한다.
  3. envRecord.[[IsWithEnvironment]]isWithEnv로 설정한다.
  4. envRecord.[[OuterEnv]]outerEnv로 설정한다.
  5. envRecord를 반환한다.

9.1.2.4 NewFunctionEnvironment ( func, newTarget )

The abstract operation NewFunctionEnvironment takes arguments func (an ECMAScript function object) and newTarget (an Object or undefined) and returns a Function Environment Record. It performs the following steps when called:

  1. 바인딩을 포함하지 않는 새 Function Environment RecordenvRecord로 둔다.
  2. envRecord.[[FunctionObject]]func로 설정한다.
  3. func.[[ThisMode]]lexical이면, envRecord.[[ThisBindingStatus]]lexical로 설정한다.
  4. 그렇지 않으면, envRecord.[[ThisBindingStatus]]uninitialized로 설정한다.
  5. envRecord.[[NewTarget]]newTarget으로 설정한다.
  6. envRecord.[[OuterEnv]]func.[[Environment]]로 설정한다.
  7. envRecord.[[DisposableResourceStack]]을 새 빈 List로 설정한다.
  8. envRecord를 반환한다.

9.1.2.5 NewGlobalEnvironment ( obj, thisValue )

The abstract operation NewGlobalEnvironment takes arguments obj (an Object) and thisValue (an Object) and returns a Global Environment Record. It performs the following steps when called:

  1. objRecordNewObjectEnvironment(obj, false, null)로 둔다.
  2. declRecordNewDeclarativeEnvironment(null)로 둔다.
  3. Global Environment Record envRecord를 둔다.
  4. envRecord.[[ObjectRecord]]objRecord로 설정한다.
  5. envRecord.[[GlobalThisValue]]thisValue로 설정한다.
  6. envRecord.[[DeclarativeRecord]]declRecord로 설정한다.
  7. envRecord.[[OuterEnv]]null로 설정한다.
  8. envRecord를 반환한다.

9.1.2.6 NewModuleEnvironment ( outerEnv )

The abstract operation NewModuleEnvironment takes argument outerEnv (a Global Environment Record) and returns a Module Environment Record. It performs the following steps when called:

  1. 바인딩을 포함하지 않는 새 Module Environment RecordenvRecord로 둔다.
  2. envRecord.[[OuterEnv]]outerEnv로 설정한다.
  3. envRecord.[[DisposableResourceStack]]을 새 빈 List로 설정한다.
  4. envRecord를 반환한다.

9.2 PrivateEnvironment Records

PrivateEnvironment Record는 ECMAScript code 안의 ClassDeclarationClassExpression의 lexical nesting structure에 기반하여 Private Name을 track하는 데 사용되는 specification mechanism입니다. 이는 Environment Record와 similar하지만 distinct합니다. 각 PrivateEnvironment RecordClassDeclaration 또는 ClassExpression과 associated됩니다. 그러한 class가 evaluate될 때마다, 그 class가 declared한 Private Name을 record하기 위해 새 PrivateEnvironment Record가 생성됩니다.

PrivateEnvironment RecordTable 19에 정의된 field를 가집니다.

Table 19: PrivateEnvironment Record Fields
Field Name Value Type Meaning
[[OuterPrivateEnvironment]] a PrivateEnvironment Record or null 가장 가까운 containing class의 PrivateEnvironment Record입니다. 이 PrivateEnvironment Record와 associated된 class가 다른 class 안에 contained되어 있지 않으면 null입니다.
[[Names]] a List of Private Names 이 class가 declared한 Private Name입니다.

9.2.1 PrivateEnvironment Record Operations

다음 abstract operation은 이 명세에서 PrivateEnvironment Record에 대해 operate하는 데 사용됩니다:

9.2.1.1 NewPrivateEnvironment ( outerPrivateEnv )

The abstract operation NewPrivateEnvironment takes argument outerPrivateEnv (a PrivateEnvironment Record or null) and returns a PrivateEnvironment Record. It performs the following steps when called:

  1. names를 새 empty List로 둔다.
  2. PrivateEnvironment Record { [[OuterPrivateEnvironment]]: outerPrivateEnv, [[Names]]: names }를 반환한다.

9.2.1.2 ResolvePrivateIdentifier ( privateEnv, identifier )

The abstract operation ResolvePrivateIdentifier takes arguments privateEnv (a PrivateEnvironment Record) and identifier (a String) and returns a Private Name. It performs the following steps when called:

  1. namesprivateEnv.[[Names]]로 둔다.
  2. names의 각 Private Name privateName에 대해, 다음을 수행한다.
    1. privateName.[[Description]]identifier이면, 다음을 수행한다.
      1. privateName을 반환한다.
  3. outerPrivateEnvprivateEnv.[[OuterPrivateEnvironment]]로 둔다.
  4. Assert: outerPrivateEnvnull이 아니다.
  5. ResolvePrivateIdentifier(outerPrivateEnv, identifier)를 반환한다.

9.3 Realms

evaluate되기 전에, 모든 ECMAScript code는 realm과 associated되어야 합니다. Conceptually, realm은 intrinsic object의 set, ECMAScript global environment, 그 global environment의 scope 안에 loaded된 모든 ECMAScript code, 그리고 기타 associated state와 resource로 구성됩니다.

realm은 이 명세에서 Table 20에 specified된 field를 가진 Realm Record로 represented됩니다:

Table 20: Realm Record Fields
Field Name Value Meaning
[[AgentSignifier]] an agent signifier realm을 own하는 agent
[[Intrinsics]] a Record whose field names are intrinsic keys and whose values are objects realm과 associated된 code가 사용하는 intrinsic value
[[GlobalObject]] an Object realmglobal object
[[GlobalEnv]] a Global Environment Record realm의 global environment
[[TemplateMap]] a List of Records with fields [[Site]] (a TemplateLiteral Parse Node) and [[Array]] (an Array)

Template object는 각 realm마다 그 Realm Record[[TemplateMap]]을 사용하여 separately canonicalized됩니다. 각 [[Site]] value는 TemplateLiteralParse Node입니다. associated [[Array]] value는 tag function에 passed되는 corresponding template object입니다.

Note 1
Parse Node가 unreachable이 되면, corresponding [[Array]]도 unreachable이 되며, implementation이 [[TemplateMap]] list에서 그 pair를 removed하더라도 unobservable합니다.
[[LoadedModules]] a List of LoadedModuleRequest Records

realm이 import한 specifier string에서 resolved Module Record로의 map입니다. 이 list는 ModuleRequestsEqual(r1, r2)이 true인 서로 다른 Record r1r2를 contain하지 않습니다.

Note 2
HostLoadImportedModule(16.2.1.10 Note 1)에서 언급한 것처럼, Realm Record 안의 [[LoadedModules]]는 active script나 module이 없는 context에서 import() expression을 running할 때만 사용됩니다.
[[HostDefined]] anything (default value is undefined) Realm Record와 additional information을 associate해야 하는 host가 사용하기 위해 reserved된 field입니다.

9.3.1 InitializeHostDefinedRealm ( )

The abstract operation InitializeHostDefinedRealm takes no arguments and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. realm을 새 Realm Record로 둔다.
  2. CreateIntrinsics(realm)를 수행한다.
  3. realm.[[AgentSignifier]]AgentSignifier()로 설정한다.
  4. realm.[[TemplateMap]]을 새 empty List로 설정한다.
  5. newContext를 새 execution context로 둔다.
  6. newContext의 Function을 null로 설정한다.
  7. newContextRealmrealm으로 설정한다.
  8. newContext의 ScriptOrModule을 null로 설정한다.
  9. newContextexecution context stack 위로 push한다; newContext는 이제 running execution context이다.
  10. hostrealmglobal object 역할을 할 specific object의 use를 require하면, 다음을 수행한다.
    1. globalhost-defined manner로 created된 그러한 object로 둔다.
  11. 그렇지 않으면,
    1. globalOrdinaryObjectCreate(realm.[[Intrinsics]].[[%Object.prototype%]])로 둔다.
  12. hostrealm의 global scope 안의 this binding이 global object가 아닌 object를 return하도록 require하면, 다음을 수행한다.
    1. thisValuehost-defined manner로 created된 그러한 object로 둔다.
  13. 그렇지 않으면,
    1. thisValueglobal로 둔다.
  14. realm.[[GlobalObject]]global로 설정한다.
  15. realm.[[GlobalEnv]]NewGlobalEnvironment(global, thisValue)로 설정한다.
  16. SetDefaultGlobalBindings(realm)를 수행한다.
  17. host-defined global object property를 global 위에 create한다.
  18. unused를 반환한다.

9.3.2 CreateIntrinsics ( realmRecord )

The abstract operation CreateIntrinsics takes argument realmRecord (a Realm Record) and returns unused. It performs the following steps when called:

  1. realmRecord.[[Intrinsics]]를 새 Record로 설정한다.
  2. realmRecord.[[Intrinsics]]의 field를 Table 6에 listed된 value로 설정한다. field name은 table의 “Intrinsic Name” column에 listed된 name입니다. 각 field의 value는 clause 19부터 28까지의 각 object specification에 의해 정의된 property value로 fully and recursively populated된 새 object value입니다. 모든 object property value는 newly created object value입니다. built-in function object인 모든 value는 CreateBuiltinFunction(steps, length, name, slots, realmRecord, proto, async)를 수행하여 created되며, 여기서 steps는 이 명세가 제공하는 해당 function의 definition, name은 function의 "name" property의 initial value, length는 function의 "length" property의 initial value, slots는 function의 specified internal slot의 name list(있는 경우), proto는 function의 [[Prototype]] internal slot의 specified value, async는 function이 “async”로 described되면 true이고 그렇지 않으면 false입니다. intrinsics와 그 property의 creation은 아직 created되지 않은 object에 대한 dependency를 피하도록 ordered되어야 합니다.
  3. AddRestrictedFunctionProperties(realmRecord.[[Intrinsics]].[[%Function.prototype%]], realmRecord)를 수행한다.
  4. unused를 반환한다.

9.3.3 SetDefaultGlobalBindings ( realmRecord )

The abstract operation SetDefaultGlobalBindings takes argument realmRecord (a Realm Record) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. globalrealmRecord.[[GlobalObject]]로 둔다.
  2. clause 19에 specified된 Global Object의 각 property에 대해, 다음을 수행한다.
    1. nameproperty name의 String value로 둔다.
    2. propertyDesc를 property에 대한 specified attribute를 contain하는, property에 대한 fully populated data Property Descriptor로 둔다. 19.2, 19.3 또는 19.4에 listed된 property에 대해서는 [[Value]] attribute의 value가 realmRecord의 corresponding intrinsic object입니다.
    3. DefinePropertyOrThrow(global, name, propertyDesc)를 수행한다.
  3. unused를 반환한다.

9.4 Execution Contexts

execution context는 ECMAScript implementation에 의한 code의 runtime evaluation을 track하는 데 사용되는 specification device입니다. 어느 시점에서든, 실제로 code를 executing하고 있는 execution context는 agent마다 at most one입니다. 이는 agentrunning execution context로 알려져 있습니다. 이 명세에서 running execution context에 대한 모든 reference는 surrounding agentrunning execution context를 denote합니다.

execution context stack은 execution context를 track하는 데 사용됩니다. running execution context는 항상 이 stack의 top element입니다. currently running execution context와 associated된 executable code에서 그 execution context와 associated되지 않은 executable code로 control이 transferred될 때마다 새 execution context가 created됩니다. newly created execution context는 stack 위로 pushed되고 running execution context가 됩니다.

execution context는 associated code의 execution progress를 track하는 데 필요한 implementation specific state를 포함합니다. 각 execution context는 적어도 Table 21에 listed된 state component를 가집니다.

Table 21: State Components for All Execution Contexts
Component Purpose
code evaluation state execution context와 associated된 code의 evaluation을 perform, suspend, resume하는 데 필요한 모든 state입니다.
Function execution contextfunction object의 code를 evaluating하고 있으면, 이 component의 value는 그 function object입니다. context가 Script 또는 Module의 code를 evaluating하고 있으면, value는 null입니다.
Realm associated code가 ECMAScript resource에 access하는 Realm Record입니다.
ScriptOrModule associated code가 originate하는 Module Record 또는 Script Record입니다. InitializeHostDefinedRealm에서 created된 original execution context의 경우처럼 originating script나 module이 없으면, value는 null입니다.

실행 중인 실행 컨텍스트에 의한 코드 평가는 이 명세 안에 정의된 여러 지점에서 중단될 수 있다. 실행 중인 실행 컨텍스트가 일단 중단되면, 다른 실행 컨텍스트가 실행 중인 실행 컨텍스트가 되어 그 코드를 평가하기 시작할 수 있다. 나중의 어느 시점에 중단된 실행 컨텍스트가 다시 실행 중인 실행 컨텍스트가 되어 이전에 중단되었던 지점에서 그 코드 평가를 계속할 수 있다. 실행 컨텍스트들 사이에서 실행 중인 실행 컨텍스트 상태의 전환은 보통 스택과 같은 후입선출 방식으로 일어난다. 그러나 일부 ECMAScript 기능은 실행 중인 실행 컨텍스트의 비-LIFO 전환을 필요로 한다.

실행 중인 실행 컨텍스트의 Realm 구성 요소 값은 현재 Realm Record라고도 한다. 실행 중인 실행 컨텍스트의 Function 구성 요소 값은 활성 함수 객체라고도 한다.

ECMAScript 코드 실행 컨텍스트에는 Table 22에 나열된 추가 상태 구성 요소가 있다.

Table 22: Additional State Components for ECMAScript Code Execution Contexts
Component Purpose
LexicalEnvironment execution context 안의 code가 만든 identifier reference를 resolve하는 데 사용되는 Environment Record를 identify합니다.
VariableEnvironment execution context 안의 VariableStatement에 의해 created된 binding을 hold하는 Environment Record를 identify합니다.
PrivateEnvironment 가장 가까운 containing class 안의 ClassElement에 의해 created된 Private Name을 hold하는 PrivateEnvironment Record를 identify합니다. containing class가 없으면 null입니다.

execution context의 LexicalEnvironment와 VariableEnvironment component는 항상 Environment Record입니다.

Generator의 evaluation을 representing하는 execution context는 Table 23에 listed된 additional state component를 가집니다.

Table 23: Additional State Components for Generator Execution Contexts
Component Purpose
Generator execution context가 evaluating하고 있는 Generator입니다.

대부분의 situation에서는 running execution context(execution context stack의 top)만 이 명세 안의 algorithm에 의해 directly manipulated됩니다. 따라서 “LexicalEnvironment”와 “VariableEnvironment”라는 term이 qualification 없이 사용될 때는 running execution context의 해당 component를 reference합니다.

execution context는 순수하게 specification mechanism이며 ECMAScript implementation의 특정 artefact에 대응할 필요가 없습니다. ECMAScript code가 execution context에 직접 access하거나 observe하는 것은 불가능합니다.

9.4.1 GetActiveScriptOrModule ( )

The abstract operation GetActiveScriptOrModule takes no arguments and returns a Script Record, a Module Record, or null. running execution context에 기반하여 running script 또는 module을 determine하는 데 사용됩니다. It performs the following steps when called:

  1. execution context stack이 empty이면, null을 반환한다.
  2. executionContextexecution context stack 위에서 ScriptOrModule component가 null이 아닌 topmost execution context로 둔다.
  3. 그러한 execution context가 존재하지 않으면, null을 반환한다.
  4. executionContext의 ScriptOrModule을 반환한다.

9.4.2 ResolveBinding ( name [ , envRecord ] )

The abstract operation ResolveBinding takes argument name (a String) and optional argument envRecord (an Environment Record or undefined) and returns either a normal completion containing a Reference Record or a throw completion. name의 binding을 determine하는 데 사용됩니다. envRecord는 binding을 search할 Environment Record를 명시적으로 provide하는 데 사용될 수 있습니다. It performs the following steps when called:

  1. envRecord가 present하지 않거나 envRecordundefined이면, 다음을 수행한다.
    1. envRecordrunning execution context의 LexicalEnvironment로 설정한다.
  2. Assert: envRecordEnvironment Record이다.
  3. strict를 evaluating되고 있는 syntactic production의 IsStrict로 둔다.
  4. GetIdentifierReference(envRecord, name, strict)를 반환한다.
Note

ResolveBinding의 result는 항상 [[ReferencedName]] field가 nameReference Record입니다.

9.4.3 GetThisEnvironment ( )

The abstract operation GetThisEnvironment takes no arguments and returns an Environment Record. keyword this의 binding을 currently supply하는 Environment Record를 찾습니다. It performs the following steps when called:

  1. envRecordrunning execution context의 LexicalEnvironment로 둔다.
  2. Repeat,
    1. existsenvRecord.HasThisBinding()으로 둔다.
    2. existstrue이면, envRecord를 반환한다.
    3. outerenvRecord.[[OuterEnv]]로 둔다.
    4. Assert: outernull이 아니다.
    5. envRecordouter로 설정한다.
Note

step 2의 loop는 environment list가 항상 this binding을 가진 global environment로 끝나기 때문에 항상 terminate합니다.

9.4.4 ResolveThisBinding ( )

The abstract operation ResolveThisBinding takes no arguments and returns either a normal completion containing an ECMAScript language value or a throw completion. running execution context의 LexicalEnvironment를 사용하여 keyword this의 binding을 determine합니다. It performs the following steps when called:

  1. envRecordGetThisEnvironment()로 둔다.
  2. envRecord.GetThisBinding()을 반환한다.

9.4.5 GetNewTarget ( )

The abstract operation GetNewTarget takes no arguments and returns an Object or undefined. running execution context의 LexicalEnvironment를 사용하여 NewTarget value를 determine합니다. It performs the following steps when called:

  1. envRecordGetThisEnvironment()로 둔다.
  2. Assert: envRecord[[NewTarget]] field를 가진다.
  3. envRecord.[[NewTarget]]을 반환한다.

9.4.6 GetGlobalObject ( )

The abstract operation GetGlobalObject takes no arguments and returns an Object. currently running execution context가 사용하는 global object를 반환합니다. It performs the following steps when called:

  1. currentRealm을 current Realm Record로 둔다.
  2. currentRealm.[[GlobalObject]]를 반환한다.

9.4.7 RunSuspendedContext ( context, completionRecord )

The abstract operation RunSuspendedContext takes arguments context (an execution context) and completionRecord (a Completion Record) and returns either a normal completion containing either an ECMAScript language value or unused, or an abrupt completion. context를 resume하고(completionRecord를 resumption value로 sending), result를 기다립니다. It performs the following steps when called:

  1. callerContextrunning execution context로 둔다.
  2. callerContext를 Suspend한다.
  3. contextexecution context stack 위로 push한다; context는 이제 running execution context이다.
  4. suspended시킨 operation의 result로 completionRecord를 사용하여 context의 suspended evaluation을 Resume한다. result를 resumed computation이 반환한 Completion Record로 둔다.
  5. Assert: 이 step에 도달했을 때, context는 이미 execution context stack에서 removed되었고 callerContext가 다시 running execution context이다.
  6. Completion(result)를 반환한다.

9.4.8 RunCallerContext ( value )

The abstract operation RunCallerContext takes argument value (ECMAScript 언어 값 또는 empty) and returns Completion Record. 호출자 컨텍스트를 재개하고(value를 재개 값으로 보냄), 결과가 있으면 그 결과를 기다린다. It performs the following steps when called:

  1. genContext를 실행 중인 실행 컨텍스트라 하자.
  2. 실행 컨텍스트 스택에서 genContext를 제거하고, 실행 컨텍스트 스택의 맨 위에 있는 실행 컨텍스트를 실행 중인 실행 컨텍스트로 복원한다.
  3. callerContext를 실행 중인 실행 컨텍스트라 하자.
  4. callerContext를 재개하며, NormalCompletion(value)를 전달한다.
  5. NOTE: 위 단계는 제어를 callerContext로 이전하고 일시 중지한다. 이것이 일시 중지를 해제하고 이 알고리즘의 이후 단계로 제어가 진행되게 하는 유일한 방법은 genContext가 다시 재개되는 것이며, 이는 결코 일어나지 않을 수도 있다.
  6. Assert: genContext는 실행 중인 실행 컨텍스트이다.
  7. resultgenContext가 방금 재개될 때 함께 전달된 Completion Record라 하자.
  8. Completion(result)를 반환한다.

9.5 Jobs and Host Operations to Enqueue Jobs

Job은 현재 진행 중인 다른 ECMAScript computation이 없을 때 ECMAScript computation을 initiate하는 parameter가 없는 Abstract Closure입니다.

Job은 특정 agent 안에서 ECMAScript host environment에 의해 execution을 위해 scheduled됩니다. 이 명세는 job을 schedule하기 위한 host hook HostEnqueueGenericJob, HostEnqueueFinalizationRegistryCleanupJob, HostEnqueuePromiseJob, HostEnqueueTimeoutJob을 설명합니다. 이 명세의 host hook은 job scheduling에 imposed되는 additional constraint에 의해 organized됩니다. Host는 job을 schedule하는 additional abstract operation을 define할 수 있습니다. 그러한 operation은 Job Abstract Closurerealm(Realm Record 또는 null)을 parameter로 accept합니다. Realm Record가 provided되면, 이러한 operation은 provided realm 안에서, 그 realm을 owns하는 agent 안에서, future time에 job이 performed되도록 schedule합니다. realm으로 null이 대신 provided되면, job은 ECMAScript code를 evaluate하지 않습니다. 그 implementation은 다음 requirement를 conform해야 합니다:

Note 1
Host environment는 scheduling과 관련하여 Job을 uniformly 취급할 필요가 없습니다. 예를 들어, web browser와 Node.js는 Promise-handling Job을 다른 work보다 higher priority로 취급합니다. future feature는 그렇게 high priority로 취급되지 않는 Job을 add할 수 있습니다.

특정 시점에서 scriptOrModule(Script Record, Module Record 또는 null)은 다음 조건이 모두 true이면 active script or module입니다:

특정 시점에서 execution은 다음 조건이 모두 true이면 prepared to evaluate ECMAScript code입니다:

Note 2

Host environmentexecution contextexecution context stack 위로 push함으로써 code를 evaluate할 execution을 prepare할 수 있습니다. specific step은 implementation-defined입니다.

Realm의 specific choice는 host environment에 달려 있습니다. 이 initial execution contextRealm은 callback function이 invoked되기 전까지만 사용됩니다. Promise handler 같은 Job과 관련된 callback function이 invoked되면, invocation은 자체 execution contextRealm을 push합니다.

Particular kind의 Job은 additional conformance requirement를 가집니다.

9.5.1 JobCallback Records

JobCallback Recordfunction objecthost-defined value를 store하는 데 사용되는 Record value입니다. host에 의해 enqueued된 Job을 통해 invoked되는 function object는 additional host-defined context를 가질 수 있습니다. state를 propagate하기 위해 Job Abstract Closurefunction object를 직접 capture하고 call해서는 안 됩니다. 대신 HostMakeJobCallbackHostCallJobCallback을 사용하십시오.

Note

WHATWG HTML specification(https://html.spec.whatwg.org/)은, 예를 들어, host-defined value를 사용하여 Promise callback에 대한 incumbent settings object를 propagate합니다.

JobCallback Record는 Table 24에 listed된 field를 가집니다.

Table 24: JobCallback Record Fields
Field Name Value Meaning
[[Callback]] a function object Job이 invoked될 때 invoke할 function입니다.
[[HostDefined]] anything (default value is empty) host가 사용하기 위해 reserved된 field입니다.

9.5.2 HostMakeJobCallback ( callback )

The host-defined abstract operation HostMakeJobCallback takes argument callback (a function object) and returns a JobCallback Record.

HostMakeJobCallback의 implementation은 다음 requirement를 conform해야 합니다:

HostMakeJobCallback의 default implementation은 called될 때 다음 step을 수행합니다:

  1. JobCallback Record { [[Callback]]: callback, [[HostDefined]]: empty }를 반환한다.

web browser가 아닌 ECMAScript host는 HostMakeJobCallback의 default implementation을 사용해야 합니다.

Note

이는 callback이 eventually scheduled되고 run되는 것을 responsible하는 function에 passed되는 시점에 called됩니다. 예를 들어, promise.then(thenAction)은 reaction Job을 scheduling하는 시점이 아니라 Promise.prototype.then을 invoking하는 시점에 thenAction에 대해 MakeJobCallback을 call합니다.

9.5.3 HostCallJobCallback ( jobCallback, thisValue, argList )

The host-defined abstract operation HostCallJobCallback takes arguments jobCallback (a JobCallback Record), thisValue (an ECMAScript language value), and argList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion.

HostCallJobCallback의 implementation은 다음 requirement를 conform해야 합니다:

  • Call(jobCallback.[[Callback]], thisValue, argList)의 result를 perform하고 반환해야 합니다.
Note

이 requirement는 host가 이 명세에 정의된 function object[[Call]] behaviour를 change할 수 없음을 의미합니다.

HostCallJobCallback의 default implementation은 called될 때 다음 step을 수행합니다:

  1. Assert: IsCallable(jobCallback.[[Callback]])은 true이다.
  2. Call(jobCallback.[[Callback]], thisValue, argList)를 반환한다.

web browser가 아닌 ECMAScript host는 HostCallJobCallback의 default implementation을 사용해야 합니다.

9.5.4 HostEnqueueGenericJob ( job, realm )

The host-defined abstract operation HostEnqueueGenericJob takes arguments job (a Job Abstract Closure) and realm (a Realm Record) and returns unused. realm.[[AgentSignifier]]가 signified하는 agent 안에서, realm realm 안에 job을 future time에 performed되도록 schedule합니다. 이 algorithm과 함께 사용되는 Abstract Closure는 priority와 ordering 같은 additional constraint 없이 scheduled되도록 intended됩니다.

HostEnqueueGenericJob의 implementation은 9.5의 requirement를 conform해야 합니다.

9.5.5 HostEnqueuePromiseJob ( job, realm )

The host-defined abstract operation HostEnqueuePromiseJob takes arguments job (a Job Abstract Closure) and realm (a Realm Record or null) and returns unused. job을 future time에 performed되도록 schedule합니다. 이 algorithm과 함께 사용되는 Abstract Closure는 Promise의 handling과 관련되거나, 그 밖에 Promise handling operation과 equal priority로 scheduled되도록 intended됩니다.

HostEnqueuePromiseJob의 implementation은 9.5의 requirement와 다음 requirement를 conform해야 합니다:

  • realmnull이 아니면, job이 invoked될 때마다 implementation은 job의 invocation 시점에 execution이 ECMAScript code를 evaluate할 준비가 되도록 implementation-defined step을 수행해야 합니다.
  • HostEnqueuePromiseJob이 invoked되는 시점의 GetActiveScriptOrModule()을 scriptOrModule로 둡니다. realmnull이 아니면, job이 invoked될 때마다 implementation은 job의 invocation 시점에 scriptOrModuleactive script or module이 되도록 implementation-defined step을 수행해야 합니다.
  • Job은 그것을 scheduled한 HostEnqueuePromiseJob invocation과 같은 order로 run해야 합니다.
Note

NewPromiseResolveThenableJob이 반환하는 Jobrealm은 보통 then function object에 대해 GetFunctionRealm을 call한 result입니다. NewPromiseReactionJob이 반환하는 Jobrealm은 handler가 undefined가 아니면 보통 handler에 대해 GetFunctionRealm을 call한 result입니다. handler가 undefined이면 realmnull입니다. 두 종류의 Job 모두에 대해, GetFunctionRealm이 abnormally complete하면(즉 revoked Proxy에 called되면), realmGetFunctionRealm call 시점의 current Realm Record입니다. realmnull이면 user ECMAScript code는 evaluate되지 않고 새 ECMAScript object(예: Error object)도 created되지 않습니다. WHATWG HTML specification(https://html.spec.whatwg.org/)은, 예를 들어, realm을 사용하여 script를 run할 capability와 entry concept를 check합니다.

9.5.6 HostEnqueueTimeoutJob ( timeoutJob, realm, milliseconds )

The host-defined abstract operation HostEnqueueTimeoutJob takes arguments timeoutJob (a Job Abstract Closure), realm (a Realm Record), and milliseconds (a non-negative finite Number) and returns unused. realm.[[AgentSignifier]]가 signified하는 agent 안에서, realm realm 안에 timeoutJob을 at least milliseconds milliseconds 후에 performed되도록 schedule합니다.

HostEnqueueTimeoutJob의 implementation은 9.5의 requirement를 conform해야 합니다.

9.6 Agents

agent는 ECMAScript execution context의 set, execution context stack, running execution context, Agent Record, 그리고 executing thread로 구성됩니다. executing thread를 제외하면, agent의 구성 요소는 exclusively 그 agent에 belong합니다.

agentexecuting thread는 다른 agent와 independent하게 그 agentexecution context에서 algorithmic step을 execute하지만, thread를 sharing하는 agent[[CanBlock]] field가 trueAgent Record를 가진 agent가 하나도 없다면 executing thread가 여러 agent에 의해 executing thread로 사용될 수 있습니다.

Note 1

예를 들어, 일부 web browser는 browser window의 unrelated tab 여러 개에 걸쳐 single executing thread를 share합니다.

agentexecuting thread가 algorithmic step을 executing하는 동안, 그 agent는 그 step에 대한 surrounding agent입니다. step은 surrounding agent를 사용하여 agent 안에 held된 specification-level execution object, 즉 running execution context, execution context stack, Agent Record의 field에 access합니다.

agent signifierAgent를 identify하는 데 사용되는 globally-unique opaque value입니다.

Table 25: 에이전트 레코드 필드
필드 이름 의미
[[LittleEndian]] Boolean 값 GetValueFromBufferSetValueInBuffer 알고리즘에서 필요할 때 isLittleEndian 매개변수에 대해 계산되는 기본값. 선택은 구현 정의이며, 해당 구현에 가장 효율적인 대안이어야 한다.
[[CanBlock]] Boolean 값 에이전트가 블록될 수 있는지 여부를 결정한다.
[[Signifier]] 에이전트 표시자 에이전트 클러스터 내에서 에이전트를 고유하게 식별한다.
[[IsLockFree1]] Boolean 값 1바이트 값에 대한 원자적 연산이 lock-free이면 true, 그렇지 않으면 false.
[[IsLockFree2]] Boolean 값 2바이트 값에 대한 원자적 연산이 lock-free이면 true, 그렇지 않으면 false.
[[IsLockFree8]] Boolean 값 8바이트 값에 대한 원자적 연산이 lock-free이면 true, 그렇지 않으면 false.
[[CandidateExecution]] candidate execution Record 메모리 모델을 참조하라.
[[KeptAlive]] Object 또는 Symbol의 List 처음에는 새 빈 List이며, 현재 Job의 끝까지 살아 있게 유지할 객체 및/또는 심벌의 목록을 나타낸다
[[ModuleAsyncEvaluationCount]] 정수 처음에는 0이며, 비동기이거나 비동기 의존성을 가진 모듈의 [[AsyncEvaluationOrder]] 필드에 고유하게 증가하는 값을 할당하는 데 사용된다.
[[GlobalSymbolRegistry]] GlobalSymbolRegistry RecordList 처음에는 새 빈 List이며, Symbol.for에 의해 생성된 Symbol 값의 목록을 나타낸다.

[[LittleEndian]], [[Signifier]], [[IsLockFree1]], [[IsLockFree2]], [[IsLockFree8]]의 값은 변경될 수 없다.

[[GlobalSymbolRegistry]] List는 추가만 가능하며 재할당되지 않는다.

Note 2

[[IsLockFree1]], [[IsLockFree2]], [[IsLockFree8]]의 value는 necessarily hardware에 의해 determined되는 것은 아니며, over time 및 ECMAScript implementation 사이에서 vary할 수 있는 implementation choice를 reflect할 수도 있습니다.

[[IsLockFree4]] field는 없습니다: 4-byte atomic operation은 항상 lock-free입니다.

실제로 atomic operation이 어떤 type의 lock으로 implement되면 그 operation은 lock-free가 아닙니다. Lock-free는 wait-free를 imply하지 않습니다: lock-free atomic operation을 complete하는 데 필요한 machine step 수에는 upper bound가 없습니다.

size가 n인 atomic access가 lock-free라는 것이 size가 n인 non-atomic access의 (perceived) atomicity에 대해 어떤 것도 imply하지 않습니다. 특히 non-atomic access는 여전히 여러 separate memory access의 sequence로 performed될 수 있습니다. detail은 ReadSharedMemoryWriteSharedMemory를 참조하십시오.

Note 3

agent는 specification mechanism이며 ECMAScript implementation의 특정 artefact에 대응할 필요가 없습니다.

9.6.1 AgentSignifier ( )

The abstract operation AgentSignifier takes no arguments and returns an agent signifier. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. agentRecord.[[Signifier]]를 반환한다.

9.6.2 AgentCanSuspend ( )

The abstract operation AgentCanSuspend takes no arguments and returns a Boolean. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. agentRecord.[[CanBlock]]을 반환한다.
Note

일부 environment에서는 주어진 agent가 suspend되는 것이 reasonable하지 않을 수 있습니다. 예를 들어, web browser environment에서는 document의 main event handling thread가 suspend되는 것을 disallow하면서 worker의 event handling thread는 suspend하도록 allow하는 것이 reasonable할 수 있습니다.

9.6.3 IncrementModuleAsyncEvaluationCount ( )

The abstract operation IncrementModuleAsyncEvaluationCount takes no arguments and returns a non-negative integer. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. countagentRecord.[[ModuleAsyncEvaluationCount]]로 둔다.
  3. agentRecord.[[ModuleAsyncEvaluationCount]]count + 1로 설정한다.
  4. count를 반환한다.
Note

이 value는 pending module 사이의 relative evaluation order를 keep track하는 데만 사용됩니다. implementation은 pending module이 없을 때마다 unobservably [[ModuleAsyncEvaluationCount]]를 0으로 reset할 수 있습니다.

9.7 Agent Clusters

agent cluster는 shared memory를 operate함으로써 communicate할 수 있는 agent의 maximal set입니다.

Note 1

서로 다른 agent 안의 program은 unspecified means로 memory를 share할 수 있습니다. 최소한 SharedArrayBuffer의 backing memory는 cluster 안의 agent들 사이에서 shared될 수 있습니다.

message passing으로 communicate할 수 있지만 memory를 share할 수 없는 agent가 있을 수 있습니다. 이들은 결코 같은 agent cluster에 있지 않습니다.

모든 agent는 exactly one agent cluster에 belong합니다.

Note 2

cluster 안의 agent가 모두 특정 시점에 alive일 필요는 없습니다. agent A가 다른 agent B를 create한 후 A가 terminate되고 Bagent C를 create하면, AB와 some memory를 share할 수 있었고 BC와 some memory를 share할 수 있었다면 세 agent는 같은 cluster에 있습니다.

cluster 안의 모든 agent는 각각의 Agent Record 안의 [[LittleEndian]] field에 대해 같은 value를 가져야 합니다.

Note 3

agent cluster 안의 서로 다른 agent[[LittleEndian]]의 different value를 가지면 multi-byte data에 shared memory를 use하기 어려워집니다.

cluster 안의 모든 agent는 각각의 Agent Record 안의 [[IsLockFree1]] field에 대해 같은 value를 가져야 합니다; [[IsLockFree2]][[IsLockFree8]] field도 마찬가지입니다.

cluster 안의 모든 agent는 각각의 Agent Record 안의 [[Signifier]] field에 대해 서로 다른 value를 가져야 합니다.

embedding은 agent의 knowledge나 cooperation 없이 agent를 deactivate(forward progress를 stop)하거나 activate(forward progress를 resume)할 수 있습니다. embedding이 그렇게 하는 경우, cluster 안의 일부 agent를 active로 남겨둔 채 다른 agent를 indefinitely deactivated 상태로 두어서는 안 됩니다.

Note 4

preceding restriction의 purpose는 다른 agent가 deactivated되어 agent가 deadlock되거나 starve되는 situation을 avoid하는 것입니다. 예를 들어, 어떤 window의 document와 independent한 lifetime을 가진 HTML shared worker가 그러한 independent document의 dedicated worker와 memory를 share할 수 있도록 allowed되었고, document와 그 dedicated worker가 dedicated worker가 lock을 hold하고 있는 동안 deactivated된다면(예: document가 window의 history에 pushed됨), shared worker가 그 lock을 acquire하려고 할 때 shared worker는 dedicated worker가 다시 activated될 때까지, 혹은 ever, blocked됩니다. Meanwhile 다른 window에서 shared worker에 access하려는 다른 worker는 starve됩니다.

restriction의 implication은 embedding 안에서 같은 suspend/wake collective에 belong하지 않는 agent 사이에서는 memory를 share할 수 없다는 것입니다.

embedding은 agent cluster의 다른 agent가 prior knowledge나 cooperation을 가지지 않아도 agent를 terminate할 수 있습니다. agent가 cluster 안의 자체 programmatic action이나 다른 agent의 programmatic action이 아니라 cluster 외부의 force에 의해 terminated되면, embedding은 두 strategy 중 하나를 choose해야 합니다: cluster 안의 모든 agent를 terminate하거나, cluster 안의 agent가 coordinate하여 cluster의 적어도 하나의 remaining member가 termination을 detect할 수 있게 하는 reliable API를 provide해야 하며, termination data는 terminated된 agent를 identify하기에 충분한 information을 contain해야 합니다.

Note 5

그 type의 termination example은 다음과 같습니다: operating system 또는 user가 separate process에서 running 중인 agent를 terminate하는 경우; per-agent resource accounting이 agent가 runaway임을 indicate할 때 embedding 자체가 다른 agent와 in-process로 running 중인 agent를 terminate하는 경우.

다음 specification value 각각과, 그것들로부터 transitively reachable한 value는 exactly one agent cluster에 belong합니다.

cluster 안의 어떤 agent가 ECMAScript code를 evaluate하기 전에, cluster 안의 모든 agent에 대한 Agent Record[[CandidateExecution]] field는 initial candidate execution으로 set됩니다. initial candidate execution[[EventsRecords]] field가 각 agent에 대해 그 agentagent signifier[[AgentSignifier]] field와 empty List[[EventList]][[AgentSynchronizesWith]] field를 가진 Agent Events Record를 contain하는 Listempty candidate execution입니다.

Note 6

agent cluster 안의 모든 agent는 그 Agent Record[[CandidateExecution]] field 안에서 같은 candidate execution을 share합니다. candidate executionmemory model에서 사용하는 specification mechanism입니다.

Note 7

agent cluster는 specification mechanism이며 ECMAScript implementation의 특정 artefact에 대응할 필요가 없습니다.

9.8 Forward Progress

agentmake forward progress한다는 것은 이 명세에 따라 evaluation step을 perform한다는 것입니다.

agentrunning execution context가 external event를 위해 synchronously and indefinitely wait할 때 agentblocked가 됩니다. Agent Record[[CanBlock]] field가 trueagent만 이러한 의미에서 blocked될 수 있습니다. unblocked agent는 blocked되지 않은 agent입니다.

implementation은 다음을 ensure해야 합니다:

  • dedicated executing thread를 가진 모든 unblocked agent는 eventually forward progress를 make합니다
  • executing thread를 share하는 agent의 set 안에서는 하나의 agent가 eventually forward progress를 make합니다
  • agent는 blocking을 provide하는 explicit API를 통하지 않고는 다른 agent를 blocked되게 cause하지 않습니다.
Note

이는 memory model의 liveness guarantee와 함께, 모든 seq-cst write가 eventually 모든 agent에 observable하게 됨을 ensure합니다.

9.9 Processing Model of WeakRef and FinalizationRegistry Targets

9.9.1 Objectives

이 명세는 어떤 object 또는 symbol도 garbage collected될 것이라는 guarantee를 하지 않습니다. live가 아닌 object 또는 symbol은 long period of time 후에 released될 수도 있고, 전혀 released되지 않을 수도 있습니다. 이러한 이유로, 이 명세는 garbage collection에 의해 triggered되는 behaviour를 describing할 때 “may”라는 term을 사용합니다.

WeakRefFinalizationRegistry의 semantics는 특정 point in time에 발생하는 두 operation에 기반합니다:

  • WeakRef.prototype.deref가 called될 때, referent(undefined가 returned되지 않는 경우)는 subsequent synchronous access도 같은 value를 return하도록 alive로 kept됩니다. 이 list는 ClearKeptObjects abstract operation을 사용하여 synchronous work가 done될 때 reset됩니다.
  • FinalizationRegistry에 registered된 object 또는 symbol이 unreachable이 되면, synchronous ECMAScript execution이 completes된 후 FinalizationRegistry의 cleanup callback call이 eventually made될 수 있습니다. FinalizationRegistry cleanup은 CleanupFinalizationRegistry abstract operation으로 performed됩니다.

이러한 action(ClearKeptObjects 또는 CleanupFinalizationRegistry) 중 어느 것도 synchronous ECMAScript execution을 interrupt할 수 없습니다. host는 더 긴 synchronous ECMAScript execution run을 assemble할 수 있으므로, 이 명세는 ClearKeptObjectsCleanupFinalizationRegistry의 scheduling을 host environment에 defer합니다.

일부 ECMAScript implementation은 ECMAScript가 idle일 때를 포함하여 background에서 run하는 garbage collector implementation을 포함합니다. host environmentCleanupFinalizationRegistry를 schedule하게 하면 finalizer work를 run하기 위해 ECMAScript execution을 resume할 수 있으며, 이는 held value를 free up하여 overall memory usage를 reduce할 수 있습니다.

9.9.2 Liveness

object 및/또는 symbol의 어떤 set objSet에 대해 objSet와 관련한 hypothetical WeakRef-oblivious execution은 referent가 objSet의 element인 WeakRef의 abstract operation WeakRefDeref가 항상 undefined를 반환하는 execution입니다.

Note 1
WeakRef-obliviousness는 liveness와 함께 두 notion을 capture합니다. 첫째, WeakRef 자체는 그 referent를 alive로 keep하지 않습니다. 둘째, liveness의 cycle은 value가 live임을 imply하지 않습니다. 구체적으로, v의 liveness를 determining하는 것이 WeakRef referent r의 liveness를 determining하는 것에 depend한다면, r의 liveness는 v의 liveness를 assume할 수 없습니다. 이는 circular reasoning이기 때문입니다.
Note 2
WeakRef-obliviousness는 cycle을 account하기 위해 individual value 대신 object 또는 symbol의 set에 대해 정의됩니다. individual value에 대해 정의된다면, cycle 안의 WeakRef referent는 그 identity가 cycle 안의 다른 WeakRef referent를 통해서만 observed되더라도 live로 considered될 것입니다.
Note 3
Colloquially, 우리는 individual object 또는 symbol이 그것을 contain하는 모든 set이 live이면 live라고 말합니다.

evaluation 중 어느 point에서든, object 및/또는 symbol의 set objSet는 다음 조건 중 하나가 met되면 live로 considered됩니다:

  • objSet 안의 어떤 element가 어떤 agent[[KeptAlive]] List에 included되어 있습니다.
  • objSet와 관련하여 valid future hypothetical WeakRef-oblivious execution이 존재하며, 이는 objSet 안의 어떤 value의 identity를 observe합니다.
Note 4
위의 두 번째 condition은 value의 identity가 non-WeakRef means를 통해 observable하면 그 value가 live라는 intuition을 capture하려는 의도입니다. value의 identity는 strict equality comparison을 observing하거나 Map의 key로 사용되는 value를 observing함으로써 observed될 수 있습니다.
Note 5

field, internal slot 또는 property 안에 object나 symbol이 존재한다는 것은 그 value가 live임을 imply하지 않습니다. 예를 들어 해당 value가 program에 다시 passed되지 않으면, it cannot be observed.

이는 WeakMap의 key, WeakSet의 member, 그리고 FinalizationRegistry Cell record의 [[WeakRefTarget]][[UnregisterToken]] field의 경우에 해당합니다.

위 definition은, WeakMap 안의 key가 live가 아니면, 그 corresponding value도 necessarily live인 것은 아님을 imply합니다.

Note 6
Liveness는 engine이 반드시 empty하지 않아야 하는 WeakRef를 guarantee하기 위한 lower bound입니다. 여기서 정의된 Liveness는 undecidable입니다. 실제로 engine은 reachability 같은 conservative approximation을 사용합니다. significant implementation leeway가 expected됩니다.

9.9.3 Execution

어느 때든 object 및/또는 symbol의 set objSetlive가 아니면, ECMAScript implementation은 다음 step을 atomically perform할 수 있습니다:

  1. objSet의 각 element value에 대해, 다음을 수행한다.
    1. ref.[[WeakRefTarget]]value인 각 WeakRef ref에 대해, 다음을 수행한다.
      1. ref.[[WeakRefTarget]]empty로 설정한다.
    2. finalizationRegistry.[[Cells]]cell.[[WeakRefTarget]]valueRecord cell을 contain하는 각 FinalizationRegistry finalizationRegistry에 대해, 다음을 수행한다.
      1. cell.[[WeakRefTarget]]empty로 설정한다.
      2. enqueueCleanuptrue 또는 false 중 하나의 implementation-defined choice로 둔다.
      3. enqueueCleanuptrue이면, HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)를 수행한다.
    3. map.[[WeakMapData]]entry.[[Key]]valueRecord entry를 contain하는 각 WeakMap map에 대해, 다음을 수행한다.
      1. entry.[[Key]]empty로 설정한다.
      2. entry.[[Value]]empty로 설정한다.
    4. set.[[WeakSetData]]value를 contain하는 각 WeakSet set에 대해, 다음을 수행한다.
      1. set.[[WeakSetData]] 안에서 value가 value인 element를 value가 empty인 element로 replace한다.
Note 1

liveness의 definition과 함께, 이 clause는 implementation이 WeakRef와 관련하여 apply할 수 있는 optimization을 prescribe합니다.

object의 identity를 observing하지 않고 object에 access하는 것이 가능합니다. identity가 observed되지 않는 non-escaping object의 property에 대한 dead variable elimination 및 scalar replacement 같은 optimization은 allowed됩니다. 따라서 이러한 optimization은 그러한 object를 point하는 WeakRef를 observably empty하는 것을 allow합니다.

반면, object의 identity가 observable이고 그 object가 WeakRef[[WeakRefTarget]] internal slot 안에 있으면, WeakRef를 observably empty하는 rematerialization 같은 optimization은 prohibited됩니다.

HostEnqueueFinalizationRegistryCleanupJob을 calling하는 것은 optional이므로, FinalizationRegistry 안의 registered object가 necessarily 그 FinalizationRegistrylive로 hold하지는 않습니다. implementation은 어떤 이유로든 FinalizationRegistry callback을 omit할 수 있습니다. 예를 들어, FinalizationRegistry 자체가 dead가 되거나 application이 shutting down되는 경우입니다.

Note 2

implementation은 non-live object 또는 symbol의 maximal set에 대해 WeakRef를 empty할 의무가 없습니다.

implementation이 WeakRef를 empty할 non-live set objSet을 choose하면, 이 definition은 objSet 안의 모든 value에 대한 WeakRef를 simultaneously empty할 것을 require합니다. 다시 말해, implementation이 value v를 point하는 WeakRef를 empty하면서, empty하지 않으면 v의 value를 observe하는 execution을 result할 수 있는 다른 WeakRef를 empty하지 않는 것은 conformant하지 않습니다.

9.9.4 Host Hooks

9.9.4.1 HostEnqueueFinalizationRegistryCleanupJob ( finalizationRegistry )

The host-defined abstract operation HostEnqueueFinalizationRegistryCleanupJob takes argument finalizationRegistry (a FinalizationRegistry) and returns unused.

cleanupJob을 parameter가 없고 finalizationRegistry를 capture하며 called될 때 다음 step을 수행하는 새 Job Abstract Closure로 둔다:

  1. cleanupResultCompletion(CleanupFinalizationRegistry(finalizationRegistry))로 둔다.
  2. cleanupResultabrupt completion이면, error를 reporting하기 위한 host-defined step을 수행한다.
  3. unused를 반환한다.

HostEnqueueFinalizationRegistryCleanupJob의 implementation은 가능하면 cleanupJob이 future time에 performed되도록 schedule합니다. 또한 9.5의 requirement를 conform해야 합니다.

9.10 ClearKeptObjects ( )

The abstract operation ClearKeptObjects takes no arguments and returns unused. ECMAScript implementation은 synchronous sequence of ECMAScript executions가 completes될 때 ClearKeptObjects를 call할 것으로 expected됩니다. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. agentRecord.[[KeptAlive]]를 새 empty List로 설정한다.
  3. unused를 반환한다.

9.11 AddToKeptObjects ( value )

The abstract operation AddToKeptObjects takes argument value (an Object or a Symbol) and returns unused. It performs the following steps when called:

  1. agentRecordsurrounding agentAgent Record로 둔다.
  2. valueagentRecord.[[KeptAlive]]에 append한다.
  3. unused를 반환한다.
Note
abstract operation AddToKeptObjects가 target object 또는 symbol과 함께 called되면, 이는 ClearKeptObjects가 called될 때까지 target을 strongly point할 list에 target을 add합니다.

9.12 CleanupFinalizationRegistry ( finalizationRegistry )

The abstract operation CleanupFinalizationRegistry takes argument finalizationRegistry (a FinalizationRegistry) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. Assert: finalizationRegistry[[Cells]][[CleanupCallback]] internal slot을 가진다.
  2. callbackfinalizationRegistry.[[CleanupCallback]]으로 둔다.
  3. finalizationRegistry.[[Cells]]cell.[[WeakRefTarget]]emptyRecord cell을 contain하는 동안, implementation은 다음 step을 수행할 수 있다:
    1. 그러한 cell 중 아무 것이나 choose한다.
    2. finalizationRegistry.[[Cells]]에서 cell을 remove한다.
    3. HostCallJobCallback(callback, undefined, « cell.[[HeldValue]] »)를 수행한다.
  4. unused를 반환한다.

9.13 CanBeHeldWeakly ( arg )

The abstract operation CanBeHeldWeakly takes argument arg (an ECMAScript language value) and returns a Boolean. arg가 weak reference로 사용하기에 suitable하면 and only if true를 반환합니다. weak reference로 사용하기에 suitable한 value만 WeakMap의 key, WeakSet의 element, WeakRef의 target, 또는 FinalizationRegistry의 target 중 하나일 수 있습니다. It performs the following steps when called:

  1. arg가 Object이면, true를 반환한다.
  2. arg가 Symbol이고 KeyForSymbol(arg)이 undefined이면, true를 반환한다.
  3. false를 반환한다.
Note

language identity가 없는 language value는 prior reference 없이 manifested될 수 있으므로 weak reference로 사용하기에 unsuitable합니다. Symbol.for가 produced한 Symbol value는 다른 Symbol value와 달리 language identity를 가지지 않으며 weak reference로 사용하기에 unsuitable합니다. Well-known symbols는 collected되지 않을 가능성이 높지만, number가 limited되어 다양한 implementation approach로 manageable하기 때문에 nonetheless weak reference로 사용하기에 suitable한 것으로 treated됩니다. 그러나 live WeakMap 안의 well-known symbol에 associated된 value는 collected될 가능성이 낮고 implementation에서 memory resource를 “leak”할 수 있습니다.