10 일반 객체 및 이색 객체 동작

10.1 일반 객체 내부 메서드와 내부 슬롯

모든 일반 객체는 [[Prototype]]이라는 내부 슬롯을 가진다. 이 내부 슬롯의 값은 null 또는 객체이며 상속을 구현하는 데 사용된다. propertyKey라는 이름의 프로퍼티가 일반 객체 obj에는 없지만 그 [[Prototype]] 객체에는 존재한다고 가정하자. propertyKey[[Prototype]] 객체의 데이터 프로퍼티를 가리키면, obj는 get 접근에 대해 그것을 상속받아 propertyKeyobj의 프로퍼티인 것처럼 동작한다. propertyKey[[Prototype]] 객체의 쓰기 가능한 데이터 프로퍼티를 가리키면, obj에서 propertyKey에 대한 set 접근은 objpropertyKey라는 이름의 새로운 데이터 프로퍼티를 생성한다. propertyKey[[Prototype]] 객체의 쓰기 불가능한 데이터 프로퍼티를 가리키면, obj에서 propertyKey에 대한 set 접근은 실패한다. propertyKey[[Prototype]] 객체의 접근자 프로퍼티를 가리키면, 그 접근자는 get 접근과 set 접근 모두에 대해 obj에 상속된다.

모든 일반 객체는 Boolean 값의 [[Extensible]] 내부 슬롯을 가지며, 이는 6.1.7.3에 명시된 확장 가능성과 관련된 내부 메서드 불변식을 충족하는 데 사용된다. 즉, 객체의 [[Extensible]] 내부 슬롯 값이 한 번 false로 설정되면, 더 이상 그 객체에 프로퍼티를 추가하거나, 객체의 [[Prototype]] 내부 슬롯 값을 수정하거나, 이후 [[Extensible]]의 값을 true로 다시 변경하는 것은 불가능하다.

다음 알고리즘 설명에서, obj는 일반 객체이고, propertyKey는 프로퍼티 키 값이며, value는 임의의 ECMAScript 언어 값이고, descProperty Descriptor 레코드라고 가정한다.

각 일반 객체 내부 메서드는 유사한 이름의 추상 연산에 위임한다. 그러한 추상 연산이 다른 내부 메서드에 의존한다면, 유사한 이름의 추상 연산을 직접 호출하는 대신 그 내부 메서드가 obj에 대해 호출된다. 이러한 의미론은 일반 객체 내부 메서드가 이색 객체에 적용될 때, 이색 객체가 재정의한 내부 메서드가 호출되도록 보장한다.

10.1.1 [[GetPrototypeOf]] ( )

The [[GetPrototypeOf]] internal method of 일반 객체 obj takes no arguments and returns a normal completion containing either an Object or null. It performs the following steps when called:

  1. OrdinaryGetPrototypeOf(obj)를 반환한다.

10.1.1.1 OrdinaryGetPrototypeOf ( obj )

The abstract operation OrdinaryGetPrototypeOf takes argument obj (an Object) and returns an Object or null. It performs the following steps when called:

  1. obj.[[Prototype]]를 반환한다.

10.1.2 [[SetPrototypeOf]] ( proto )

The [[SetPrototypeOf]] internal method of 일반 객체 obj takes argument proto (an Object or null) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. OrdinarySetPrototypeOf(obj, proto)를 반환한다.

10.1.2.1 OrdinarySetPrototypeOf ( obj, proto )

The abstract operation OrdinarySetPrototypeOf takes arguments obj (an Object) and proto (an Object or null) and returns a Boolean. It performs the following steps when called:

  1. currentobj.[[Prototype]]라고 하자.
  2. SameValue(proto, current)가 true이면, true를 반환한다.
  3. extensibleobj.[[Extensible]]이라고 하자.
  4. extensiblefalse이면, false를 반환한다.
  5. cursorproto라고 하자.
  6. donefalse라고 하자.
  7. donefalse인 동안, 다음을 반복한다.
    1. cursornull이면,
      1. donetrue로 설정한다.
    2. 그렇지 않고 SameValue(cursor, obj)가 true이면,
      1. false를 반환한다.
    3. 그렇지 않으면,
      1. cursor.[[GetPrototypeOf]]10.1.1에 정의된 일반 객체 내부 메서드가 아니면, donetrue로 설정한다.
      2. 그렇지 않으면, cursorcursor.[[Prototype]]로 설정한다.
  8. obj.[[Prototype]]proto로 설정한다.
  9. true를 반환한다.
Note

단계 7의 반복은 [[GetPrototypeOf]][[SetPrototypeOf]]에 대해 일반 객체 정의를 사용하는 객체만 포함하는 모든 프로토타입 체인에 순환이 없음을 보장한다.

10.1.3 [[IsExtensible]] ( )

The [[IsExtensible]] internal method of 일반 객체 obj takes no arguments and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. OrdinaryIsExtensible(obj)를 반환한다.

10.1.3.1 OrdinaryIsExtensible ( obj )

The abstract operation OrdinaryIsExtensible takes argument obj (an Object) and returns a Boolean. It performs the following steps when called:

  1. obj.[[Extensible]]를 반환한다.

10.1.4 [[PreventExtensions]] ( )

The [[PreventExtensions]] internal method of 일반 객체 obj takes no arguments and returns a normal completion containing true. It performs the following steps when called:

  1. OrdinaryPreventExtensions(obj)를 반환한다.

10.1.4.1 OrdinaryPreventExtensions ( obj )

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

  1. obj.[[Extensible]]false로 설정한다.
  2. true를 반환한다.

10.1.5 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of 일반 객체 obj takes argument propertyKey (a property key) and returns a normal completion containing either a Property Descriptor or undefined. It performs the following steps when called:

  1. OrdinaryGetOwnProperty(obj, propertyKey)를 반환한다.

10.1.5.1 OrdinaryGetOwnProperty ( obj, propertyKey )

The abstract operation OrdinaryGetOwnProperty takes arguments obj (an Object) and propertyKey (a property key) and returns a Property Descriptor or undefined. It performs the following steps when called:

  1. obj가 키가 propertyKey인 자체 프로퍼티를 가지지 않으면, undefined를 반환한다.
  2. 필드가 없는 새로 생성된 Property Descriptordesc라고 하자.
  3. ownProperty를 키가 propertyKeyobj의 자체 프로퍼티라고 하자.
  4. ownProperty가 데이터 프로퍼티이면,
    1. desc.[[Value]]ownProperty[[Value]] 속성 값으로 설정한다.
    2. desc.[[Writable]]ownProperty[[Writable]] 속성 값으로 설정한다.
  5. 그렇지 않으면,
    1. Assert: ownProperty는 접근자 프로퍼티이다.
    2. desc.[[Get]]ownProperty[[Get]] 속성 값으로 설정한다.
    3. desc.[[Set]]ownProperty[[Set]] 속성 값으로 설정한다.
  6. desc.[[Enumerable]]ownProperty[[Enumerable]] 속성 값으로 설정한다.
  7. desc.[[Configurable]]ownProperty[[Configurable]] 속성 값으로 설정한다.
  8. desc를 반환한다.

10.1.6 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of 일반 객체 obj takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. OrdinaryDefineOwnProperty(obj, propertyKey, desc)를 반환한다.

10.1.6.1 OrdinaryDefineOwnProperty ( obj, propertyKey, desc )

The abstract operation OrdinaryDefineOwnProperty takes arguments obj (an Object), propertyKey (a property key), and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. current를 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  2. extensible을 ? IsExtensible(obj)라고 하자.
  3. ValidateAndApplyPropertyDescriptor(obj, propertyKey, extensible, desc, current)를 반환한다.

10.1.6.2 IsCompatiblePropertyDescriptor ( extensible, desc, current )

The abstract operation IsCompatiblePropertyDescriptor takes arguments extensible (a Boolean), desc (a Property Descriptor), and current (a Property Descriptor or undefined) and returns a Boolean. It performs the following steps when called:

  1. ValidateAndApplyPropertyDescriptor(undefined, "", extensible, desc, current)를 반환한다.

10.1.6.3 ValidateAndApplyPropertyDescriptor ( obj, propertyKey, extensible, desc, current )

The abstract operation ValidateAndApplyPropertyDescriptor takes arguments obj (an Object or undefined), propertyKey (a property key), extensible (a Boolean), desc (a Property Descriptor), and current (a Property Descriptor or undefined) and returns a Boolean. 이것은 desc를, 명시된 extensibility와 현재 프로퍼티 current를 가진 객체의 프로퍼티로 적용하면서 불변식을 유지할 수 있는 경우에만 true를 반환한다. 그러한 적용이 가능하고 objundefined가 아니면, propertyKey라는 이름의 프로퍼티에 대해 그 적용이 수행된다(필요하면 생성된다). It performs the following steps when called:

  1. Assert: propertyKey는 프로퍼티 키이다.
  2. currentundefined이면,
    1. extensiblefalse이면, false를 반환한다.
    2. objundefined이면, true를 반환한다.
    3. IsAccessorDescriptor(desc)가 true이면,
      1. desc에 해당 필드가 있으면 그 값으로, 없으면 해당 속성의 기본값으로 [[Get]], [[Set]], [[Enumerable]], [[Configurable]] 속성이 설정된 propertyKey라는 이름의 자체 접근자 프로퍼티를 객체 obj에 생성한다.
    4. 그렇지 않으면,
      1. desc에 해당 필드가 있으면 그 값으로, 없으면 해당 속성의 기본값으로 [[Value]], [[Writable]], [[Enumerable]], [[Configurable]] 속성이 설정된 propertyKey라는 이름의 자체 데이터 프로퍼티를 객체 obj에 생성한다.
    5. true를 반환한다.
  3. Assert: current는 완전히 채워진 Property Descriptor이다.
  4. desc가 어떤 필드도 가지지 않으면, true를 반환한다.
  5. current.[[Configurable]]false이면,
    1. desc[[Configurable]] 필드를 가지고 있고 desc.[[Configurable]]true이면, false를 반환한다.
    2. desc[[Enumerable]] 필드를 가지고 있고 desc.[[Enumerable]]current.[[Enumerable]]과 같지 않으면, false를 반환한다.
    3. IsGenericDescriptor(desc)가 false이고 IsAccessorDescriptor(desc)가 IsAccessorDescriptor(current)와 같지 않으면, false를 반환한다.
    4. IsAccessorDescriptor(current)가 true이면,
      1. desc[[Get]] 필드를 가지고 있고 SameValue(desc.[[Get]], current.[[Get]])가 false이면, false를 반환한다.
      2. desc[[Set]] 필드를 가지고 있고 SameValue(desc.[[Set]], current.[[Set]])가 false이면, false를 반환한다.
    5. 그렇지 않고 current.[[Writable]]false이면,
      1. desc[[Writable]] 필드를 가지고 있고 desc.[[Writable]]true이면, false를 반환한다.
      2. NOTE: SameValue는 다른 수단으로 구별될 수 있는 NaN 값에 대해서도 true를 반환한다. 여기서 반환함으로써 obj의 기존 프로퍼티가 수정되지 않도록 보장한다.
      3. desc[[Value]] 필드를 가지고 있으면, SameValue(desc.[[Value]], current.[[Value]])를 반환한다.
  6. objundefined가 아니면,
    1. IsDataDescriptor(current)가 true이고 IsAccessorDescriptor(desc)가 true이면,
      1. desc[[Configurable]] 필드를 가지면 configurabledesc.[[Configurable]]라고 하자; 그렇지 않으면 configurablecurrent.[[Configurable]]라고 하자.
      2. desc[[Enumerable]] 필드를 가지면 enumerabledesc.[[Enumerable]]라고 하자; 그렇지 않으면 enumerablecurrent.[[Enumerable]]라고 하자.
      3. 객체 objpropertyKey라는 이름의 프로퍼티를, [[Configurable]][[Enumerable]] 속성은 각각 configurableenumerable로 설정하고, [[Get]][[Set]] 속성은 desc에 해당 필드가 있으면 그 값으로, 없으면 해당 속성의 기본값으로 설정한 접근자 프로퍼티로 교체한다.
    2. 그렇지 않고 IsAccessorDescriptor(current)가 true이며 IsDataDescriptor(desc)가 true이면,
      1. desc[[Configurable]] 필드를 가지면 configurabledesc.[[Configurable]]라고 하자; 그렇지 않으면 configurablecurrent.[[Configurable]]라고 하자.
      2. desc[[Enumerable]] 필드를 가지면 enumerabledesc.[[Enumerable]]라고 하자; 그렇지 않으면 enumerablecurrent.[[Enumerable]]라고 하자.
      3. 객체 objpropertyKey라는 이름의 프로퍼티를, [[Configurable]][[Enumerable]] 속성은 각각 configurableenumerable로 설정하고, [[Value]][[Writable]] 속성은 desc에 해당 필드가 있으면 그 값으로, 없으면 해당 속성의 기본값으로 설정한 데이터 프로퍼티로 교체한다.
    3. 그렇지 않으면,
      1. desc의 각 필드 이름 fieldName에 대해, 객체 objpropertyKey라는 이름의 프로퍼티에서 fieldName이라는 속성을 descfieldName 필드 값으로 설정한다.
  7. true를 반환한다.

10.1.7 [[HasProperty]] ( propertyKey )

The [[HasProperty]] internal method of 일반 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. OrdinaryHasProperty(obj, propertyKey)를 반환한다.

10.1.7.1 OrdinaryHasProperty ( obj, propertyKey )

The abstract operation OrdinaryHasProperty takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. hasOwn을 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  2. hasOwnundefined가 아니면, true를 반환한다.
  3. parent를 ? obj.[[GetPrototypeOf]]()라고 하자.
  4. parentnull이 아니면,
    1. parent.[[HasProperty]](propertyKey)를 반환한다.
  5. false를 반환한다.

10.1.8 [[Get]] ( propertyKey, receiver )

The [[Get]] internal method of 일반 객체 obj takes arguments propertyKey (a property key) and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. OrdinaryGet(obj, propertyKey, receiver)를 반환한다.

10.1.8.1 OrdinaryGet ( obj, propertyKey, receiver )

The abstract operation OrdinaryGet takes arguments obj (an Object), propertyKey (a property key), and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. desc를 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  2. descundefined이면,
    1. parent를 ? obj.[[GetPrototypeOf]]()라고 하자.
    2. parentnull이면, undefined를 반환한다.
    3. parent.[[Get]](propertyKey, receiver)를 반환한다.
  3. IsDataDescriptor(desc)가 true이면, desc.[[Value]]를 반환한다.
  4. Assert: IsAccessorDescriptor(desc)는 true이다.
  5. getterdesc.[[Get]]이라고 하자.
  6. getterundefined이면, undefined를 반환한다.
  7. Call(getter, receiver)를 반환한다.

10.1.9 [[Set]] ( propertyKey, value, receiver )

The [[Set]] internal method of 일반 객체 obj takes arguments propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. OrdinarySet(obj, propertyKey, value, receiver)를 반환한다.

10.1.9.1 OrdinarySet ( obj, propertyKey, value, receiver )

The abstract operation OrdinarySet takes arguments obj (an Object), propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ownDesc를 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  2. OrdinarySetWithOwnDescriptor(obj, propertyKey, value, receiver, ownDesc)를 반환한다.

10.1.9.2 OrdinarySetWithOwnDescriptor ( obj, propertyKey, value, receiver, ownDesc )

The abstract operation OrdinarySetWithOwnDescriptor takes arguments obj (an Object), propertyKey (a property key), value (an ECMAScript language value), receiver (an ECMAScript language value), and ownDesc (a Property Descriptor or undefined) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ownDescundefined이면,
    1. parent를 ? obj.[[GetPrototypeOf]]()라고 하자.
    2. parentnull이 아니면, ? parent.[[Set]](propertyKey, value, receiver)를 반환한다.
    3. ownDesc를 PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }로 설정한다.
  2. IsDataDescriptor(ownDesc)가 true이면,
    1. ownDesc.[[Writable]]false이면, false를 반환한다.
    2. receiver가 Object가 아니면, false를 반환한다.
    3. existingDescriptor를 ? receiver.[[GetOwnProperty]](propertyKey)라고 하자.
    4. existingDescriptorundefined이면,
      1. Assert: receiver는 현재 propertyKey 프로퍼티를 가지고 있지 않다.
      2. CreateDataProperty(receiver, propertyKey, value)를 반환한다.
    5. IsAccessorDescriptor(existingDescriptor)가 true이면, false를 반환한다.
    6. existingDescriptor.[[Writable]]false이면, false를 반환한다.
    7. valueDesc를 PropertyDescriptor { [[Value]]: value }라고 하자.
    8. receiver.[[DefineOwnProperty]](propertyKey, valueDesc)를 반환한다.
  3. Assert: IsAccessorDescriptor(ownDesc)는 true이다.
  4. setterownDesc.[[Set]]이라고 하자.
  5. setterundefined이면, false를 반환한다.
  6. Call(setter, receiver, « value »)를 수행한다.
  7. true를 반환한다.

10.1.10 [[Delete]] ( propertyKey )

The [[Delete]] internal method of 일반 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. OrdinaryDelete(obj, propertyKey)를 반환한다.

10.1.10.1 OrdinaryDelete ( obj, propertyKey )

The abstract operation OrdinaryDelete takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. desc를 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  2. descundefined이면, true를 반환한다.
  3. desc.[[Configurable]]true이면,
    1. obj에서 이름이 propertyKey인 자체 프로퍼티를 제거한다.
    2. true를 반환한다.
  4. false를 반환한다.

10.1.11 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of 일반 객체 obj takes no arguments and returns a normal completion containing a List of property keys. It performs the following steps when called:

  1. OrdinaryOwnPropertyKeys(obj)를 반환한다.

10.1.11.1 OrdinaryOwnPropertyKeys ( obj )

The abstract operation OrdinaryOwnPropertyKeys takes argument obj (an Object) and returns a List of property keys. It performs the following steps when called:

  1. 새로운 빈 Listkeys라고 하자.
  2. obj의 각 자체 프로퍼티 키 propertyKeypropertyKey가 배열 인덱스인 것에 대해, 숫자 인덱스 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  3. obj의 각 자체 프로퍼티 키 propertyKeypropertyKey가 String이고 배열 인덱스가 아닌 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  4. obj의 각 자체 프로퍼티 키 propertyKeypropertyKey가 Symbol인 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  5. keys를 반환한다.

10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] )

The abstract operation OrdinaryObjectCreate takes argument proto (an Object or null) and optional argument additionalInternalSlotsList (a List of names of internal slots) and returns an Object. 이것은 새로운 일반 객체의 런타임 생성을 명세하는 데 사용된다. additionalInternalSlotsList[[Prototype]][[Extensible]] 외에, 객체의 일부로 정의되어야 하는 추가 내부 슬롯들의 이름을 담고 있다. additionalInternalSlotsList가 제공되지 않으면, 새로운 빈 List가 사용된다. It performs the following steps when called:

  1. internalSlotsList를 « [[Prototype]], [[Extensible]] »라고 하자.
  2. additionalInternalSlotsList가 존재하면, internalSlotsListinternalSlotsListadditionalInternalSlotsList의 리스트 연결로 설정한다.
  3. objMakeBasicObject(internalSlotsList)라고 하자.
  4. obj.[[Prototype]]proto로 설정한다.
  5. obj를 반환한다.
Note

OrdinaryObjectCreate는 MakeBasicObject를 호출하는 것 외에 거의 하는 일이 없지만, 그 사용은 이색 객체가 아닌 일반 객체를 생성하려는 의도를 전달한다. 따라서 이 명세 안에서, 결과를 비일반적으로 만드는 방식으로 객체의 내부 메서드를 이후 수정하는 어떤 알고리즘도 이것을 호출하지 않는다. 이색 객체를 생성하는 연산은 MakeBasicObject를 직접 호출한다.

10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

The abstract operation OrdinaryCreateFromConstructor takes arguments constructor (a function object) and intrinsicDefaultProto (a String) and optional argument internalSlotsList (a List of names of internal slots) and returns either a normal completion containing an Object or a throw completion. 이것은 [[Prototype]] 값이 생성자의 "prototype" 프로퍼티에서 존재하면 거기서 가져와지는 일반 객체를 생성한다. 그렇지 않으면 intrinsicDefaultProto로 명명된 intrinsic이 [[Prototype]]에 사용된다. internalSlotsList는 객체의 일부로 정의되어야 하는 추가 내부 슬롯들의 이름을 담고 있다. internalSlotsList가 제공되지 않으면, 새로운 빈 List가 사용된다. It performs the following steps when called:

  1. Assert: intrinsicDefaultProto는 이 명세에서 intrinsic 객체의 이름이다. 대응하는 객체는 객체의 [[Prototype]] 값으로 사용되도록 의도된 intrinsic이어야 한다.
  2. proto를 ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto)라고 하자.
  3. internalSlotsList가 존재하면, slotsListinternalSlotsList라고 하자.
  4. 그렇지 않으면, slotsList를 새로운 빈 List라고 하자.
  5. OrdinaryObjectCreate(proto, slotsList)를 반환한다.

10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

The abstract operation GetPrototypeFromConstructor takes arguments constructor (a function object) and intrinsicDefaultProto (a String) and returns either a normal completion containing an Object or a throw completion. 이것은 특정 생성자에 대응하는 객체를 만들 때 사용해야 하는 [[Prototype]] 값을 결정한다. 그 값은 생성자의 "prototype" 프로퍼티가 존재하면 거기서 가져온다. 그렇지 않으면 intrinsicDefaultProto로 명명된 intrinsic이 [[Prototype]]에 사용된다. It performs the following steps when called:

  1. Assert: intrinsicDefaultProto는 이 명세에서 intrinsic 객체의 이름이다. 대응하는 객체는 객체의 [[Prototype]] 값으로 사용되도록 의도된 intrinsic이어야 한다.
  2. proto를 ? Get(constructor, "prototype")이라고 하자.
  3. proto가 Object가 아니면,
    1. realm을 ? GetFunctionRealm(constructor)이라고 하자.
    2. protorealmintrinsicDefaultProto라는 이름의 intrinsic 객체로 설정한다.
  4. proto를 반환한다.
Note

constructor[[Prototype]] 값을 제공하지 않으면, 사용되는 기본값은 실행 중인 실행 컨텍스트가 아니라 constructor 함수의 realm에서 가져온다.

10.1.15 RequireInternalSlot ( obj, internalSlot )

The abstract operation RequireInternalSlot takes arguments obj (an ECMAScript language value) and internalSlot (an internal slot name) and returns either a normal completion containing unused or a throw completion. 이것은 obj가 Object이고 주어진 내부 슬롯을 가지는 경우가 아니면 예외를 던진다. It performs the following steps when called:

  1. obj가 Object가 아니면, TypeError 예외를 던진다.
  2. objinternalSlot 내부 슬롯을 가지지 않으면, TypeError 예외를 던진다.
  3. unused를 반환한다.

10.2 ECMAScript 함수 객체

ECMAScript 함수 객체는 어휘 환경에 대해 닫힌 매개변수화된 ECMAScript 코드를 캡슐화하며, 그 코드의 동적 평가를 지원한다. ECMAScript 함수 객체는 일반 객체이며, 다른 일반 객체와 동일한 내부 슬롯과 동일한 내부 메서드를 가진다. ECMAScript 함수 객체의 코드는 strict mode 코드(11.2.2)이거나 non-strict 코드일 수 있다. 코드가 strict mode 코드인 ECMAScript 함수 객체는 strict function 이라고 한다. 코드가 strict mode 코드가 아닌 것은 non-strict function이라고 한다.

[[Extensible]][[Prototype]] 외에도, ECMAScript 함수 객체는 Table 25 에 나열된 내부 슬롯도 가진다.

Table 25: Internal Slots of ECMAScript Function Objects
내부 슬롯 타입 설명
[[Environment]] an Environment Record 함수가 닫혀 있던 Environment Record이다. 함수의 코드를 평가할 때 바깥 환경으로 사용된다.
[[PrivateEnvironment]] a PrivateEnvironment Record or null 함수가 닫혀 있던 Private Name들을 위한 PrivateEnvironment Record이다. 이 함수가 구문적으로 클래스 안에 포함되어 있지 않다면 null이다. 함수의 코드를 평가할 때 내부 클래스들의 바깥 PrivateEnvironment로 사용된다.
[[FormalParameters]] a Parse Node 함수의 형식 매개변수 목록을 정의하는 소스 텍스트의 루트 parse node이다.
[[ECMAScriptCode]] a Parse Node 함수의 본문을 정의하는 소스 텍스트의 루트 parse node이다.
[[ConstructorKind]] base or derived 함수가 파생 클래스 생성자인지 여부.
[[Realm]] a Realm Record 함수가 생성된 realm이며, 함수를 평가할 때 접근되는 모든 intrinsic 객체를 제공한다.
[[ScriptOrModule]] a Script Record or a Module Record 함수가 생성된 script 또는 module.
[[ThisMode]] lexical, strict, or global 함수의 형식 매개변수와 코드 본문 안에서 this 참조가 어떻게 해석되는지를 정의한다. lexicalthis가 어휘적으로 둘러싼 함수의 this 값을 가리킨다는 뜻이다. strictthis 값이 함수 호출 시 제공된 그대로 사용된다는 뜻이다. globalthis 값이 undefined 또는 null이면 전역 객체에 대한 참조로 해석되고, 그 외의 this 값은 먼저 ToObject에 전달된다는 뜻이다.
[[Strict]] a Boolean 이것이 strict function이면 true, non-strict function이면 false.
[[HomeObject]] an Object or undefined 함수가 super를 사용한다면, 이것은 [[GetPrototypeOf]]super 프로퍼티 조회가 시작되는 객체를 제공하는 객체이다.
[[SourceText]] a sequence of Unicode code points 함수를 정의하는 source text.
[[Fields]] a List of ClassFieldDefinition Records 함수가 클래스라면, 이것은 클래스의 non-static 필드와 그에 대응하는 initializer를 나타내는 Record들의 리스트이다.
[[PrivateMethods]] a List of PrivateElements 함수가 클래스라면, 이것은 클래스의 non-static private 메서드와 접근자를 나타내는 리스트이다.
[[ClassFieldInitializerName]] a String, a Symbol, a Private Name, or empty 함수가 클래스 필드의 initializer로 생성된 경우, 필드의 NamedEvaluation에 사용할 이름이며, 그렇지 않으면 empty이다.
[[IsClassConstructor]] a Boolean 함수가 클래스 생성자인지 여부를 나타낸다. (true이면, 함수의 [[Call]]을 호출할 때 즉시 TypeError 예외를 던진다.)

모든 ECMAScript 함수 객체는 여기 정의된 [[Call]] 내부 메서드를 가진다. 추가로 생성자이기도 한 ECMAScript 함수는 [[Construct]] 내부 메서드도 가진다.

10.2.1 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method of an ECMAScript function object func takes arguments thisArgument (an ECMAScript language value) and argumentsList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. callerContext를 현재 실행 중인 execution context라고 하자.
  2. calleeContextPrepareForOrdinaryCall(func, undefined)라고 하자.
  3. Assert: 이제 calleeContext가 현재 실행 중인 execution context이다.
  4. func.[[IsClassConstructor]]true이면,
    1. 새로 생성된 TypeError 객체를 error라고 하자.
    2. NOTE: errorfunc와 연관된 Realm Record를 사용하여 calleeContext 안에서 생성된다.
    3. execution context stack에서 calleeContext를 제거하고, callerContext를 현재 실행 중인 execution context로 복원한다.
    4. error를 던진다.
  5. OrdinaryCallBindThis(func, calleeContext, thisArgument)를 수행한다.
  6. resultCompletion(OrdinaryCallEvaluateBody(func, argumentsList))라고 하자.
  7. execution context stack에서 calleeContext를 제거하고, callerContext를 현재 실행 중인 execution context로 복원한다.
  8. resultreturn completion이면, result.[[Value]]를 반환한다.
  9. Assert: resultthrow completion이다.
  10. result를 반환한다.
Note

단계 7에서 calleeContextexecution context stack에서 제거될 때, 그것이 중단된 상태로 나중에 접근 가능한 Generator에 의해 재개를 위해 유지되고 있다면 파괴되어서는 안 된다.

10.2.1.1 PrepareForOrdinaryCall ( func, newTarget )

The abstract operation PrepareForOrdinaryCall takes arguments func (an ECMAScript function object) and newTarget (an Object or undefined) and returns an execution context. It performs the following steps when called:

  1. callerContext를 현재 실행 중인 execution context라고 하자.
  2. 새로운 ECMAScript 코드 execution contextcalleeContext라고 하자.
  3. calleeContext의 Function을 func로 설정한다.
  4. calleeRealmfunc.[[Realm]]이라고 하자.
  5. calleeContextRealmcalleeRealm으로 설정한다.
  6. calleeContext의 ScriptOrModule을 func.[[ScriptOrModule]]로 설정한다.
  7. localEnvNewFunctionEnvironment(func, newTarget)라고 하자.
  8. calleeContext의 LexicalEnvironment를 localEnv로 설정한다.
  9. calleeContext의 VariableEnvironment를 localEnv로 설정한다.
  10. calleeContext의 PrivateEnvironment를 func.[[PrivateEnvironment]]로 설정한다.
  11. callerContext가 아직 중단되지 않았다면, callerContext를 중단한다.
  12. execution context stackcalleeContext를 push한다; calleeContext는 이제 현재 실행 중인 execution context이다.
  13. NOTE: 이 지점 이후에 생성되는 모든 예외 객체는 calleeRealm과 연관된다.
  14. calleeContext를 반환한다.

10.2.1.2 OrdinaryCallBindThis ( func, calleeContext, thisArgument )

The abstract operation OrdinaryCallBindThis takes arguments func (an ECMAScript function object), calleeContext (an execution context), and thisArgument (an ECMAScript language value) and returns unused. It performs the following steps when called:

  1. thisModefunc.[[ThisMode]]라고 하자.
  2. thisModelexical이면, unused를 반환한다.
  3. calleeRealmfunc.[[Realm]]이라고 하자.
  4. localEnvcalleeContext의 LexicalEnvironment라고 하자.
  5. thisModestrict이면,
    1. thisValuethisArgument라고 하자.
  6. 그렇지 않으면,
    1. thisArgumentundefined 또는 null 중 하나이면,
      1. globalEnvcalleeRealm.[[GlobalEnv]]라고 하자.
      2. Assert: globalEnvGlobal Environment Record이다.
      3. thisValueglobalEnv.[[GlobalThisValue]]라고 하자.
    2. 그렇지 않으면,
      1. thisValue를 ! ToObject(thisArgument)라고 하자.
      2. NOTE: ToObjectcalleeRealm을 사용하여 wrapper 객체를 생성한다.
  7. Assert: localEnvFunction Environment Record이다.
  8. Assert: 다음 단계는 localEnv.[[ThisBindingStatus]]initialized가 아니므로 결코 abrupt completion을 반환하지 않는다.
  9. BindThisValue(localEnv, thisValue)를 수행한다.
  10. unused를 반환한다.

10.2.1.3 Runtime Semantics: EvaluateBody

The syntax-directed operation EvaluateBody takes arguments func (an ECMAScript function object) and argumentsList (a List of ECMAScript language values) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. 인수 funcargumentsList를 사용한 FunctionBodyEvaluateFunctionBody를 ? 반환한다.
ConciseBody : ExpressionBody
  1. 인수 funcargumentsList를 사용한 ConciseBodyEvaluateConciseBody를 ? 반환한다.
GeneratorBody : FunctionBody
  1. 인수 funcargumentsList를 사용한 GeneratorBodyEvaluateGeneratorBody를 ? 반환한다.
AsyncGeneratorBody : FunctionBody
  1. 인수 funcargumentsList를 사용한 AsyncGeneratorBodyEvaluateAsyncGeneratorBody를 ? 반환한다.
AsyncFunctionBody : FunctionBody
  1. 인수 funcargumentsList를 사용한 AsyncFunctionBodyEvaluateAsyncFunctionBody를 ? 반환한다.
AsyncConciseBody : ExpressionBody
  1. 인수 funcargumentsList를 사용한 AsyncConciseBodyEvaluateAsyncConciseBody를 ? 반환한다.
Initializer : = AssignmentExpression
  1. Assert: argumentsList는 비어 있다.
  2. Assert: func.[[ClassFieldInitializerName]]empty가 아니다.
  3. IsAnonymousFunctionDefinition(AssignmentExpression)이 true이면,
    1. value를 인수 func.[[ClassFieldInitializerName]]를 사용한 InitializerNamedEvaluation 결과로 ? 하자.
  4. 그렇지 않으면,
    1. rhsAssignmentExpressionEvaluation 결과로 ? 하자.
    2. value를 ? GetValue(rhs)라고 하자.
  5. ReturnCompletion(value)를 반환한다.
Note

필드 initializer가 함수 경계를 구성하더라도, FunctionDeclarationInstantiation 호출은 관찰 가능한 효과를 갖지 않으므로 생략된다.

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Assert: argumentsList는 비어 있다.
  2. 인수 func를 사용한 ClassStaticBlockBodyEvaluateClassStaticBlockBody를 ? 반환한다.

10.2.1.4 OrdinaryCallEvaluateBody ( func, argumentsList )

The abstract operation OrdinaryCallEvaluateBody takes arguments func (an ECMAScript function object) and argumentsList (a List of ECMAScript language values) and returns a return completion or a throw completion. It performs the following steps when called:

  1. 인수 funcargumentsList를 사용한 func.[[ECMAScriptCode]]EvaluateBody를 ? 반환한다.

10.2.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of an ECMAScript function object func takes arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. callerContext를 현재 실행 중인 execution context라고 하자.
  2. kindfunc.[[ConstructorKind]]라고 하자.
  3. kindbase이면,
    1. thisArgument를 ? OrdinaryCreateFromConstructor(newTarget, "%Object.prototype%")라고 하자.
  4. calleeContextPrepareForOrdinaryCall(func, newTarget)라고 하자.
  5. Assert: 이제 calleeContext가 현재 실행 중인 execution context이다.
  6. kindbase이면,
    1. OrdinaryCallBindThis(func, calleeContext, thisArgument)를 수행한다.
    2. initializeResultCompletion(InitializeInstanceElements( thisArgument, func))라고 하자.
    3. initializeResultabrupt completion이면,
      1. execution context stack에서 calleeContext를 제거하고, callerContext를 현재 실행 중인 execution context로 복원한다.
      2. initializeResult를 반환한다.
  7. constructorEnvcalleeContext의 LexicalEnvironment라고 하자.
  8. resultCompletion(OrdinaryCallEvaluateBody(func, argumentsList))라고 하자.
  9. execution context stack에서 calleeContext를 제거하고, callerContext를 현재 실행 중인 execution context로 복원한다.
  10. resultthrow completion이면,
    1. result를 반환한다.
  11. Assert: resultreturn completion이다.
  12. result.[[Value]]가 Object이면, result.[[Value]]를 반환한다.
  13. kindbase이면, thisArgument를 반환한다.
  14. result.[[Value]]undefined가 아니면, TypeError 예외를 던진다.
  15. thisBinding을 ? constructorEnv.GetThisBinding()이라고 하자.
  16. Assert: thisBinding은 Object이다.
  17. thisBinding을 반환한다.

10.2.3 OrdinaryFunctionCreate ( functionPrototype, sourceText, parameterList, body, thisMode, env, privateEnv )

The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), parameterList (a Parse Node), body (a Parse Node), thisMode (lexical-this or non-lexical-this), env (an Environment Record), and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. 이것은 기본 [[Call]] 내부 메서드를 가지고 [[Construct]] 내부 메서드는 가지지 않는 새로운 함수의 런타임 생성을 명세하는 데 사용된다(다만 MakeConstructor 같은 연산에 의해 이후 추가될 수는 있다). sourceText는 생성될 함수의 구문 정의에 대한 source text이다. It performs the following steps when called:

  1. internalSlotsListTable 25 에 나열된 내부 슬롯이라고 하자.
  2. funcOrdinaryObjectCreate(functionPrototype, internalSlotsList)라고 하자.
  3. func.[[Call]]10.2.1 에 명시된 정의로 설정한다.
  4. func.[[SourceText]]sourceText로 설정한다.
  5. func.[[FormalParameters]]parameterList로 설정한다.
  6. func.[[ECMAScriptCode]]body로 설정한다.
  7. strictIsStrict(body)라고 하자.
  8. func.[[Strict]]strict로 설정한다.
  9. thisModelexical-this이면, func.[[ThisMode]]lexical로 설정한다.
  10. 그렇지 않고 stricttrue이면, func.[[ThisMode]]strict로 설정한다.
  11. 그렇지 않으면, func.[[ThisMode]]global로 설정한다.
  12. func.[[IsClassConstructor]]false로 설정한다.
  13. func.[[Environment]]env로 설정한다.
  14. func.[[PrivateEnvironment]]privateEnv로 설정한다.
  15. func.[[ScriptOrModule]]GetActiveScriptOrModule()로 설정한다.
  16. func.[[Realm]]를 현재 Realm Record로 설정한다.
  17. func.[[HomeObject]]undefined로 설정한다.
  18. func.[[Fields]]를 새로운 빈 List로 설정한다.
  19. func.[[PrivateMethods]]를 새로운 빈 List로 설정한다.
  20. func.[[ClassFieldInitializerName]]empty로 설정한다.
  21. lenparameterListExpectedArgumentCount라고 하자.
  22. SetFunctionLength(func, len)를 수행한다.
  23. func를 반환한다.

10.2.4 AddRestrictedFunctionProperties ( func, realm )

The abstract operation AddRestrictedFunctionProperties takes arguments func (a function object) and realm (a Realm Record) and returns unused. It performs the following steps when called:

  1. Assert: realm.[[Intrinsics]].[[%ThrowTypeError%]]가 존재하며 초기화되어 있다.
  2. throwerrealm.[[Intrinsics]].[[%ThrowTypeError%]]라고 하자.
  3. DefinePropertyOrThrow(func, "caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  4. DefinePropertyOrThrow(func, "arguments", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  5. unused를 반환한다.

10.2.4.1 %ThrowTypeError% ( )

이 함수는 %ThrowTypeError% intrinsic 객체이다.

이것은 각 realm마다 한 번 정의되는 익명 built-in 함수 객체이다.

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

  1. TypeError 예외를 던진다.

이 함수의 [[Extensible]] 내부 슬롯 값은 false이다.

이 함수의 "length" 프로퍼티는 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } 속성을 가진다.

이 함수의 "name" 프로퍼티는 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } 속성을 가진다.

10.2.5 MakeConstructor ( func [ , writablePrototype [ , prototype ] ] )

The abstract operation MakeConstructor takes argument func (an ECMAScript function object or a built-in function object) and optional arguments writablePrototype (a Boolean) and prototype (an Object) and returns unused. 이것은 func를 생성자로 변환한다. It performs the following steps when called:

  1. func가 ECMAScript 함수 객체이면,
    1. Assert: IsConstructor(func)는 false이다.
    2. Assert: func"prototype" 자체 프로퍼티를 가지지 않는 확장 가능한 객체이다.
    3. func.[[Construct]]10.2.2 에 명시된 정의로 설정한다.
  2. 그렇지 않으면,
    1. func.[[Construct]]10.3.2 에 명시된 정의로 설정한다.
  3. func.[[ConstructorKind]]base로 설정한다.
  4. writablePrototype이 존재하지 않으면, writablePrototypetrue로 설정한다.
  5. prototype이 존재하지 않으면,
    1. prototypeOrdinaryObjectCreate(%Object.prototype%)로 설정한다.
    2. DefinePropertyOrThrow(prototype, "constructor", PropertyDescriptor { [[Value]]: func, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  6. DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. unused를 반환한다.

10.2.6 MakeClassConstructor ( func )

The abstract operation MakeClassConstructor takes argument func (an ECMAScript function object) and returns unused. It performs the following steps when called:

  1. Assert: func.[[IsClassConstructor]]false이다.
  2. func.[[IsClassConstructor]]true로 설정한다.
  3. unused를 반환한다.

10.2.7 MakeMethod ( func, homeObject )

The abstract operation MakeMethod takes arguments func (an ECMAScript function object) and homeObject (an Object) and returns unused. 이것은 func를 메서드로 구성한다. It performs the following steps when called:

  1. Assert: homeObject는 일반 객체이다.
  2. func.[[HomeObject]]homeObject로 설정한다.
  3. unused를 반환한다.

10.2.8 DefineMethodProperty ( homeObject, key, closure, enumerable )

The abstract operation DefineMethodProperty takes arguments homeObject (an Object), key (a property key or Private Name), closure (a function object), and enumerable (a Boolean) and returns either a normal completion containing either a PrivateElement or unused, or an abrupt completion. It performs the following steps when called:

  1. Assert: homeObject는 일반적이고 확장 가능한 객체이다.
  2. keyPrivate Name이면, PrivateElement { [[Key]]: key, [[Kind]]: method, [[Value]]: closure }를 반환한다.
  3. desc를 PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }라고 하자.
  4. DefinePropertyOrThrow(homeObject, key, desc)를 수행한다.
  5. NOTE: DefinePropertyOrThrowkey"prototype"인 클래스 static 메서드를 정의하려고 시도할 때만 abrupt completion을 반환한다.
  6. unused를 반환한다.

10.2.9 SetFunctionName ( func, name [ , prefix ] )

The abstract operation SetFunctionName takes arguments func (a function object) and name (a property key or Private Name) and optional argument prefix (a String) and returns unused. 이것은 func"name" 프로퍼티를 추가한다. It performs the following steps when called:

  1. Assert: func"name" 자체 프로퍼티를 가지지 않는 확장 가능한 객체이다.
  2. name이 Symbol이면,
    1. descriptionname.[[Description]]이라고 하자.
    2. descriptionundefined이면, name을 빈 String으로 설정한다.
    3. 그렇지 않으면, name"[", description, "]"의 string-concatenation으로 설정한다.
  3. 그렇지 않고 namePrivate Name이면,
    1. namename.[[Description]]으로 설정한다.
  4. func[[InitialName]] 내부 슬롯을 가지면,
    1. func.[[InitialName]]name으로 설정한다.
  5. prefix가 존재하면,
    1. nameprefix, 코드 단위 0x0020 (SPACE), name의 string-concatenation으로 설정한다.
    2. func[[InitialName]] 내부 슬롯을 가지면,
      1. NOTE: 다음 단계의 선택은 이 Abstract Operation이 호출될 때마다 독립적으로 이루어진다.
      2. 선택적으로, func.[[InitialName]]name으로 설정한다.
  6. DefinePropertyOrThrow(func, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  7. unused를 반환한다.

10.2.10 SetFunctionLength ( func, length )

The abstract operation SetFunctionLength takes arguments func (a function object) and length (a non-negative integer or +∞) and returns unused. 이것은 func"length" 프로퍼티를 추가한다. It performs the following steps when called:

  1. Assert: func"length" 자체 프로퍼티를 가지지 않는 확장 가능한 객체이다.
  2. DefinePropertyOrThrow(func, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  3. unused를 반환한다.

10.2.11 FunctionDeclarationInstantiation ( func, argumentsList )

The abstract operation FunctionDeclarationInstantiation takes arguments func (an ECMAScript function object) and argumentsList (a List of ECMAScript language values) and returns either a normal completion containing unused or a throw completion. funcexecution context가 설정되고 있는 대상 함수 객체이다.

Note

ECMAScript 함수를 평가하기 위한 execution context가 설정될 때, 새로운 Function Environment Record가 생성되고 각 형식 매개변수에 대한 바인딩이 그 Environment Record 안에 instantiate된다. 함수 본문 안의 각 선언도 역시 instantiate된다. 함수의 형식 매개변수에 기본값 initializer가 포함되어 있지 않다면, 본문 선언은 매개변수와 같은 Environment Record 안에 instantiate된다. 기본값 매개변수 initializer가 존재하면, 본문 선언을 위해 두 번째 Environment Record가 생성된다. 형식 매개변수와 함수는 FunctionDeclarationInstantiation의 일부로 초기화된다. 다른 모든 바인딩은 함수 본문 평가 중에 초기화된다.

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

  1. calleeContext를 현재 실행 중인 execution context라고 하자.
  2. codefunc.[[ECMAScriptCode]]라고 하자.
  3. strictfunc.[[Strict]]라고 하자.
  4. formalsfunc.[[FormalParameters]]라고 하자.
  5. parameterNamesformalsBoundNames라고 하자.
  6. parameterNames에 중복 항목이 하나라도 있으면, hasDuplicatestrue라고 하자; 그렇지 않으면 hasDuplicatesfalse라고 하자.
  7. simpleParameterListformalsIsSimpleParameterList라고 하자.
  8. hasParameterExpressionsformalsContainsExpression이라고 하자.
  9. varNamescodeVarDeclaredNames라고 하자.
  10. varDeclarationscodeVarScopedDeclarations라고 하자.
  11. lexicalNamescodeLexicallyDeclaredNames라고 하자.
  12. functionNames를 새로운 빈 List라고 하자.
  13. functionsToInitialize를 새로운 빈 List라고 하자.
  14. varDeclarations의 각 요소 varDecl에 대해, 역순 List 순서로, 다음을 수행한다
    1. varDeclVariableDeclarationForBindingBindingIdentifier도 아니면,
      1. Assert: varDeclFunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, AsyncGeneratorDeclaration 중 하나이다.
      2. fnvarDeclBoundNames의 유일한 요소라고 하자.
      3. functionNamesfn을 포함하지 않으면,
        1. functionNames의 첫 번째 요소로 fn을 삽입한다.
        2. NOTE: 같은 이름에 대한 함수 선언이 여러 개 있으면, 마지막 선언이 사용된다.
        3. functionsToInitialize의 첫 번째 요소로 varDecl을 삽입한다.
  15. argumentsObjectNeededtrue라고 하자.
  16. func.[[ThisMode]]lexical이면,
    1. NOTE: 화살표 함수는 결코 arguments 객체를 가지지 않는다.
    2. argumentsObjectNeededfalse로 설정한다.
  17. 그렇지 않고 parameterNames"arguments"를 포함하면,
    1. argumentsObjectNeededfalse로 설정한다.
  18. 그렇지 않고 hasParameterExpressionsfalse이면,
    1. functionNames"arguments"를 포함하거나 lexicalNames"arguments"를 포함하면,
      1. argumentsObjectNeededfalse로 설정한다.
  19. stricttrue이거나 hasParameterExpressionsfalse이면,
    1. NOTE: strict mode 코드에서 eval 호출은 eval 바깥에서 보이는 새 바인딩을 만들 수 없으므로, 매개변수에는 하나의 Environment Record만 필요하다.
    2. envcalleeContext의 LexicalEnvironment라고 하자.
  20. 그렇지 않으면,
    1. NOTE: 형식 매개변수 목록 안의 직접 eval 호출로 생성된 바인딩이 매개변수가 선언된 환경 바깥에 있도록 보장하기 위해 별도의 Environment Record가 필요하다.
    2. calleeEnvcalleeContext의 LexicalEnvironment라고 하자.
    3. envNewDeclarativeEnvironment(calleeEnv)라고 하자.
    4. Assert: calleeContext의 VariableEnvironment와 calleeEnv는 같은 Environment Record이다.
    5. calleeContext의 LexicalEnvironment를 env로 설정한다.
  21. parameterNames의 각 String paramName에 대해, 다음을 수행한다
    1. alreadyDeclared를 ! env.HasBinding(paramName)라고 하자.
    2. NOTE: Early Error는 중복 매개변수 이름이 매개변수 기본값이나 rest parameter가 없는 non-strict 함수에서만 발생할 수 있음을 보장한다.
    3. alreadyDeclaredfalse이면,
      1. env.CreateMutableBinding(paramName, false)를 수행한다.
      2. hasDuplicatestrue이면,
        1. env.InitializeBinding(paramName, undefined)를 수행한다.
  22. argumentsObjectNeededtrue이면,
    1. stricttrue이거나 simpleParameterListfalse이면,
      1. aoCreateUnmappedArgumentsObject(argumentsList)라고 하자.
    2. 그렇지 않으면,
      1. NOTE: 매핑된 인수 객체는 rest parameter, 매개변수 기본값 initializer, 구조 분해 매개변수가 없는 non-strict 함수에 대해서만 제공된다.
      2. aoCreateMappedArgumentsObject(func, formals, argumentsList, env)라고 하자.
    3. stricttrue이면,
      1. env.CreateImmutableBinding("arguments", false)를 수행한다.
      2. NOTE: strict mode 코드에서는 early error가 이 바인딩에 대한 할당 시도를 막기 때문에, 그 가변성은 관찰 가능하지 않다.
    4. 그렇지 않으면,
      1. env.CreateMutableBinding("arguments", false)를 수행한다.
    5. env.InitializeBinding("arguments", ao)를 수행한다.
    6. parameterBindingsparameterNames와 « "arguments" »의 list-concatenation이라고 하자.
  23. 그렇지 않으면,
    1. parameterBindingsparameterNames라고 하자.
  24. iteratorRecordCreateListIteratorRecord(argumentsList)라고 하자.
  25. hasDuplicatestrue이면,
    1. usedEnvundefined라고 하자.
  26. 그렇지 않으면,
    1. usedEnvenv라고 하자.
  27. NOTE: 다음 단계는 ReturnCompletion을 반환할 수 없는데, 표현식 위치에서 그러한 completion이 발생할 수 있는 유일한 방법은 YieldExpression의 사용뿐이며, 이것은 15.5.115.6.1의 Early Error 규칙에 의해 매개변수 목록에서 금지되기 때문이다.
  28. 인수 iteratorRecordusedEnv를 사용한 formalsIteratorBindingInitialization을 ? 수행한다.
  29. hasParameterExpressionsfalse이면,
    1. NOTE: 매개변수와 최상위 var에는 하나의 Environment Record만 필요하다.
    2. instantiatedVarNamesList parameterBindings의 복사본이라고 하자.
    3. varNames의 각 요소 n에 대해, 다음을 수행한다
      1. instantiatedVarNamesn을 포함하지 않으면,
        1. ninstantiatedVarNames에 추가한다.
        2. env.CreateMutableBinding(n, false)를 수행한다.
        3. env.InitializeBinding(n, undefined)를 수행한다.
    4. varEnvenv라고 하자.
  30. 그렇지 않으면,
    1. NOTE: 형식 매개변수 목록 안의 표현식에 의해 생성된 closure가 함수 본문의 선언을 볼 수 없도록 보장하기 위해 별도의 Environment Record가 필요하다.
    2. varEnvNewDeclarativeEnvironment(env)라고 하자.
    3. calleeContext의 VariableEnvironment를 varEnv로 설정한다.
    4. instantiatedVarNames를 새로운 빈 List라고 하자.
    5. varNames의 각 요소 n에 대해, 다음을 수행한다
      1. instantiatedVarNamesn을 포함하지 않으면,
        1. ninstantiatedVarNames에 추가한다.
        2. varEnv.CreateMutableBinding(n, false)를 수행한다.
        3. parameterBindingsn을 포함하지 않거나 functionNamesn을 포함하면,
          1. initialValueundefined라고 하자.
        4. 그렇지 않으면,
          1. initialValue를 ! env.GetBindingValue(n, false)라고 하자.
        5. varEnv.InitializeBinding(n, initialValue)를 수행한다.
        6. NOTE: 형식 매개변수와 같은 이름의 var는 초기에 대응하는 초기화된 매개변수와 같은 값을 가진다.
  31. stricttrue이면,
    1. lexEnvvarEnv라고 하자.
  32. 그렇지 않으면,
    1. Normative Optional
      호스트가 웹 브라우저이거나 또는 Block-Level Function Declaration 웹 Legacy 호환성 의미론를 지원하면,
      1. code Contains xtrue인 임의의 Block, CaseClause, DefaultClause xStatementList에 직접 포함된 각 FunctionDeclaration fnDecl에 대해, 다음을 수행한다
        1. funcNamefnDeclBindingIdentifierStringValue라고 하자.
        2. FunctionDeclaration fnDeclfuncNameBindingIdentifier로 가지는 VariableStatement로 바꾸더라도 func에 대해 어떤 Early Error도 발생하지 않고 parameterNamesfuncName을 포함하지 않으면,
          1. NOTE: funcName에 대한 var 바인딩은 여기서, 그것이 VarDeclaredName도, 형식 매개변수의 이름도, 다른 FunctionDeclaration도 아닐 때에만 instantiate된다.
          2. instantiatedVarNamesfuncName을 포함하지 않고 funcName"arguments"가 아니면,
            1. varEnv.CreateMutableBinding(funcName, false)를 수행한다.
            2. varEnv.InitializeBinding(funcName, undefined)를 수행한다.
            3. funcNameinstantiatedVarNames에 추가한다.
          3. FunctionDeclaration fnDecl이 평가될 때, 15.2.6에 제공된 FunctionDeclaration Evaluation 알고리즘 대신 다음 단계를 수행한다:
            1. fEnv를 현재 실행 중인 execution context의 VariableEnvironment라고 하자.
            2. bEnv를 현재 실행 중인 execution context의 LexicalEnvironment라고 하자.
            3. fObj를 ! bEnv.GetBindingValue(funcName, false)라고 하자.
            4. fEnv.SetMutableBinding(funcName, fObj, false)를 수행한다.
            5. unused를 반환한다.
    2. lexEnvNewDeclarativeEnvironment(varEnv)라고 하자.
    3. NOTE: non-strict 함수는 최상위 lexical declaration을 위해 별도의 Environment Record를 사용하는데, 이는 direct eval이 eval 코드에 의해 도입된 var 스코프 선언이 기존 최상위 lexical 스코프 선언과 충돌하는지를 판별할 수 있도록 하기 위함이다. strict 함수에는 이것이 필요하지 않은데, strict direct eval은 항상 모든 선언을 새로운 Environment Record에 배치하기 때문이다.
  33. calleeContext의 LexicalEnvironment를 lexEnv로 설정한다.
  34. lexDeclarationscodeLexicallyScopedDeclarations라고 하자.
  35. lexDeclarations의 각 요소 lexDecl에 대해, 다음을 수행한다
    1. NOTE: lexical로 선언된 이름은 함수/제너레이터 선언, 형식 매개변수, var 이름과 같을 수 없다. lexical로 선언된 이름은 여기서 instantiate만 되고 초기화되지는 않는다.
    2. lexDeclBoundNames의 각 요소 dn에 대해, 다음을 수행한다
      1. lexDeclIsConstantDeclarationtrue이면,
        1. lexEnv.CreateImmutableBinding(dn, true)를 수행한다.
      2. 그렇지 않으면,
        1. lexEnv.CreateMutableBinding(dn, false)를 수행한다.
  36. privateEnvcalleeContext의 PrivateEnvironment라고 하자.
  37. functionsToInitialize의 각 Parse Node fnDecl에 대해, 다음을 수행한다
    1. fnfnDeclBoundNames의 유일한 요소라고 하자.
    2. fo를 인수 lexEnvprivateEnv를 사용한 fnDeclInstantiateFunctionObject라고 하자.
    3. varEnv.SetMutableBinding(fn, fo, false)를 수행한다.
  38. unused를 반환한다.

10.3 내장 함수 객체

내장 함수 객체는 일반 객체이다; 그것은 10.1 에 규정된 일반 객체에 대한 요구사항을 충족해야 한다.

모든 일반 객체에 요구되는 내부 슬롯(참조: 10.1) 외에도, 내장 함수 객체는 다음 내부 슬롯도 가져야 한다:

  • [[Realm]], 함수가 생성된 realm을 나타내는 Realm Record.
  • [[InitialName]], 함수의 초기 이름인 String. 20.2.3.5에서 사용된다.
  • [[Async]], 함수가 BuiltinCallOrConstruct에서 async 함수 호출 및 construct 동작을 가지는지를 나타내는 Boolean.

내장 함수 객체의 [[Prototype]] 내부 슬롯의 초기값은, 달리 명시되지 않는 한 %Function.prototype%이다.

내장 함수 객체는 10.3.1 의 정의에 부합하는 [[Call]] 내부 메서드를 가져야 한다.

내장 함수 객체는 그것이 “constructor”로 설명되거나, 또는 이 명세의 어떤 알고리즘이 그 [[Construct]] 내부 메서드를 명시적으로 설정하는 경우에만 [[Construct]] 내부 메서드를 가진다. 그러한 [[Construct]] 내부 메서드는 10.3.2 의 정의에 부합해야 한다.

구현은 이 명세에 정의되지 않은 추가적인 내장 함수 객체를 제공할 수 있다.

10.3.1 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method of 내장 함수 객체 func takes arguments thisArgument (an ECMAScript language value) and argumentsList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. BuiltinCallOrConstruct(func, thisArgument, argumentsList, undefined)를 반환한다.

10.3.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of 내장 함수 객체 func (메서드가 존재할 때) takes arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. result를 ? BuiltinCallOrConstruct(func, uninitialized, argumentsList, newTarget)라고 하자.
  2. Assert: result는 Object이다.
  3. result를 반환한다.

10.3.3 BuiltinCallOrConstruct ( func, thisArgument, argumentsList, newTarget )

The abstract operation BuiltinCallOrConstruct takes arguments func (a built-in function object), thisArgument (an ECMAScript language value or uninitialized), argumentsList (a List of ECMAScript language values), and newTarget (a constructor or undefined) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. callerContext를 현재 실행 중인 execution context라고 하자.
  2. callerContext가 아직 중단되지 않았다면, callerContext를 중단한다.
  3. 새로운 execution contextcalleeContext라고 하자.
  4. calleeContext의 Function을 func로 설정한다.
  5. calleeRealmfunc.[[Realm]]이라고 하자.
  6. calleeContextRealmcalleeRealm으로 설정한다.
  7. calleeContext의 ScriptOrModule을 null로 설정한다.
  8. calleeContext에 대해 필요한 구현 정의 초기화를 수행한다.
  9. execution context stackcalleeContext를 push한다; calleeContext는 이제 현재 실행 중인 execution context이다.
  10. func.[[Async]]true이면,
    1. promiseCapability를 ! NewPromiseCapability(%Promise%)라고 하자.
    2. func, thisArgument, argumentsList, newTarget을 캡처하고, 호출될 때 다음 단계를 수행하는 매개변수 없는 새로운 Abstract ClosureresultsClosure라고 하자:
      1. result를, func의 명세에 부합하는 방식으로 func평가한 결과Completion Record라고 하자. thisArgumentuninitialized이면 this 값은 초기화되지 않은 상태이고; 그렇지 않으면 thisArgumentthis 값을 제공한다. argumentsList는 이름 있는 매개변수를 제공한다. newTarget은 NewTarget 값을 제공한다.
      2. NOTE: func가 이 문서에 정의되어 있다면, “func의 명세”는 알고리즘 단계나 다른 수단을 통해 명시된 그 동작이다.
      3. Completion(result)를 반환한다.
    3. AsyncFunctionStart(promiseCapability, resultsClosure)를 수행한다.
    4. execution context stack에서 calleeContext를 제거하고 callerContext를 현재 실행 중인 execution context로 복원한다.
    5. promiseCapability.[[Promise]]를 반환한다.
  11. result를, func의 명세에 부합하는 방식으로 func평가한 결과Completion Record라고 하자. thisArgumentuninitialized이면 this 값은 초기화되지 않은 상태이고; 그렇지 않으면 thisArgumentthis 값을 제공한다. argumentsList는 이름 있는 매개변수를 제공한다. newTarget은 NewTarget 값을 제공한다.
  12. NOTE: func가 이 문서에 정의되어 있다면, “func의 명세”는 알고리즘 단계나 다른 수단을 통해 명시된 그 동작이다.
  13. execution context stack에서 calleeContext를 제거하고 callerContext를 현재 실행 중인 execution context로 복원한다.
  14. result를 반환한다.
Note

calleeContextexecution context stack에서 제거될 때, 그것이 접근 가능한 Generator에 의해 나중 재개를 위해 중단된 채 유지되고 있다면 파괴되어서는 안 된다.

10.3.4 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix [ , async ] ] ] ] )

The abstract operation CreateBuiltinFunction takes arguments behaviour (an Abstract Closure, a set of algorithm steps, or some other definition of a function's behaviour provided in this specification), length (a non-negative integer or +∞), name (a property key or a Private Name), and additionalInternalSlotsList (a List of names of internal slots) and optional arguments realm (a Realm Record), prototype (an Object or null), prefix (a String), and async (a Boolean) and returns a built-in function object. additionalInternalSlotsList는 객체의 일부로 정의되어야 하는 추가 내부 슬롯의 이름들을 담고 있다. 이 연산은 내장 함수 객체를 생성한다. It performs the following steps when called:

  1. realm이 존재하지 않으면, realm을 현재 Realm Record로 설정한다.
  2. prototype이 존재하지 않으면, prototyperealm.[[Intrinsics]].[[%Function.prototype%]]로 설정한다.
  3. async가 존재하지 않으면, asyncfalse로 설정한다.
  4. internalSlotsList를, 생성되려는 내장 함수 객체에 대해 10.3가 요구하는 모든 내부 슬롯의 이름을 포함하는 List라고 하자.
  5. additionalInternalSlotsList의 요소들을 internalSlotsList에 추가한다.
  6. func를, 호출되었을 때 제공된 인수들을 behaviour가 명시하는 대응 매개변수의 값으로 사용하여 behaviour가 설명하는 동작을 수행하는 새로운 내장 함수 객체라고 하자. 이 새로운 함수 객체는 이름이 internalSlotsList의 요소인 내부 슬롯들과 [[InitialName]] 내부 슬롯을 가진다.
  7. func.[[Async]]async로 설정한다.
  8. func.[[Prototype]]prototype으로 설정한다.
  9. func.[[Extensible]]true로 설정한다.
  10. func.[[Realm]]realm으로 설정한다.
  11. func.[[InitialName]]null로 설정한다.
  12. SetFunctionLength(func, length)를 수행한다.
  13. prefix가 존재하지 않으면,
    1. SetFunctionName(func, name)을 수행한다.
  14. 그렇지 않으면,
    1. SetFunctionName(func, name, prefix)를 수행한다.
  15. func를 반환한다.

이 명세에 정의된 각 내장 함수는 CreateBuiltinFunction 추상 연산을 호출하여 생성된다.

10.4 내장 이색 객체 내부 메서드와 슬롯

이 명세는 여러 종류의 내장 이색 객체를 정의한다. 이 객체들은 일반적으로 몇몇 특정 상황을 제외하면 일반 객체와 유사하게 동작한다. 다음 이색 객체들은, 아래에서 명시적으로 달리 규정된 경우를 제외하고는, 일반 객체 내부 메서드를 사용한다:

10.4.1 바인드 함수 이색 객체

바인드 함수 이색 객체는 다른 함수 객체를 감싸는 이색 객체이다. 바인드 함수 이색 객체는 호출 가능하다([[Call]] 내부 메서드를 가지며, [[Construct]] 내부 메서드를 가질 수도 있다). 바인드 함수 이색 객체를 호출하면 일반적으로 그것이 감싸고 있는 함수가 호출된다.

객체는 그 [[Call]] 및 (해당하는 경우) [[Construct]] 내부 메서드가 다음 구현을 사용하고, 다른 essential 내부 메서드는 10.1 에서 찾을 수 있는 정의를 사용할 때 바인드 함수 이색 객체 이다. 이 메서드들은 BoundFunctionCreate에서 설치된다.

바인드 함수 이색 객체Table 25 에 나열된 ECMAScript 함수 객체의 내부 슬롯을 가지지 않는다. 대신 [[Prototype]][[Extensible]] 외에 Table 26 에 나열된 내부 슬롯을 가진다.

Table 26: Internal Slots of Bound Function Exotic Objects
내부 슬롯 타입 설명
[[BoundTargetFunction]] a callable Object 감싸고 있는 함수 객체.
[[BoundThis]] an ECMAScript language value 감싸고 있는 함수를 호출할 때 항상 this 값으로 전달되는 값.
[[BoundArguments]] a List of ECMAScript language values 그 요소들이 감싸고 있는 함수에 대한 모든 호출의 첫 번째 인수들로 사용되는 값들의 리스트.

10.4.1.1 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method of 바인드 함수 이색 객체 func takes arguments thisArgument (an ECMAScript language value) and argumentsList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. targetfunc.[[BoundTargetFunction]]이라고 하자.
  2. boundThisfunc.[[BoundThis]]라고 하자.
  3. boundArgsfunc.[[BoundArguments]]라고 하자.
  4. argsboundArgsargumentsListlist-concatenation이라고 하자.
  5. Call(target, boundThis, args)를 반환한다.

10.4.1.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of 바인드 함수 이색 객체 func takes arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. targetfunc.[[BoundTargetFunction]]이라고 하자.
  2. Assert: IsConstructor(target)는 true이다.
  3. boundArgsfunc.[[BoundArguments]]라고 하자.
  4. argsboundArgsargumentsListlist-concatenation이라고 하자.
  5. SameValue(func, newTarget)가 true이면, newTargettarget으로 설정한다.
  6. Construct(target, args, newTarget)를 반환한다.

10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs )

The abstract operation BoundFunctionCreate takes arguments targetFunction (a function object), boundThis (an ECMAScript language value), and boundArgs (a List of ECMAScript language values) and returns either a normal completion containing a function object or a throw completion. 이것은 새로운 바인드 함수 이색 객체의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. proto를 ? targetFunction.[[GetPrototypeOf]]() 라고 하자.
  2. internalSlotsList를 « [[Prototype]], [[Extensible]] »와 Table 26 에 나열된 내부 슬롯들의 list-concatenation이라고 하자.
  3. objMakeBasicObject(internalSlotsList)라고 하자.
  4. obj.[[Prototype]]proto로 설정한다.
  5. obj.[[Call]]10.4.1.1 에 명시된 대로 설정한다.
  6. IsConstructor(targetFunction)가 true이면,
    1. obj.[[Construct]]10.4.1.2 에 명시된 대로 설정한다.
  7. obj.[[BoundTargetFunction]]targetFunction으로 설정한다.
  8. obj.[[BoundThis]]boundThis로 설정한다.
  9. obj.[[BoundArguments]]boundArgs로 설정한다.
  10. obj를 반환한다.

10.4.2 배열 이색 객체

Array는 배열 인덱스 프로퍼티 키를 특별하게 처리하는 이색 객체이다 (참조: 6.1.7). 프로퍼티 이름이 배열 인덱스인 프로퍼티는 element라고도 불린다. 모든 Array는 non-configurable한 "length" 프로퍼티를 가지며, 그 값은 수학적 값이 엄격히 232보다 작은, 항상 음이 아닌 정수 Number이다. "length" 프로퍼티의 값은 이름이 배열 인덱스인 모든 자체 프로퍼티의 이름보다 수치적으로 더 크며; Array의 자체 프로퍼티가 생성되거나 변경될 때마다, 이 불변식을 유지하기 위해 다른 프로퍼티들이 필요에 따라 조정된다. 구체적으로, 이름이 배열 인덱스인 자체 프로퍼티가 추가될 때마다, "length" 프로퍼티의 값은 필요하면 그 배열 인덱스의 수치값보다 1 큰 값으로 변경된다; 그리고 "length" 프로퍼티의 값이 변경될 때마다, 값이 새로운 length보다 작지 않은 이름의 배열 인덱스인 모든 자체 프로퍼티는 삭제된다. 이 제약은 Array의 자체 프로퍼티에만 적용되며, 그 프로토타입으로부터 상속될 수 있는 "length" 또는 배열 인덱스 프로퍼티의 영향을 받지 않는다.

객체는 그 [[DefineOwnProperty]] 내부 메서드가 다음 구현을 사용하고, 다른 essential 내부 메서드는 10.1 에서 찾을 수 있는 정의를 사용할 때 Array 이색 객체(또는 단순히 Array)이다. 이 메서드들은 ArrayCreate에서 설치된다.

10.4.2.1 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of Array 이색 객체 array takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. propertyKey"length"이면, ? ArraySetLength(array, desc)를 반환한다.
  2. propertyKey가 배열 인덱스이면,
    1. lengthDescOrdinaryGetOwnProperty(array, "length") 라고 하자.
    2. Assert: lengthDescundefined가 아니다.
    3. Assert: IsDataDescriptor(lengthDesc)는 true이다.
    4. Assert: lengthDesc.[[Configurable]]false이다.
    5. lengthlengthDesc.[[Value]]라고 하자.
    6. Assert: length는 음이 아닌 정수 Number이다.
    7. index를 ! ToUint32(propertyKey)라고 하자.
    8. indexlength이고 lengthDesc.[[Writable]]false이면, false를 반환한다.
    9. succeeded를 ! OrdinaryDefineOwnProperty(array, propertyKey, desc)라고 하자.
    10. succeededfalse이면, false를 반환한다.
    11. indexlength이면,
      1. lengthDesc.[[Value]]index + 1𝔽로 설정한다.
      2. succeeded를 ! OrdinaryDefineOwnProperty(array, "length", lengthDesc)로 설정한다.
      3. Assert: succeededtrue이다.
    12. true를 반환한다.
  3. OrdinaryDefineOwnProperty(array, propertyKey, desc)를 반환한다.

10.4.2.2 ArrayCreate ( length [ , proto ] )

The abstract operation ArrayCreate takes argument length (a non-negative integer) and optional argument proto (an Object) and returns either a normal completion containing an Array exotic object or a throw completion. 이것은 새로운 Array의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. length > 232 - 1이면, RangeError 예외를 던진다.
  2. proto가 존재하지 않으면, proto%Array.prototype%로 설정한다.
  3. arrayMakeBasicObject[[Prototype]], [[Extensible]] »)라고 하자.
  4. array.[[Prototype]]proto로 설정한다.
  5. array.[[DefineOwnProperty]]10.4.2.1 에 명시된 대로 설정한다.
  6. OrdinaryDefineOwnProperty(array, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  7. array를 반환한다.

10.4.2.3 ArraySpeciesCreate ( originalArray, length )

The abstract operation ArraySpeciesCreate takes arguments originalArray (an Object) and length (a non-negative integer) and returns either a normal completion containing an Object or a throw completion. 이것은 originalArray로부터 파생된 생성자 함수를 사용하여 새로운 Array 또는 유사 객체를 생성하는 것을 명세하는 데 사용된다. 이 연산은 생성자 함수가 Array를 반환해야 한다고 강제하지는 않는다. It performs the following steps when called:

  1. isArray를 ? IsArray(originalArray)라고 하자.
  2. isArrayfalse이면, ? ArrayCreate(length)를 반환한다.
  3. constructor를 ? Get(originalArray, "constructor") 라고 하자.
  4. IsConstructor(constructor)가 true이면,
    1. thisRealm을 현재 Realm Record라고 하자.
    2. constructorRealm을 ? GetFunctionRealm(constructor) 라고 하자.
    3. thisRealmconstructorRealm이 같은 Realm Record가 아니면,
      1. SameValue(constructor, constructorRealm.[[Intrinsics]].[[%Array%]])가 true이면, constructorundefined로 설정한다.
  5. constructor가 Object이면,
    1. constructor를 ? Get(constructor, %Symbol.species%)로 설정한다.
    2. constructornull이면, constructorundefined로 설정한다.
  6. constructorundefined이면, ? ArrayCreate(length)를 반환한다.
  7. IsConstructor(constructor)가 false이면, TypeError 예외를 던진다.
  8. Construct(constructor, « 𝔽(length) »)를 반환한다.
Note

originalArray가 현재 실행 중인 execution contextrealm이 아닌 realm에 대한 표준 내장 Array 생성자를 사용하여 생성되었다면, 새로운 Array는 현재 실행 중인 execution contextrealm을 사용하여 생성된다. 이것은 현재 ArraySpeciesCreate를 사용하여 정의되는 Array.prototype 메서드들에 대해 역사적으로 그러한 동작을 가져온 웹 브라우저와의 호환성을 유지한다.

10.4.2.4 ArraySetLength ( array, desc )

The abstract operation ArraySetLength takes arguments array (an Array) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. desc[[Value]] 필드를 가지지 않으면,
    1. OrdinaryDefineOwnProperty(array, "length", desc)를 반환한다.
  2. newLenDescdesc의 복사본이라고 하자.
  3. newLen을 ? ToUint32(desc.[[Value]])라고 하자.
  4. numberLen을 ? ToNumber(desc.[[Value]])라고 하자.
  5. SameValueZero(newLen, numberLen)가 false이면, RangeError 예외를 던진다.
  6. newLenDesc.[[Value]]newLen으로 설정한다.
  7. oldLenDescOrdinaryGetOwnProperty(array, "length") 라고 하자.
  8. Assert: oldLenDescundefined가 아니다.
  9. Assert: IsDataDescriptor(oldLenDesc)는 true이다.
  10. Assert: oldLenDesc.[[Configurable]]false이다.
  11. oldLenoldLenDesc.[[Value]]라고 하자.
  12. newLenoldLen이면,
    1. OrdinaryDefineOwnProperty(array, "length", newLenDesc)를 반환한다.
  13. oldLenDesc.[[Writable]]false이면, false를 반환한다.
  14. newLenDesc[[Writable]] 필드를 가지지 않거나 newLenDesc.[[Writable]]true이면,
    1. newWritabletrue라고 하자.
  15. 그렇지 않으면,
    1. NOTE: 어떤 element라도 삭제할 수 없는 경우에 대비해, [[Writable]] 속성을 false로 설정하는 것은 연기된다.
    2. newWritablefalse라고 하자.
    3. newLenDesc.[[Writable]]true로 설정한다.
  16. succeeded를 ! OrdinaryDefineOwnProperty(array, "length", newLenDesc)라고 하자.
  17. succeededfalse이면, false를 반환한다.
  18. array의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 배열 인덱스이고 ! ToUint32(propertyKey) ≥ newLen인 것에 대해, 숫자 인덱스 내림차순으로, 다음을 수행한다
    1. deleteSucceeded를 ! array.[[Delete]](propertyKey) 라고 하자.
    2. deleteSucceededfalse이면,
      1. newLenDesc.[[Value]]를 ! ToUint32(propertyKey) + 1𝔽로 설정한다.
      2. newWritablefalse이면, newLenDesc.[[Writable]]false로 설정한다.
      3. OrdinaryDefineOwnProperty(array, "length", newLenDesc)를 수행한다.
      4. false를 반환한다.
  19. newWritablefalse이면,
    1. succeeded를 ! OrdinaryDefineOwnProperty(array, "length", PropertyDescriptor { [[Writable]]: false })로 설정한다.
    2. Assert: succeededtrue이다.
  20. true를 반환한다.
Note

단계 34에서, desc.[[Value]]가 객체라면 그 valueOf 메서드는 두 번 호출된다. 이것은 이 명세 제2판부터 이러한 효과를 갖도록 명시된 legacy 동작이다.

10.4.3 문자열 이색 객체

String 객체는 String 값을 캡슐화하고, 그 String 값의 개별 코드 유닛 요소에 대응하는 가상 정수 인덱스 데이터 프로퍼티를 노출하는 이색 객체이다. 문자열 이색 객체는 항상 "length"라는 데이터 프로퍼티를 가지며, 그 값은 캡슐화된 String 값의 길이이다. 코드 유닛 데이터 프로퍼티와 "length" 프로퍼티는 모두 non-writable이고 non-configurable이다.

객체는 그 [[GetOwnProperty]], [[DefineOwnProperty]], 그리고 [[OwnPropertyKeys]] 내부 메서드가 다음 구현을 사용하고, 다른 essential 내부 메서드는 10.1 에서 찾을 수 있는 정의를 사용할 때 문자열 이색 객체(또는 단순히 String 객체)이다. 이 메서드들은 StringCreate에서 설치된다.

문자열 이색 객체는 일반 객체와 동일한 내부 슬롯을 가진다. 또한 [[StringData]] 내부 슬롯도 가진다.

10.4.3.1 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of 문자열 이색 객체 str takes argument propertyKey (a property key) and returns a normal completion containing either a Property Descriptor or undefined. It performs the following steps when called:

  1. descOrdinaryGetOwnProperty(str, propertyKey)라고 하자.
  2. descundefined가 아니면, desc를 반환한다.
  3. StringGetOwnProperty(str, propertyKey)를 반환한다.

10.4.3.2 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of 문자열 이색 객체 str takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. stringDescStringGetOwnProperty(str, propertyKey) 라고 하자.
  2. stringDescundefined가 아니면,
    1. extensiblestr.[[Extensible]]이라고 하자.
    2. IsCompatiblePropertyDescriptor(extensible, desc, stringDesc)를 반환한다.
  3. OrdinaryDefineOwnProperty(str, propertyKey, desc)를 반환한다.

10.4.3.3 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of 문자열 이색 객체 obj takes no arguments and returns a normal completion containing a List of property keys. It performs the following steps when called:

  1. keys를 새로운 빈 List라고 하자.
  2. strobj.[[StringData]]라고 하자.
  3. Assert: str는 String이다.
  4. lenstr의 길이라고 하자.
  5. 0 ≤ i < len인 각 정수 i에 대해, 오름차순으로, 다음을 수행한다
    1. ToString(𝔽(i))를 keys에 추가한다.
  6. obj의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 배열 인덱스이고 ! ToIntegerOrInfinity(propertyKey) ≥ len인 것에 대해, 숫자 인덱스 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  7. obj의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 String이고 배열 인덱스가 아닌 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  8. obj의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 Symbol인 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  9. keys를 반환한다.

10.4.3.4 StringCreate ( value, prototype )

The abstract operation StringCreate takes arguments value (a String) and prototype (an Object) and returns a String exotic object. 이것은 새로운 문자열 이색 객체의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. strMakeBasicObject[[Prototype]], [[Extensible]], [[StringData]] »)라고 하자.
  2. str.[[Prototype]]prototype으로 설정한다.
  3. str.[[StringData]]value로 설정한다.
  4. str.[[GetOwnProperty]]10.4.3.1 에 명시된 대로 설정한다.
  5. str.[[DefineOwnProperty]]10.4.3.2 에 명시된 대로 설정한다.
  6. str.[[OwnPropertyKeys]]10.4.3.3 에 명시된 대로 설정한다.
  7. lengthvalue의 길이라고 하자.
  8. DefinePropertyOrThrow(str, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false })를 수행한다.
  9. str를 반환한다.

10.4.3.5 StringGetOwnProperty ( str, propertyKey )

The abstract operation StringGetOwnProperty takes arguments str (an Object that has a [[StringData]] internal slot) and propertyKey (a property key) and returns a Property Descriptor or undefined. It performs the following steps when called:

  1. propertyKey가 String이 아니면, undefined를 반환한다.
  2. indexCanonicalNumericIndexString(propertyKey)이라고 하자.
  3. index정수 Number가 아니면, undefined를 반환한다.
  4. index-0𝔽이거나 index < -0𝔽이면, undefined를 반환한다.
  5. stringDatastr.[[StringData]]라고 하자.
  6. Assert: stringData는 String이다.
  7. lenstringData의 길이라고 하자.
  8. (index) ≥ len이면, undefined를 반환한다.
  9. resultStrstringData(index)부터 (index) + 1까지의 substring이라고 하자.
  10. PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }를 반환한다.

10.4.4 Arguments 이색 객체

대부분의 ECMAScript 함수는 자신의 코드에서 arguments 객체를 사용할 수 있게 한다. 함수 정의의 특성에 따라, 그 arguments 객체는 일반 객체이거나 arguments 이색 객체이다. arguments 이색 객체는 그 배열 인덱스 프로퍼티들이 연관된 ECMAScript 함수의 호출에 대한 형식 매개변수 바인딩에 매핑되는 이색 객체이다.

객체는, 여기에서 명시되지 않은 내부 메서드는 10.1 에 있는 정의를 사용하면서, 그 내부 메서드가 다음 구현을 사용할 때 arguments 이색 객체 이다. 이 메서드들은 CreateMappedArgumentsObject에서 설치된다.

Note 1

CreateUnmappedArgumentsObject는 이 절에 함께 묶여 있지만, arguments 이색 객체가 아니라 일반 객체를 생성한다.

arguments 이색 객체는 일반 객체와 동일한 내부 슬롯을 가진다. 또한 [[ParameterMap]] 내부 슬롯도 가진다. 일반 arguments 객체도 [[ParameterMap]] 내부 슬롯을 가지며, 그 값은 항상 undefined이다. 일반 arguments 객체의 경우 [[ParameterMap]] 내부 슬롯은 Object.prototype.toString (20.1.3.6)에서 그것들을 그러한 것으로 식별하기 위해서만 사용된다.

Note 2

숫자 이름 값이 해당 함수 객체의 형식 매개변수 개수보다 작은 arguments 이색 객체정수 인덱스 데이터 프로퍼티는 처음에는 함수의 execution context 안의 대응 인수 바인딩과 그 값을 공유한다. 이는 프로퍼티를 변경하면 대응하는 인수 바인딩의 값도 바뀌고 그 반대도 마찬가지임을 뜻한다. 그러한 프로퍼티가 삭제된 뒤 다시 정의되거나, 그 프로퍼티가 접근자 프로퍼티로 변경되면 이 대응 관계는 깨진다. arguments 객체가 일반 객체인 경우, 그 프로퍼티 값은 단순히 함수에 전달된 인수의 복사본이며, 프로퍼티 값과 형식 매개변수 값 사이에 동적 연결은 없다.

Note 3

ParameterMap 객체와 그 프로퍼티 값은 arguments 객체와 인수 바인딩 사이의 대응을 명세하기 위한 장치로 사용된다. ParameterMap 객체와 그 프로퍼티 값인 객체들은 ECMAScript 코드로부터 직접 관찰될 수 없다. ECMAScript 구현은 명시된 의미론을 구현하기 위해 실제로 그러한 객체를 생성하거나 사용할 필요가 없다.

Note 4

일반 arguments 객체는 "callee"라는 이름의 non-configurable 접근자 프로퍼티를 정의하며, 이에 접근하면 TypeError 예외를 던진다. "callee" 프로퍼티는 오직 일부 non-strict 함수들에 대해서만 생성되는 arguments 이색 객체에서는 더 구체적인 의미를 가진다. 일반 변형에서 이 프로퍼티를 이렇게 정의하는 것은, ECMAScript 적합 구현이 그것을 다른 방식으로 정의하지 않도록 보장하기 위해 존재한다.

Note 5

ECMAScript 구현의 arguments 이색 객체는 역사적으로 "caller"라는 이름의 접근자 프로퍼티를 포함해 왔다. ECMAScript 2017 이전에는, 이 명세는 일반 arguments 객체에 대해 예외를 던지는 "caller" 프로퍼티를 정의하고 있었다. 구현들이 더 이상 이 확장을 포함하지 않기 때문에, ECMAScript 2017은 예외를 던지는 "caller" 접근자 요구사항을 제거했다.

10.4.4.1 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of arguments 이색 객체 args takes argument propertyKey (a property key) and returns a normal completion containing either a Property Descriptor or undefined. It performs the following steps when called:

  1. descOrdinaryGetOwnProperty(args, propertyKey)라고 하자.
  2. descundefined이면, undefined를 반환한다.
  3. mapargs.[[ParameterMap]]이라고 하자.
  4. isMapped를 ! HasOwnProperty(map, propertyKey)라고 하자.
  5. isMappedtrue이면,
    1. desc.[[Value]]를 ! Get(map, propertyKey)로 설정한다.
  6. desc를 반환한다.

10.4.4.2 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of arguments 이색 객체 args takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. mapargs.[[ParameterMap]]이라고 하자.
  2. isMapped를 ! HasOwnProperty(map, propertyKey)라고 하자.
  3. newArgDescdesc라고 하자.
  4. isMappedtrue이고 IsDataDescriptor(desc)가 true이면,
    1. desc[[Value]] 필드를 가지지 않고, desc[[Writable]] 필드를 가지며, desc.[[Writable]]false이면,
      1. newArgDescdesc의 복사본으로 설정한다.
      2. newArgDesc.[[Value]]를 ! Get(map, propertyKey)로 설정한다.
  5. allowed를 ! OrdinaryDefineOwnProperty(args, propertyKey, newArgDesc)라고 하자.
  6. allowedfalse이면, false를 반환한다.
  7. isMappedtrue이면,
    1. IsAccessorDescriptor(desc)가 true이면,
      1. map.[[Delete]](propertyKey)를 수행한다.
    2. 그렇지 않으면,
      1. desc[[Value]] 필드를 가지면,
        1. Assert: 다음 Set은 성공할 것인데, arguments 객체에 의해 매핑되는 형식 매개변수는 항상 쓰기 가능하기 때문이다.
        2. Set(map, propertyKey, desc.[[Value]], false) 를 수행한다.
      2. desc[[Writable]] 필드를 가지고 desc.[[Writable]]false이면,
        1. map.[[Delete]](propertyKey)를 수행한다.
  8. true를 반환한다.

10.4.4.3 [[Get]] ( propertyKey, receiver )

The [[Get]] internal method of arguments 이색 객체 args takes arguments propertyKey (a property key) and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. mapargs.[[ParameterMap]]이라고 하자.
  2. isMapped를 ! HasOwnProperty(map, propertyKey)라고 하자.
  3. isMappedfalse이면, ? OrdinaryGet(args, propertyKey, receiver)를 반환한다.
  4. Assert: mappropertyKey에 대한 형식 매개변수 매핑을 포함한다.
  5. Get(map, propertyKey)를 반환한다.

10.4.4.4 [[Set]] ( propertyKey, value, receiver )

The [[Set]] internal method of arguments 이색 객체 args takes arguments propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. SameValue(args, receiver)가 false이면,
    1. isMappedfalse라고 하자.
  2. 그렇지 않으면,
    1. mapargs.[[ParameterMap]]이라고 하자.
    2. isMapped를 ! HasOwnProperty(map, propertyKey)라고 하자.
  3. isMappedtrue이면,
    1. Assert: 다음 Set은 성공할 것인데, arguments 객체에 의해 매핑되는 형식 매개변수는 항상 쓰기 가능하기 때문이다.
    2. Set(map, propertyKey, value, false)를 수행한다.
  4. OrdinarySet(args, propertyKey, value, receiver)를 반환한다.

10.4.4.5 [[Delete]] ( propertyKey )

The [[Delete]] internal method of arguments 이색 객체 args takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. mapargs.[[ParameterMap]]이라고 하자.
  2. isMapped를 ! HasOwnProperty(map, propertyKey)라고 하자.
  3. result를 ? OrdinaryDelete(args, propertyKey)라고 하자.
  4. resulttrue이고 isMappedtrue이면,
    1. map.[[Delete]](propertyKey)를 수행한다.
  5. result를 반환한다.

10.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )

The abstract operation CreateUnmappedArgumentsObject takes argument argumentsList (a List of ECMAScript language values) and returns an ordinary object. It performs the following steps when called:

  1. lenargumentsList의 요소 개수라고 하자.
  2. objOrdinaryObjectCreate(%Object.prototype%, « [[ParameterMap]] ») 이라고 하자.
  3. obj.[[ParameterMap]]undefined로 설정한다.
  4. DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  5. index를 0이라고 하자.
  6. index < len인 동안, 다음을 반복한다
    1. valargumentsList[index]라고 하자.
    2. CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), val)를 수행한다.
    3. indexindex + 1로 설정한다.
  7. DefinePropertyOrThrow(obj, %Symbol.iterator%, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  8. DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Get]]: %ThrowTypeError%, [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false }) 를 수행한다.
  9. obj를 반환한다.

10.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )

The abstract operation CreateMappedArgumentsObject takes arguments func (an ECMAScript function object), formals (a Parse Node), argumentsList (a List of ECMAScript language values), and env (an Environment Record) and returns an arguments exotic object. It performs the following steps when called:

  1. Assert: formals는 rest parameter, 어떤 binding pattern, 어떤 initializer도 포함하지 않는다. 중복 식별자는 포함할 수 있다.
  2. lenargumentsList의 요소 개수라고 하자.
  3. objMakeBasicObject[[Prototype]], [[Extensible]], [[ParameterMap]] »)라고 하자.
  4. obj.[[GetOwnProperty]]10.4.4.1 에 명시된 대로 설정한다.
  5. obj.[[DefineOwnProperty]]10.4.4.2 에 명시된 대로 설정한다.
  6. obj.[[Get]]10.4.4.3 에 명시된 대로 설정한다.
  7. obj.[[Set]]10.4.4.4 에 명시된 대로 설정한다.
  8. obj.[[Delete]]10.4.4.5 에 명시된 대로 설정한다.
  9. obj.[[Prototype]]%Object.prototype%으로 설정한다.
  10. mapOrdinaryObjectCreate(null)라고 하자.
  11. obj.[[ParameterMap]]map으로 설정한다.
  12. parameterNamesformalsBoundNames라고 하자.
  13. numberOfParametersparameterNames의 요소 개수라고 하자.
  14. index를 0이라고 하자.
  15. index < len인 동안, 다음을 반복한다
    1. valargumentsList[index]라고 하자.
    2. CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), val)를 수행한다.
    3. indexindex + 1로 설정한다.
  16. DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  17. mappedNames를 새로운 빈 List라고 하자.
  18. indexnumberOfParameters - 1로 설정한다.
  19. index ≥ 0인 동안, 다음을 반복한다
    1. nameparameterNames[index]라고 하자.
    2. mappedNamesname을 포함하지 않으면,
      1. namemappedNames에 추가한다.
      2. index < len이면,
        1. getterMakeArgGetter(name, env)라고 하자.
        2. setterMakeArgSetter(name, env)라고 하자.
        3. map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: setter, [[Get]]: getter, [[Enumerable]]: false, [[Configurable]]: true }) 를 수행한다.
    3. indexindex - 1로 설정한다.
  20. DefinePropertyOrThrow(obj, %Symbol.iterator%, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  21. DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true })를 수행한다.
  22. obj를 반환한다.

10.4.4.7.1 MakeArgGetter ( name, env )

The abstract operation MakeArgGetter takes arguments name (a String) and env (an Environment Record) and returns a function object. 이것은 실행되었을 때 env 안에서 name에 바인딩된 값을 반환하는 built-in 함수 객체를 생성한다. It performs the following steps when called:

  1. nameenv를 캡처하고, 호출될 때 다음 단계를 수행하는 매개변수 없는 새로운 Abstract ClosuregetterClosure라고 하자:
    1. NormalCompletion(! env.GetBindingValue(name, false)) 를 반환한다.
  2. getterCreateBuiltinFunction(getterClosure, 0, "", « ») 라고 하자.
  3. NOTE: getter는 ECMAScript 코드에서 직접 접근할 수 없다.
  4. getter를 반환한다.

10.4.4.7.2 MakeArgSetter ( name, env )

The abstract operation MakeArgSetter takes arguments name (a String) and env (an Environment Record) and returns a function object. 이것은 실행되었을 때 env 안에서 name에 바인딩된 값을 설정하는 built-in 함수 객체를 생성한다. It performs the following steps when called:

  1. nameenv를 캡처하고, (value) 매개변수를 가지며 호출될 때 다음 단계를 수행하는 새로운 Abstract ClosuresetterClosure라고 하자:
    1. NormalCompletion(! env.SetMutableBinding(name, value, false))를 반환한다.
  2. setterCreateBuiltinFunction(setterClosure, 1, "", « ») 라고 하자.
  3. NOTE: setter는 ECMAScript 코드에서 직접 접근할 수 없다.
  4. setter를 반환한다.

10.4.5 TypedArray 이색 객체

TypedArray는 canonical numeric string인 프로퍼티 키를 특별하게 처리하는 이색 객체이며, 그 중 경계 내 정수 인덱스인 부분집합을 사용해 균일한 타입의 element에 인덱싱하고, 나머지는 프로토타입 체인 탐색을 발생시키지 않고 존재하지 않음을 보장하는 불변식을 강제한다.

Note

임의의 Number n에 대한 ToString(n)은 canonical numeric string이므로, 구현은 TypedArray의 프로퍼티 키로 Number를 실제 문자열 변환 없이 취급할 수 있다.

TypedArray는 일반 객체와 동일한 내부 슬롯을 가지며, 추가로 [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] 내부 슬롯을 가진다.

객체는 그 [[PreventExtensions]], [[GetOwnProperty]], [[HasProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]], [[OwnPropertyKeys]] 내부 메서드가 이 절의 정의를 사용하고, 다른 essential 내부 메서드는 10.1 에서 찾을 수 있는 정의를 사용할 때 TypedArray 이다. 이 메서드들은 TypedArrayCreate에 의해 설치된다.

10.4.5.1 [[PreventExtensions]] ( )

The [[PreventExtensions]] internal method of TypedArray obj takes no arguments and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. NOTE: 6.1.7.3 에 명시된 확장 가능성과 관련된 불변식은, obj가 프로퍼티를 얻을 수 있거나(또는 잃었다가 다시 얻을 수 있거나), 이는 그 기반 버퍼가 리사이즈될 때 정수 인덱스 이름을 가진 프로퍼티에서 발생할 수 있는데, 그 경우 이 메서드가 true를 반환하는 것을 허용하지 않는다.
  2. IsTypedArrayFixedLength(obj)가 false이면, false를 반환한다.
  3. OrdinaryPreventExtensions(obj)를 반환한다.

10.4.5.2 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of TypedArray obj takes argument propertyKey (a property key) and returns a normal completion containing either a Property Descriptor or undefined. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면,
      1. valueTypedArrayGetElement(obj, numericIndex) 라고 하자.
      2. valueundefined이면, undefined를 반환한다.
      3. PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true } 를 반환한다.
  2. OrdinaryGetOwnProperty(obj, propertyKey)를 반환한다.

10.4.5.3 [[HasProperty]] ( propertyKey )

The [[HasProperty]] internal method of TypedArray obj takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면, IsValidIntegerIndex(obj, numericIndex)를 반환한다.
  2. OrdinaryHasProperty(obj, propertyKey)를 반환한다.

10.4.5.4 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of TypedArray obj takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면,
      1. IsValidIntegerIndex(obj, numericIndex)가 false이면, false를 반환한다.
      2. desc[[Configurable]] 필드를 가지고 desc.[[Configurable]]false이면, false를 반환한다.
      3. desc[[Enumerable]] 필드를 가지고 desc.[[Enumerable]]false이면, false를 반환한다.
      4. IsAccessorDescriptor(desc)가 true이면, false를 반환한다.
      5. desc[[Writable]] 필드를 가지고 desc.[[Writable]]false이면, false를 반환한다.
      6. desc[[Value]] 필드를 가지면, ? TypedArraySetElement(obj, numericIndex, desc.[[Value]]) 를 수행한다.
      7. true를 반환한다.
  2. OrdinaryDefineOwnProperty(obj, propertyKey, desc)를 반환한다.

10.4.5.5 [[Get]] ( propertyKey, receiver )

The [[Get]] internal method of TypedArray obj takes arguments propertyKey (a property key) and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면,
      1. TypedArrayGetElement(obj, numericIndex)를 반환한다.
  2. OrdinaryGet(obj, propertyKey, receiver)를 반환한다.

10.4.5.6 [[Set]] ( propertyKey, value, receiver )

The [[Set]] internal method of TypedArray obj takes arguments propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면,
      1. SameValue(obj, receiver)가 true이면,
        1. TypedArraySetElement(obj, numericIndex, value)를 수행한다.
        2. true를 반환한다.
      2. IsValidIntegerIndex(obj, numericIndex)가 false이면, true를 반환한다.
  2. OrdinarySet(obj, propertyKey, value, receiver)를 반환한다.

10.4.5.7 [[Delete]] ( propertyKey )

The [[Delete]] internal method of TypedArray obj takes argument propertyKey (a property key) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. propertyKey가 String이면,
    1. numericIndexCanonicalNumericIndexString(propertyKey) 라고 하자.
    2. numericIndexundefined가 아니면,
      1. IsValidIntegerIndex(obj, numericIndex)가 false이면, true를 반환한다.
      2. false를 반환한다.
  2. OrdinaryDelete(obj, propertyKey)를 반환한다.

10.4.5.8 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of TypedArray obj takes no arguments and returns a normal completion containing a List of property keys. It performs the following steps when called:

  1. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  2. keys를 새로운 빈 List라고 하자.
  3. IsTypedArrayOutOfBounds(taRecord)가 false이면,
    1. lengthTypedArrayLength(taRecord)라고 하자.
    2. 0 ≤ i < length인 각 정수 i에 대해, 오름차순으로, 다음을 수행한다
      1. ToString(𝔽(i))를 keys에 추가한다.
  4. obj의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 String이고 정수 인덱스가 아닌 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  5. obj의 각 자체 프로퍼티 키 propertyKey 중, propertyKey가 Symbol인 것에 대해, 프로퍼티 생성의 시간순 오름차순으로, 다음을 수행한다
    1. propertyKeykeys에 추가한다.
  6. keys를 반환한다.

10.4.5.9 버퍼 witness record를 가진 TypedArray

TypedArray With Buffer Witness Record 는 viewed buffer의 캐시된 바이트 길이와 함께 TypedArray를 캡슐화하는 데 사용되는 Record 값이다. 이는 viewed buffer가 growable SharedArrayBuffer일 때 byte length data block에 대한 ReadSharedMemory event가 하나만 존재하도록 보장하는 데 도움을 주기 위해 사용된다.

TypedArray With Buffer Witness Record는 Table 27 에 나열된 필드를 가진다.

Table 27: TypedArray With Buffer Witness Record Fields
필드 이름 의미
[[Object]] a TypedArray 버퍼의 바이트 길이가 로드되는 TypedArray.
[[CachedBufferByteLength]] a non-negative integer or detached Record가 생성되었을 때 객체의 [[ViewedArrayBuffer]]의 바이트 길이.

10.4.5.10 MakeTypedArrayWithBufferWitnessRecord ( obj, order )

The abstract operation MakeTypedArrayWithBufferWitnessRecord takes arguments obj (a TypedArray) and order (seq-cst or unordered) and returns a TypedArray With Buffer Witness Record. It performs the following steps when called:

  1. bufferobj.[[ViewedArrayBuffer]]라고 하자.
  2. IsDetachedBuffer(buffer)가 true이면,
    1. byteLengthdetached라고 하자.
  3. 그렇지 않으면,
    1. byteLengthArrayBufferByteLength(buffer, order) 라고 하자.
  4. TypedArray With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }를 반환한다.

10.4.5.11 TypedArrayCreate ( prototype )

The abstract operation TypedArrayCreate takes argument prototype (an Object) and returns a TypedArray. 이것은 새로운 TypedArray의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. internalSlotsList를 « [[Prototype]], [[Extensible]], [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »라고 하자.
  2. typedArrayMakeBasicObject(internalSlotsList)라고 하자.
  3. typedArray.[[PreventExtensions]]10.4.5.1 에 명시된 대로 설정한다.
  4. typedArray.[[GetOwnProperty]]10.4.5.2 에 명시된 대로 설정한다.
  5. typedArray.[[HasProperty]]10.4.5.3 에 명시된 대로 설정한다.
  6. typedArray.[[DefineOwnProperty]]10.4.5.4 에 명시된 대로 설정한다.
  7. typedArray.[[Get]]10.4.5.5 에 명시된 대로 설정한다.
  8. typedArray.[[Set]]10.4.5.6 에 명시된 대로 설정한다.
  9. typedArray.[[Delete]]10.4.5.7 에 명시된 대로 설정한다.
  10. typedArray.[[OwnPropertyKeys]]10.4.5.8 에 명시된 대로 설정한다.
  11. typedArray.[[Prototype]]prototype으로 설정한다.
  12. typedArray를 반환한다.

10.4.5.12 TypedArrayByteLength ( taRecord )

The abstract operation TypedArrayByteLength takes argument taRecord (a TypedArray With Buffer Witness Record) and returns a non-negative integer. It performs the following steps when called:

  1. Assert: IsTypedArrayOutOfBounds(taRecord)는 false이다.
  2. objtaRecord.[[Object]]라고 하자.
  3. obj.[[ByteLength]]auto가 아니면, obj.[[ByteLength]]를 반환한다.
  4. lengthTypedArrayLength(taRecord)라고 하자.
  5. elementSizeTypedArrayElementSize(obj)라고 하자.
  6. NOTE: 반환되는 byte length는, 기반 버퍼가 정수배가 아닌 크기로 리사이즈된 경우에도 항상 elementSize정수배이다.
  7. length × elementSize를 반환한다.

10.4.5.13 TypedArrayLength ( taRecord )

The abstract operation TypedArrayLength takes argument taRecord (a TypedArray With Buffer Witness Record) and returns a non-negative integer. It performs the following steps when called:

  1. Assert: IsTypedArrayOutOfBounds(taRecord)는 false이다.
  2. objtaRecord.[[Object]]라고 하자.
  3. obj.[[ArrayLength]]auto가 아니면, obj.[[ArrayLength]]를 반환한다.
  4. Assert: IsFixedLengthArrayBuffer(obj.[[ViewedArrayBuffer]]) 는 false이다.
  5. byteOffsetobj.[[ByteOffset]]라고 하자.
  6. elementSizeTypedArrayElementSize(obj)라고 하자.
  7. byteLengthtaRecord.[[CachedBufferByteLength]]라고 하자.
  8. Assert: byteLengthdetached가 아니다.
  9. floor((byteLength - byteOffset) / elementSize)를 반환한다.

10.4.5.14 IsTypedArrayOutOfBounds ( taRecord )

The abstract operation IsTypedArrayOutOfBounds takes argument taRecord (a TypedArray With Buffer Witness Record) and returns a Boolean. 이것은 객체의 수치 프로퍼티 중 어느 하나라도 기반 버퍼의 경계 안에 포함되지 않는 인덱스의 값을 참조하는지를 검사한다. It performs the following steps when called:

  1. objtaRecord.[[Object]]라고 하자.
  2. bufferByteLengthtaRecord.[[CachedBufferByteLength]] 라고 하자.
  3. IsDetachedBuffer(obj.[[ViewedArrayBuffer]])가 true이면,
    1. Assert: bufferByteLengthdetached이다.
    2. true를 반환한다.
  4. Assert: bufferByteLength는 음이 아닌 정수이다.
  5. byteOffsetStartobj.[[ByteOffset]]라고 하자.
  6. obj.[[ArrayLength]]auto이면,
    1. byteOffsetEndbufferByteLength라고 하자.
  7. 그렇지 않으면,
    1. elementSizeTypedArrayElementSize(obj)라고 하자.
    2. arrayByteLengthobj.[[ArrayLength]] × elementSize 라고 하자.
    3. byteOffsetEndbyteOffsetStart + arrayByteLength라고 하자.
  8. NOTE: [[ByteOffset]]bufferByteLength인 길이 0의 TypedArray는 out-of-bounds로 간주되지 않는다.
  9. byteOffsetStart > bufferByteLength이거나 byteOffsetEnd > bufferByteLength이면, true를 반환한다.
  10. false를 반환한다.

10.4.5.15 IsTypedArrayFixedLength ( obj )

The abstract operation IsTypedArrayFixedLength takes argument obj (a TypedArray) and returns a Boolean. It performs the following steps when called:

  1. obj.[[ArrayLength]]auto이면, false를 반환한다.
  2. bufferobj.[[ViewedArrayBuffer]]라고 하자.
  3. IsFixedLengthArrayBuffer(buffer)가 false이고 IsSharedArrayBuffer(buffer)도 false이면, false를 반환한다.
  4. true를 반환한다.

10.4.5.16 IsValidIntegerIndex ( obj, index )

The abstract operation IsValidIntegerIndex takes arguments obj (a TypedArray) and index (a Number) and returns a Boolean. It performs the following steps when called:

  1. IsDetachedBuffer(obj.[[ViewedArrayBuffer]])가 true이면, false를 반환한다.
  2. index정수 Number가 아니면, false를 반환한다.
  3. index-0𝔽이거나 index < -0𝔽이면, false를 반환한다.
  4. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, unordered)라고 하자.
  5. NOTE: obj의 backing buffer가 growable SharedArrayBuffer인 경우, 경계 검사는 동기화 연산이 아니다.
  6. IsTypedArrayOutOfBounds(taRecord)가 true이면, false를 반환한다.
  7. lengthTypedArrayLength(taRecord)라고 하자.
  8. (index) ≥ length이면, false를 반환한다.
  9. true를 반환한다.

10.4.5.17 TypedArrayGetElement ( obj, index )

The abstract operation TypedArrayGetElement takes arguments obj (a TypedArray) and index (a Number) and returns a Number, a BigInt, or undefined. It performs the following steps when called:

  1. IsValidIntegerIndex(obj, index)가 false이면, undefined를 반환한다.
  2. offsetobj.[[ByteOffset]]라고 하자.
  3. elementSizeTypedArrayElementSize(obj)라고 하자.
  4. byteIndexInBuffer를 ((index) × elementSize) + offset 이라고 하자.
  5. elementTypeTypedArrayElementType(obj)라고 하자.
  6. GetValueFromBuffer(obj.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType, true, unordered)를 반환한다.

10.4.5.18 TypedArraySetElement ( obj, index, value )

The abstract operation TypedArraySetElement takes arguments obj (a TypedArray), index (a Number), and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. obj.[[ContentType]]bigint이면, numValue를 ? ToBigInt(value)라고 하자.
  2. 그렇지 않으면, numValue를 ? ToNumber(value)라고 하자.
  3. IsValidIntegerIndex(obj, index)가 true이면,
    1. offsetobj.[[ByteOffset]]라고 하자.
    2. elementSizeTypedArrayElementSize(obj)라고 하자.
    3. byteIndexInBuffer를 ((index) × elementSize) + offset 이라고 하자.
    4. elementTypeTypedArrayElementType(obj)라고 하자.
    5. SetValueInBuffer(obj.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType, numValue, true, unordered)를 수행한다.
  4. unused를 반환한다.
Note

이 연산은 항상 성공한 것처럼 보이지만, TypedArray의 끝을 넘어 쓰려고 시도하거나 detached ArrayBuffer를 backing으로 가진 TypedArray에 쓰려고 시도할 때는 아무 효과가 없다.

10.4.5.19 IsArrayBufferViewOutOfBounds ( obj )

The abstract operation IsArrayBufferViewOutOfBounds takes argument obj (a TypedArray or a DataView) and returns a Boolean. 이것은 TypedArray의 수치 프로퍼티들이나 DataView 객체의 메서드 중 어느 하나라도 기반 data block의 경계 안에 포함되지 않는 인덱스의 값을 참조할 수 있는지를 검사한다. 이 추상 연산은 상위 명세를 위한 편의 기능으로 존재한다. It performs the following steps when called:

  1. obj[[DataView]] 내부 슬롯을 가지면,
    1. viewRecordMakeDataViewWithBufferWitnessRecord(obj, seq-cst)라고 하자.
    2. IsViewOutOfBounds(viewRecord)를 반환한다.
  2. taRecordMakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)라고 하자.
  3. IsTypedArrayOutOfBounds(taRecord)를 반환한다.

10.4.6 모듈 네임스페이스 이색 객체

모듈 네임스페이스 이색 객체는 ECMAScript Module에서 export된 바인딩을 노출하는 이색 객체이다 (참조: 16.2.3). 모듈 네임스페이스 이색 객체의 String 키를 가진 자체 프로퍼티와 Module이 export한 바인딩 이름 사이에는 일대일 대응이 있다. export된 바인딩에는 export * export item을 사용하여 간접적으로 export된 바인딩도 포함된다. 각 String 값의 자체 프로퍼티 키는 대응하는 export된 바인딩 이름의 StringValue이다. 이것들만이 모듈 네임스페이스 이색 객체의 String 키 프로퍼티이다. 각 그러한 프로퍼티는 { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false } 속성을 가진다. 모듈 네임스페이스 이색 객체는 확장 가능하지 않다.

객체는 그 [[GetPrototypeOf]], [[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[GetOwnProperty]], [[DefineOwnProperty]], [[HasProperty]], [[Get]], [[Set]], [[Delete]], [[OwnPropertyKeys]] 내부 메서드가 이 절의 정의를 사용하고, 다른 essential 내부 메서드는 10.1 에서 찾을 수 있는 정의를 사용할 때 모듈 네임스페이스 이색 객체 이다. 이 메서드들은 ModuleNamespaceCreate에 의해 설치된다.

모듈 네임스페이스 이색 객체Table 28 에 정의된 내부 슬롯을 가진다.

Table 28: Internal Slots of Module Namespace Exotic Objects
내부 슬롯 타입 설명
[[Module]] a Module Record 이 네임스페이스가 노출하는 export를 가진 Module Record.
[[Exports]] a List of Strings 이 객체의 자체 프로퍼티로 노출되는 export 이름들의 String 값을 요소로 가지는 List. 이 리스트는 코드 유닛 사전식 순서에 따라 정렬된다.

10.4.6.1 [[GetPrototypeOf]] ( )

The [[GetPrototypeOf]] internal method of 모듈 네임스페이스 이색 객체 takes no arguments and returns a normal completion containing null. It performs the following steps when called:

  1. null을 반환한다.

10.4.6.2 [[SetPrototypeOf]] ( proto )

The [[SetPrototypeOf]] internal method of 모듈 네임스페이스 이색 객체 obj takes argument proto (an Object or null) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. SetImmutablePrototype(obj, proto)를 반환한다.

10.4.6.3 [[IsExtensible]] ( )

The [[IsExtensible]] internal method of 모듈 네임스페이스 이색 객체 takes no arguments and returns a normal completion containing false. It performs the following steps when called:

  1. false를 반환한다.

10.4.6.4 [[PreventExtensions]] ( )

The [[PreventExtensions]] internal method of 모듈 네임스페이스 이색 객체 takes no arguments and returns a normal completion containing true. It performs the following steps when called:

  1. true를 반환한다.

10.4.6.5 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of 모듈 네임스페이스 이색 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing either a Property Descriptor or undefined, or a throw completion. It performs the following steps when called:

  1. propertyKey가 Symbol이면, OrdinaryGetOwnProperty(obj, propertyKey)를 반환한다.
  2. exportsobj.[[Exports]]라고 하자.
  3. exportspropertyKey를 포함하지 않으면, undefined를 반환한다.
  4. value를 ? obj.[[Get]](propertyKey, obj)라고 하자.
  5. PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false }를 반환한다.

10.4.6.6 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of 모듈 네임스페이스 이색 객체 obj takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. propertyKey가 Symbol이면, ! OrdinaryDefineOwnProperty(obj, propertyKey, desc)를 반환한다.
  2. current를 ? obj.[[GetOwnProperty]](propertyKey)라고 하자.
  3. currentundefined이면, false를 반환한다.
  4. desc[[Configurable]] 필드를 가지고 desc.[[Configurable]]true이면, false를 반환한다.
  5. desc[[Enumerable]] 필드를 가지고 desc.[[Enumerable]]false이면, false를 반환한다.
  6. IsAccessorDescriptor(desc)가 true이면, false를 반환한다.
  7. desc[[Writable]] 필드를 가지고 desc.[[Writable]]false이면, false를 반환한다.
  8. desc[[Value]] 필드를 가지면, SameValue(desc.[[Value]], current.[[Value]])를 반환한다.
  9. true를 반환한다.

10.4.6.7 [[HasProperty]] ( propertyKey )

The [[HasProperty]] internal method of 모듈 네임스페이스 이색 객체 obj takes argument propertyKey (a property key) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. propertyKey가 Symbol이면, ! OrdinaryHasProperty(obj, propertyKey)를 반환한다.
  2. exportsobj.[[Exports]]라고 하자.
  3. exportspropertyKey를 포함하면, true를 반환한다.
  4. false를 반환한다.

10.4.6.8 [[Get]] ( propertyKey, receiver )

The [[Get]] internal method of 모듈 네임스페이스 이색 객체 obj takes arguments propertyKey (a property key) and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. propertyKey가 Symbol이면,
    1. OrdinaryGet(obj, propertyKey, receiver)를 반환한다.
  2. exportsobj.[[Exports]]라고 하자.
  3. exportspropertyKey를 포함하지 않으면, undefined를 반환한다.
  4. moduleobj.[[Module]]이라고 하자.
  5. bindingmodule.ResolveExport(propertyKey)라고 하자.
  6. Assert: binding은 ResolvedBinding Record이다.
  7. targetModulebinding.[[Module]]이라고 하자.
  8. Assert: targetModuleundefined가 아니다.
  9. binding.[[BindingName]]namespace이면,
    1. GetModuleNamespace(targetModule)를 반환한다.
  10. targetEnvtargetModule.[[Environment]]라고 하자.
  11. targetEnvempty이면, ReferenceError 예외를 던진다.
  12. targetEnv.GetBindingValue(binding.[[BindingName]], true) 를 반환한다.
Note

ResolveExport는 부작용이 없다. 이 연산이 특정 exportName, resolveSet 쌍을 인수로 호출될 때마다 반드시 같은 결과를 반환해야 한다. 구현은 각 모듈 네임스페이스 이색 객체[[Exports]]에 대한 ResolveExport 결과를 미리 계산하거나 캐시하도록 선택할 수 있다.

10.4.6.9 [[Set]] ( propertyKey, value, receiver )

The [[Set]] internal method of 모듈 네임스페이스 이색 객체 takes arguments propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns a normal completion containing false. It performs the following steps when called:

  1. false를 반환한다.

10.4.6.10 [[Delete]] ( propertyKey )

The [[Delete]] internal method of 모듈 네임스페이스 이색 객체 obj takes argument propertyKey (a property key) and returns a normal completion containing a Boolean. It performs the following steps when called:

  1. propertyKey가 Symbol이면,
    1. OrdinaryDelete(obj, propertyKey)를 반환한다.
  2. exportsobj.[[Exports]]라고 하자.
  3. exportspropertyKey를 포함하면, false를 반환한다.
  4. true를 반환한다.

10.4.6.11 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of 모듈 네임스페이스 이색 객체 obj takes no arguments and returns a normal completion containing a List of property keys. It performs the following steps when called:

  1. exportsobj.[[Exports]]라고 하자.
  2. symbolKeysOrdinaryOwnPropertyKeys(obj)라고 하자.
  3. exportssymbolKeyslist-concatenation을 반환한다.

10.4.6.12 ModuleNamespaceCreate ( module, exports )

The abstract operation ModuleNamespaceCreate takes arguments module (a Module Record) and exports (a List of Strings) and returns a module namespace exotic object. 이것은 새로운 모듈 네임스페이스 이색 객체의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. Assert: module.[[Namespace]]empty이다.
  2. internalSlotsListTable 28 에 나열된 내부 슬롯이라고 하자.
  3. namespaceMakeBasicObject(internalSlotsList)라고 하자.
  4. namespace의 essential 내부 메서드를 10.4.6 에 명시된 정의로 설정한다.
  5. namespace.[[Module]]module로 설정한다.
  6. sortedExportsexports의 요소들을 코드 유닛 사전식 순서에 따라 정렬한 List라고 하자.
  7. namespace.[[Exports]]sortedExports로 설정한다.
  8. 28.3의 정의에 대응하는 namespace의 자체 프로퍼티를 생성한다.
  9. module.[[Namespace]]namespace로 설정한다.
  10. namespace를 반환한다.

10.4.7 불변 프로토타입 이색 객체

불변 프로토타입 이색 객체는, 한 번 초기화되면 더 이상 바뀌지 않는 [[Prototype]] 내부 슬롯을 가진 이색 객체이다.

객체는 그 [[SetPrototypeOf]] 내부 메서드가 다음 구현을 사용할 때 불변 프로토타입 이색 객체 이다. (다른 essential 내부 메서드는, 해당 불변 프로토타입 이색 객체의 구체적 성격에 따라, 임의의 구현을 사용할 수 있다.)

Note

다른 이색 객체와 달리, 불변 프로토타입 이색 객체를 위한 전용 생성 추상 연산은 제공되지 않는다. 이는 그것들이 오직 %Object.prototype%호스트 환경에서만 사용되기 때문이며, 호스트 환경에서는 관련 객체들이 다른 방식으로도 이색적일 수 있으므로 별도의 전용 생성 연산이 필요하다.

10.4.7.1 [[SetPrototypeOf]] ( proto )

The [[SetPrototypeOf]] internal method of 불변 프로토타입 이색 객체 obj takes argument proto (an Object or null) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. SetImmutablePrototype(obj, proto)를 반환한다.

10.4.7.2 SetImmutablePrototype ( obj, proto )

The abstract operation SetImmutablePrototype takes arguments obj (an Object) and proto (an Object or null) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. current를 ? obj.[[GetPrototypeOf]]() 라고 하자.
  2. SameValue(proto, current)가 true이면, true를 반환한다.
  3. false를 반환한다.

10.5 프록시 객체 내부 메서드와 내부 슬롯

프록시 객체는 essential 내부 메서드가 부분적으로 ECMAScript 코드를 사용하여 구현되는 이색 객체이다. 모든 프록시 객체는 [[ProxyHandler]]라는 내부 슬롯을 가진다. [[ProxyHandler]]의 값은 프록시의 handler object라고 불리는 객체이거나 null이다. handler object의 메서드(참조: Table 29)는 프록시 객체의 하나 이상의 내부 메서드 구현을 보강하는 데 사용될 수 있다. 모든 프록시 객체는 또한 [[ProxyTarget]]이라는 내부 슬롯을 가지며, 그 값은 객체 또는 null이다. 이 객체는 프록시의 target object라고 불린다.

객체는 그 essential 내부 메서드(해당하는 경우 [[Call]][[Construct]] 포함)가 이 절의 정의를 사용할 때 프록시 이색 객체 이다. 이 내부 메서드들은 ProxyCreate에서 설치된다.

Table 29: Proxy Handler Methods
내부 메서드 핸들러 메서드
[[GetPrototypeOf]] getPrototypeOf
[[SetPrototypeOf]] setPrototypeOf
[[IsExtensible]] isExtensible
[[PreventExtensions]] preventExtensions
[[GetOwnProperty]] getOwnPropertyDescriptor
[[DefineOwnProperty]] defineProperty
[[HasProperty]] has
[[Get]] get
[[Set]] set
[[Delete]] deleteProperty
[[OwnPropertyKeys]] ownKeys
[[Call]] apply
[[Construct]] construct

프록시 객체 내부 메서드의 구현을 제공하기 위해 handler 메서드가 호출될 때, 그 handler 메서드에는 프록시의 target object가 매개변수로 전달된다. 프록시의 handler object가 반드시 모든 essential 내부 메서드에 대응하는 메서드를 가지는 것은 아니다. 프록시에 대한 내부 메서드 호출은, handler object가 대응하는 내부 trap에 대한 메서드를 가지지 않을 경우, 프록시의 target object에 대한 대응 내부 메서드 호출이 일어나게 한다.

프록시 객체의 [[ProxyHandler]][[ProxyTarget]] 내부 슬롯은 객체가 생성될 때 항상 초기화되며, 일반적으로 수정될 수 없다. 일부 프록시 객체는 나중에 revoked될 수 있도록 허용하는 방식으로 생성된다. 프록시가 revoked되면, 그 [[ProxyHandler]][[ProxyTarget]] 내부 슬롯은 null로 설정되며, 그 결과 그 프록시 객체에 대한 이후의 내부 메서드 호출은 TypeError 예외를 던지게 된다.

프록시 객체는 내부 메서드의 구현을 임의의 ECMAScript 코드로 제공할 수 있게 허용하기 때문에, 6.1.7.3 에 정의된 불변식을 위반하는 handler 메서드를 가진 프록시 객체를 정의하는 것이 가능하다. 6.1.7.3 에 정의된 내부 메서드 불변식 중 일부는 essential 무결성 불변식이다. 이러한 불변식은 이 절에 명시된 프록시 객체 내부 메서드에 의해 명시적으로 강제된다. ECMAScript 구현은 가능한 모든 불변식 위반이 존재하는 상황에서도 견고해야 한다.

다음 알고리즘 설명에서, obj는 ECMAScript 프록시 객체이고, propertyKey는 프로퍼티 키 값이며, value는 임의의 ECMAScript 언어 값이고, descProperty Descriptor 레코드라고 가정한다.

10.5.1 [[GetPrototypeOf]] ( )

The [[GetPrototypeOf]] internal method of 프록시 이색 객체 obj takes no arguments and returns either a normal completion containing either an Object or null, or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "getPrototypeOf")라고 하자.
  6. trapundefined이면,
    1. target.[[GetPrototypeOf]]()를 반환한다.
  7. handlerProto를 ? Call(trap, handler, « target »)라고 하자.
  8. handlerProto가 Object도 아니고 null도 아니면, TypeError 예외를 던진다.
  9. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  10. extensibleTargettrue이면, handlerProto를 반환한다.
  11. targetProto를 ? target.[[GetPrototypeOf]]()라고 하자.
  12. SameValue(handlerProto, targetProto)가 false이면, TypeError 예외를 던진다.
  13. handlerProto를 반환한다.
Note

프록시 객체에 대한 [[GetPrototypeOf]]는 다음 불변식을 강제한다:

  • [[GetPrototypeOf]]의 결과는 반드시 Object 또는 null이어야 한다.
  • target 객체가 확장 가능하지 않다면, 프록시 객체에 적용된 [[GetPrototypeOf]]는 프록시 객체의 target 객체에 적용된 [[GetPrototypeOf]]와 같은 값을 반환해야 한다.

10.5.2 [[SetPrototypeOf]] ( proto )

The [[SetPrototypeOf]] internal method of 프록시 이색 객체 obj takes argument proto (an Object or null) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "setPrototypeOf")라고 하자.
  6. trapundefined이면,
    1. target.[[SetPrototypeOf]](proto)를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target, proto »))라고 하자.
  8. booleanTrapResultfalse이면, false를 반환한다.
  9. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  10. extensibleTargettrue이면, true를 반환한다.
  11. targetProto를 ? target.[[GetPrototypeOf]]()라고 하자.
  12. SameValue(proto, targetProto)가 false이면, TypeError 예외를 던진다.
  13. true를 반환한다.
Note

프록시 객체에 대한 [[SetPrototypeOf]]는 다음 불변식을 강제한다:

  • [[SetPrototypeOf]]의 결과는 Boolean 값이다.
  • target 객체가 확장 가능하지 않다면, 인수 값은 target 객체에 [[GetPrototypeOf]]를 적용한 결과와 같아야 한다.

10.5.3 [[IsExtensible]] ( )

The [[IsExtensible]] internal method of 프록시 이색 객체 obj takes no arguments and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "isExtensible")라고 하자.
  6. trapundefined이면,
    1. IsExtensible(target)를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target »))라고 하자.
  8. targetResult를 ? IsExtensible(target)라고 하자.
  9. booleanTrapResulttargetResult와 다르면, TypeError 예외를 던진다.
  10. booleanTrapResult를 반환한다.
Note

프록시 객체에 대한 [[IsExtensible]]는 다음 불변식을 강제한다:

  • [[IsExtensible]]의 결과는 Boolean 값이다.
  • 프록시 객체에 적용된 [[IsExtensible]]는 같은 인수로 프록시 객체의 target 객체에 적용된 [[IsExtensible]]와 같은 값을 반환해야 한다.

10.5.4 [[PreventExtensions]] ( )

The [[PreventExtensions]] internal method of 프록시 이색 객체 obj takes no arguments and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "preventExtensions")라고 하자.
  6. trapundefined이면,
    1. target.[[PreventExtensions]]()를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target »))라고 하자.
  8. booleanTrapResulttrue이면,
    1. extensibleTarget을 ? IsExtensible(target)이라고 하자.
    2. extensibleTargettrue이면, TypeError 예외를 던진다.
  9. booleanTrapResult를 반환한다.
Note

프록시 객체에 대한 [[PreventExtensions]]는 다음 불변식을 강제한다:

  • [[PreventExtensions]]의 결과는 Boolean 값이다.
  • 프록시 객체에 적용된 [[PreventExtensions]]는 프록시 객체의 target 객체에 [[IsExtensible]]를 적용했을 때 false인 경우에만 true를 반환한다.

10.5.5 [[GetOwnProperty]] ( propertyKey )

The [[GetOwnProperty]] internal method of 프록시 이색 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing either a Property Descriptor or undefined, or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "getOwnPropertyDescriptor") 라고 하자.
  6. trapundefined이면,
    1. target.[[GetOwnProperty]](propertyKey)를 반환한다.
  7. trapResultObj를 ? Call(trap, handler, « target, propertyKey »)라고 하자.
  8. trapResultObj가 Object도 아니고 undefined도 아니면, TypeError 예외를 던진다.
  9. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
  10. trapResultObjundefined이면,
    1. targetDescundefined이면, undefined를 반환한다.
    2. targetDesc.[[Configurable]]false이면, TypeError 예외를 던진다.
    3. extensibleTarget을 ? IsExtensible(target)이라고 하자.
    4. extensibleTargetfalse이면, TypeError 예외를 던진다.
    5. undefined를 반환한다.
  11. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  12. resultDesc를 ? ToPropertyDescriptor(trapResultObj)라고 하자.
  13. CompletePropertyDescriptor(resultDesc)를 수행한다.
  14. validIsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc)라고 하자.
  15. validfalse이면, TypeError 예외를 던진다.
  16. resultDesc.[[Configurable]]false이면,
    1. targetDescundefined이거나 targetDesc.[[Configurable]]true이면,
      1. TypeError 예외를 던진다.
    2. resultDesc[[Writable]] 필드를 가지고 resultDesc.[[Writable]]false이면,
      1. Assert: targetDesc[[Writable]] 필드를 가진다.
      2. targetDesc.[[Writable]]true이면, TypeError 예외를 던진다.
  17. resultDesc를 반환한다.
Note

프록시 객체에 대한 [[GetOwnProperty]]는 다음 불변식을 강제한다:

  • [[GetOwnProperty]]의 결과는 반드시 Property Descriptor 또는 undefined여야 한다.
  • target 객체에 non-configurable 자체 프로퍼티로 존재하는 프로퍼티는 존재하지 않는 것으로 보고될 수 없다.
  • non-extensible target 객체의 자체 프로퍼티로 존재하는 프로퍼티는 존재하지 않는 것으로 보고될 수 없다.
  • target 객체에 자체 프로퍼티로 존재하지 않고 target 객체가 확장 가능하지 않은 경우, 그 프로퍼티는 존재하는 것으로 보고될 수 없다.
  • 프로퍼티는 target 객체의 대응하는 non-configurable 자체 프로퍼티로 존재하지 않는 한 non-configurable로 보고될 수 없다.
  • 프로퍼티는 target 객체의 대응하는 non-configurable, non-writable 자체 프로퍼티로 존재하지 않는 한, non-configurable이면서 non-writable인 것으로 보고될 수 없다.

10.5.6 [[DefineOwnProperty]] ( propertyKey, desc )

The [[DefineOwnProperty]] internal method of 프록시 이색 객체 obj takes arguments propertyKey (a property key) and desc (a Property Descriptor) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "defineProperty")라고 하자.
  6. trapundefined이면,
    1. target.[[DefineOwnProperty]](propertyKey, desc)를 반환한다.
  7. descObjFromPropertyDescriptor(desc)라고 하자.
  8. booleanTrapResultToBoolean(? Call(trap, handler, « target, propertyKey, descObj »))라고 하자.
  9. booleanTrapResultfalse이면, false를 반환한다.
  10. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
  11. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  12. desc[[Configurable]] 필드를 가지고 desc.[[Configurable]]false이면,
    1. settingConfigFalsetrue라고 하자.
  13. 그렇지 않으면,
    1. settingConfigFalsefalse라고 하자.
  14. targetDescundefined이면,
    1. extensibleTargetfalse이면, TypeError 예외를 던진다.
    2. settingConfigFalsetrue이면, TypeError 예외를 던진다.
  15. 그렇지 않으면,
    1. IsCompatiblePropertyDescriptor(extensibleTarget, desc, targetDesc)가 false이면, TypeError 예외를 던진다.
    2. settingConfigFalsetrue이고 targetDesc.[[Configurable]]true이면, TypeError 예외를 던진다.
    3. IsDataDescriptor(targetDesc)가 true이고, targetDesc.[[Configurable]]false이며, targetDesc.[[Writable]]true이면,
      1. desc[[Writable]] 필드를 가지고 desc.[[Writable]]false이면, TypeError 예외를 던진다.
  16. true를 반환한다.
Note

프록시 객체에 대한 [[DefineOwnProperty]]는 다음 불변식을 강제한다:

  • [[DefineOwnProperty]]의 결과는 Boolean 값이다.
  • target 객체가 확장 가능하지 않다면 프로퍼티는 추가될 수 없다.
  • target 객체에 대응하는 non-configurable 자체 프로퍼티가 존재하지 않는 한, 프로퍼티는 non-configurable일 수 없다.
  • target 객체에 대응하는 non-configurable, non-writable 자체 프로퍼티가 존재하지 않는 한, non-configurable 프로퍼티는 non-writable일 수 없다.
  • 프로퍼티가 대응하는 target 객체 프로퍼티를 가지는 경우, 그 프로퍼티의 Property Descriptor[[DefineOwnProperty]]를 사용하여 target 객체에 적용해도 예외를 던지지 않는다.

10.5.7 [[HasProperty]] ( propertyKey )

The [[HasProperty]] internal method of 프록시 이색 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "has")라고 하자.
  6. trapundefined이면,
    1. target.[[HasProperty]](propertyKey)를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target, propertyKey »))라고 하자.
  8. booleanTrapResultfalse이면,
    1. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
    2. targetDescundefined가 아니면,
      1. targetDesc.[[Configurable]]false이면, TypeError 예외를 던진다.
      2. extensibleTarget을 ? IsExtensible(target)이라고 하자.
      3. extensibleTargetfalse이면, TypeError 예외를 던진다.
  9. booleanTrapResult를 반환한다.
Note

프록시 객체에 대한 [[HasProperty]]는 다음 불변식을 강제한다:

  • [[HasProperty]]의 결과는 Boolean 값이다.
  • target 객체에 non-configurable 자체 프로퍼티로 존재하는 프로퍼티는 존재하지 않는 것으로 보고될 수 없다.
  • target 객체의 자체 프로퍼티로 존재하고 target 객체가 확장 가능하지 않은 경우, 그 프로퍼티는 존재하지 않는 것으로 보고될 수 없다.

10.5.8 [[Get]] ( propertyKey, receiver )

The [[Get]] internal method of 프록시 이색 객체 obj takes arguments propertyKey (a property key) and receiver (an ECMAScript language value) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "get")라고 하자.
  6. trapundefined이면,
    1. target.[[Get]](propertyKey, receiver)를 반환한다.
  7. trapResult를 ? Call(trap, handler, « target, propertyKey, receiver »)라고 하자.
  8. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
  9. targetDescundefined가 아니고 targetDesc.[[Configurable]]false이면,
    1. IsDataDescriptor(targetDesc)가 true이고 targetDesc.[[Writable]]false이면,
      1. SameValue(trapResult, targetDesc.[[Value]])가 false이면, TypeError 예외를 던진다.
    2. IsAccessorDescriptor(targetDesc)가 true이고 targetDesc.[[Get]]undefined이면,
      1. trapResultundefined가 아니면, TypeError 예외를 던진다.
  10. trapResult를 반환한다.
Note

프록시 객체에 대한 [[Get]]은 다음 불변식을 강제한다:

  • target 객체의 대응 프로퍼티가 non-writable, non-configurable 자체 데이터 프로퍼티라면, 프로퍼티에 대해 보고된 값은 그 target 객체 프로퍼티의 값과 같아야 한다.
  • target 객체의 대응 프로퍼티가 [[Get]] 속성으로 undefined를 가진 non-configurable 자체 접근자 프로퍼티라면, 프로퍼티에 대해 보고된 값은 반드시 undefined이어야 한다.

10.5.9 [[Set]] ( propertyKey, value, receiver )

The [[Set]] internal method of 프록시 이색 객체 obj takes arguments propertyKey (a property key), value (an ECMAScript language value), and receiver (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "set")라고 하자.
  6. trapundefined이면,
    1. target.[[Set]](propertyKey, value, receiver)를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target, propertyKey, value, receiver »))라고 하자.
  8. booleanTrapResultfalse이면, false를 반환한다.
  9. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
  10. targetDescundefined가 아니고 targetDesc.[[Configurable]]false이면,
    1. IsDataDescriptor(targetDesc)가 true이고 targetDesc.[[Writable]]false이면,
      1. SameValue(value, targetDesc.[[Value]])가 false이면, TypeError 예외를 던진다.
    2. IsAccessorDescriptor(targetDesc)가 true이면,
      1. targetDesc.[[Set]]undefined이면, TypeError 예외를 던진다.
  11. true를 반환한다.
Note

프록시 객체에 대한 [[Set]]은 다음 불변식을 강제한다:

  • [[Set]]의 결과는 Boolean 값이다.
  • 대응하는 target 객체 프로퍼티가 non-writable, non-configurable 자체 데이터 프로퍼티인 경우, 그 프로퍼티의 값을 대응하는 target 객체 프로퍼티의 값과 다르게 변경할 수 없다.
  • 대응하는 target 객체 프로퍼티가 [[Set]] 속성으로 undefined를 가진 non-configurable 자체 접근자 프로퍼티인 경우, 그 프로퍼티의 값을 설정할 수 없다.

10.5.10 [[Delete]] ( propertyKey )

The [[Delete]] internal method of 프록시 이색 객체 obj takes argument propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "deleteProperty")라고 하자.
  6. trapundefined이면,
    1. target.[[Delete]](propertyKey)를 반환한다.
  7. booleanTrapResultToBoolean(? Call(trap, handler, « target, propertyKey »))라고 하자.
  8. booleanTrapResultfalse이면, false를 반환한다.
  9. targetDesc를 ? target.[[GetOwnProperty]](propertyKey)라고 하자.
  10. targetDescundefined이면, true를 반환한다.
  11. targetDesc.[[Configurable]]false이면, TypeError 예외를 던진다.
  12. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  13. extensibleTargetfalse이면, TypeError 예외를 던진다.
  14. true를 반환한다.
Note

프록시 객체에 대한 [[Delete]]는 다음 불변식을 강제한다:

  • [[Delete]]의 결과는 Boolean 값이다.
  • target 객체에 non-configurable 자체 프로퍼티로 존재하는 프로퍼티는 삭제된 것으로 보고될 수 없다.
  • target 객체에 자체 프로퍼티로 존재하고 target 객체가 non-extensible인 경우, 그 프로퍼티는 삭제된 것으로 보고될 수 없다.

10.5.11 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of 프록시 이색 객체 obj takes no arguments and returns either a normal completion containing a List of property keys or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "ownKeys")라고 하자.
  6. trapundefined이면,
    1. target.[[OwnPropertyKeys]]()를 반환한다.
  7. trapResultArray를 ? Call(trap, handler, « target ») 라고 하자.
  8. trapResult를 ? CreateListFromArrayLike(trapResultArray, property-key)라고 하자.
  9. trapResult가 중복 항목을 하나라도 포함하면, TypeError 예외를 던진다.
  10. extensibleTarget을 ? IsExtensible(target)이라고 하자.
  11. targetKeys를 ? target.[[OwnPropertyKeys]]()라고 하자.
  12. Assert: targetKeys는 프로퍼티 키의 List이다.
  13. Assert: targetKeys는 중복 항목을 포함하지 않는다.
  14. targetConfigurableKeys를 새로운 빈 List라고 하자.
  15. targetNonconfigurableKeys를 새로운 빈 List라고 하자.
  16. targetKeys의 각 요소 key에 대해, 다음을 수행한다
    1. desc를 ? target.[[GetOwnProperty]](key)라고 하자.
    2. descundefined가 아니고 desc.[[Configurable]]false이면,
      1. keytargetNonconfigurableKeys에 추가한다.
    3. 그렇지 않으면,
      1. keytargetConfigurableKeys에 추가한다.
  17. extensibleTargettrue이고 targetNonconfigurableKeys가 비어 있으면,
    1. trapResult를 반환한다.
  18. uncheckedResultKeystrapResult의 요소들을 요소로 가지는 List라고 하자.
  19. targetNonconfigurableKeys의 각 요소 key에 대해, 다음을 수행한다
    1. uncheckedResultKeyskey를 포함하지 않으면, TypeError 예외를 던진다.
    2. uncheckedResultKeys에서 key를 제거한다.
  20. extensibleTargettrue이면, trapResult를 반환한다.
  21. targetConfigurableKeys의 각 요소 key에 대해, 다음을 수행한다
    1. uncheckedResultKeyskey를 포함하지 않으면, TypeError 예외를 던진다.
    2. uncheckedResultKeys에서 key를 제거한다.
  22. uncheckedResultKeys가 비어 있지 않으면, TypeError 예외를 던진다.
  23. trapResult를 반환한다.
Note

프록시 객체에 대한 [[OwnPropertyKeys]]는 다음 불변식을 강제한다:

  • [[OwnPropertyKeys]]의 결과는 List이다.
  • 반환된 List는 중복 항목을 포함하지 않는다.
  • 반환된 List의 각 요소는 프로퍼티 키이다.
  • 결과 List는 target 객체의 모든 non-configurable 자체 프로퍼티의 키를 포함해야 한다.
  • target 객체가 확장 가능하지 않다면, 결과 List는 target 객체의 모든 자체 프로퍼티의 키를 포함해야 하며 다른 값은 포함해서는 안 된다.

10.5.12 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method of 프록시 이색 객체 obj takes arguments thisArgument (an ECMAScript language value) and argumentsList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. handlerobj.[[ProxyHandler]]라고 하자.
  4. Assert: handler는 Object이다.
  5. trap을 ? GetMethod(handler, "apply")라고 하자.
  6. trapundefined이면,
    1. Call(target, thisArgument, argumentsList)를 반환한다.
  7. argArrayCreateArrayFromList(argumentsList)라고 하자.
  8. Call(trap, handler, « target, thisArgument, argArray »)를 반환한다.
Note

프록시 이색 객체는 그 [[ProxyTarget]] 내부 슬롯의 초기값이 [[Call]] 내부 메서드를 가진 객체인 경우에만 [[Call]] 내부 메서드를 가진다.

10.5.13 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of 프록시 이색 객체 obj takes arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. ValidateNonRevokedProxy(obj)를 수행한다.
  2. targetobj.[[ProxyTarget]]이라고 하자.
  3. Assert: IsConstructor(target)는 true이다.
  4. handlerobj.[[ProxyHandler]]라고 하자.
  5. Assert: handler는 Object이다.
  6. trap을 ? GetMethod(handler, "construct")라고 하자.
  7. trapundefined이면,
    1. Construct(target, argumentsList, newTarget)를 반환한다.
  8. argArrayCreateArrayFromList(argumentsList)라고 하자.
  9. newObj를 ? Call(trap, handler, « target, argArray, newTarget »)라고 하자.
  10. newObj가 Object가 아니면, TypeError 예외를 던진다.
  11. newObj를 반환한다.
Note 1

프록시 이색 객체는 그 [[ProxyTarget]] 내부 슬롯의 초기값이 [[Construct]] 내부 메서드를 가진 객체인 경우에만 [[Construct]] 내부 메서드를 가진다.

Note 2

프록시 객체에 대한 [[Construct]]는 다음 불변식을 강제한다:

  • [[Construct]]의 결과는 반드시 Object여야 한다.

10.5.14 ValidateNonRevokedProxy ( proxy )

The abstract operation ValidateNonRevokedProxy takes argument proxy (a Proxy exotic object) and returns either a normal completion containing unused or a throw completion. proxy가 revoked되었으면 TypeError 예외를 던진다. It performs the following steps when called:

  1. proxy.[[ProxyTarget]]null이면, TypeError 예외를 던진다.
  2. Assert: proxy.[[ProxyHandler]]null이 아니다.
  3. unused를 반환한다.

10.5.15 ProxyCreate ( target, handler )

The abstract operation ProxyCreate takes arguments target (an ECMAScript language value) and handler (an ECMAScript language value) and returns either a normal completion containing a Proxy exotic object or a throw completion. 이것은 새로운 프록시 객체의 생성을 명세하는 데 사용된다. It performs the following steps when called:

  1. target이 Object가 아니면, TypeError 예외를 던진다.
  2. handler가 Object가 아니면, TypeError 예외를 던진다.
  3. proxyMakeBasicObject[[ProxyHandler]], [[ProxyTarget]] ») 라고 하자.
  4. proxy의 essential 내부 메서드 중 [[Call]][[Construct]]를 제외한 것들을 10.5 에 명시된 정의로 설정한다.
  5. IsCallable(target)가 true이면,
    1. proxy.[[Call]]10.5.12 에 명시된 대로 설정한다.
    2. IsConstructor(target)가 true이면,
      1. proxy.[[Construct]]10.5.13 에 명시된 대로 설정한다.
  6. proxy.[[ProxyTarget]]target으로 설정한다.
  7. proxy.[[ProxyHandler]]handler로 설정한다.
  8. proxy를 반환한다.