28 리플렉션

28.1 Reflect 객체

Reflect 객체:

  • %Reflect%이다.
  • 전역 객체"Reflect" 프로퍼티의 초기값이다.
  • 일반 객체이다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 함수 객체가 아니다.
  • [[Construct]] 내부 메서드가 없다; new 연산자로 생성자로 사용할 수 없다.
  • [[Call]] 내부 메서드가 없다; 함수로 호출될 수 없다.

28.1.1 Reflect.apply ( target, thisArgument, argumentsList )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. IsCallable(target)이 false이면 TypeError 예외를 발생시킨다.
  2. args를 ? CreateListFromArrayLike(argumentsList)로 한다.
  3. PrepareForTailCall()을 수행한다.
  4. Call(target, thisArgument, args)를 반환한다.

28.1.2 Reflect.construct ( target, argumentsList [ , newTarget ] )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. IsConstructor(target)이 false이면 TypeError 예외를 발생시킨다.
  2. newTarget이 없으면 newTargettarget으로 설정한다.
  3. 아니면 IsConstructor(newTarget)이 false이면 TypeError 예외를 발생시킨다.
  4. args를 ? CreateListFromArrayLike(argumentsList)로 한다.
  5. Construct(target, args, newTarget)을 반환한다.

28.1.3 Reflect.defineProperty ( target, propertyKey, attributes )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. desc를 ? ToPropertyDescriptor(attributes)로 한다.
  4. target.[[DefineOwnProperty]](key, desc)를 반환한다.

28.1.4 Reflect.deleteProperty ( target, propertyKey )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. target.[[Delete]](key)를 반환한다.

28.1.5 Reflect.get ( target, propertyKey [ , receiver ] )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. receiver가 없으면,
    1. receivertarget으로 설정한다.
  4. target.[[Get]](key, receiver)를 반환한다.

28.1.6 Reflect.getOwnPropertyDescriptor ( target, propertyKey )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. desc를 ? target.[[GetOwnProperty]](key)로 한다.
  4. FromPropertyDescriptor(desc)를 반환한다.

28.1.7 Reflect.getPrototypeOf ( target )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. target.[[GetPrototypeOf]]()를 반환한다.

28.1.8 Reflect.has ( target, propertyKey )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. target.[[HasProperty]](key)를 반환한다.

28.1.9 Reflect.isExtensible ( target )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. target.[[IsExtensible]]()를 반환한다.

28.1.10 Reflect.ownKeys ( target )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. keys를 ? target.[[OwnPropertyKeys]]()로 한다.
  3. CreateArrayFromList(keys)를 반환한다.

28.1.11 Reflect.preventExtensions ( target )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. target.[[PreventExtensions]]()를 반환한다.

28.1.12 Reflect.set ( target, propertyKey, V [ , receiver ] )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. key를 ? ToPropertyKey(propertyKey)로 한다.
  3. receiver가 없으면,
    1. receivertarget으로 설정한다.
  4. target.[[Set]](key, V, receiver)를 반환한다.

28.1.13 Reflect.setPrototypeOf ( target, proto )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. target이 객체가 아니면 TypeError 예외를 발생시킨다.
  2. proto가 객체가 아니고 null도 아니면 TypeError 예외를 발생시킨다.
  3. target.[[SetPrototypeOf]](proto)를 반환한다.

28.1.14 Reflect [ %Symbol.toStringTag% ]

%Symbol.toStringTag% 프로퍼티의 초기값은 문자열 값 "Reflect"이다.

이 프로퍼티의 속성은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }이다.

28.2 프록시 객체

28.2.1 Proxy 생성자

Proxy 생성자:

  • %Proxy%이다.
  • 전역 객체"Proxy" 프로퍼티의 초기값이다.
  • 생성자로 호출될 때 새로운 프록시 객체를 생성하고 초기화한다.
  • 함수로 호출되는 것은 의도된 사용이 아니며, 그렇게 호출하면 예외를 발생시킨다.

28.2.1.1 Proxy ( target, handler )

이 함수가 호출될 때 다음 단계를 수행한다:

  1. NewTarget이 undefined이면 TypeError 예외를 발생시킨다.
  2. ProxyCreate(target, handler)를 반환한다.

28.2.2 Proxy 생성자의 속성

Proxy 생성자:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 프록시 객체가 초기화할 [[Prototype]] 내부 슬롯을 가지지 않으므로 "prototype" 프로퍼티가 없다.
  • 다음의 속성들을 가진다:

28.2.2.1 Proxy.revocable ( target, handler )

이 함수는 취소 가능한 프록시 객체를 생성한다.

호출 시 다음 단계를 수행한다:

  1. proxy를 ? ProxyCreate(target, handler)로 한다.
  2. revokerClosure를 파라미터가 없고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 수행하는 새로운 추상 클로저로 한다:
    1. F를 활성 함수 객체로 한다.
    2. pF.[[RevocableProxy]]로 한다.
    3. pnull이면 NormalCompletion(undefined)를 반환한다.
    4. F.[[RevocableProxy]]null로 설정한다.
    5. p는 프록시 익조틱 객체임을 단언한다.
    6. p.[[ProxyTarget]]null로 설정한다.
    7. p.[[ProxyHandler]]null로 설정한다.
    8. NormalCompletion(undefined)를 반환한다.
  3. revokerCreateBuiltinFunction(revokerClosure, 0, "", « [[RevocableProxy]] »)로 한다.
  4. revoker.[[RevocableProxy]]proxy로 설정한다.
  5. resultOrdinaryObjectCreate(%Object.prototype%)로 한다.
  6. CreateDataPropertyOrThrow(result, "proxy", proxy)를 수행한다.
  7. CreateDataPropertyOrThrow(result, "revoke", revoker)를 수행한다.
  8. result를 반환한다.

28.3 모듈 네임스페이스 객체

모듈 네임스페이스 객체는 모듈 네임스페이스 익조틱 객체로, 모듈의 내보낸 바인딩에 대한 런타임 프로퍼티 기반 접근을 제공한다. 모듈 네임스페이스 객체의 생성자 함수는 없다. 대신, NameSpaceImport를 포함하는 ImportDeclaration에 의해 임포트된 각 모듈마다 이러한 객체가 생성된다.

10.4.6에 명시된 속성 외에도 각 모듈 네임스페이스 객체는 다음의 고유 프로퍼티를 가진다:

28.3.1 %Symbol.toStringTag%

%Symbol.toStringTag% 프로퍼티의 초기값은 문자열 값 "Module"이다.

이 프로퍼티의 속성은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.