28 Reflection

28.1 Reflect 객체

Reflect object는:

  • %Reflect%입니다.
  • global object"Reflect" property의 initial value입니다.
  • ordinary object입니다.
  • value가 %Object.prototype%[[Prototype]] internal slot을 가집니다.
  • function object가 아닙니다.
  • [[Construct]] internal method를 가지지 않습니다; new operator와 함께 constructor로 사용될 수 없습니다.
  • [[Call]] internal method를 가지지 않습니다; function으로 invoked될 수 없습니다.

28.1.1 Reflect.apply ( target, thisArg, args )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. IsCallable(target)이 false이면, TypeError exception을 throw한다.
  2. argList를 ? CreateListFromArrayLike(args)로 둔다.
  3. PrepareForTailCall()을 수행한다.
  4. Call(target, thisArg, argList)를 반환한다.

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

이 function은 호출될 때 다음 steps를 수행합니다:

  1. IsConstructor(target)가 false이면, TypeError exception을 throw한다.
  2. newTarget이 present하지 않으면, newTargettarget으로 설정한다.
  3. Else if IsConstructor(newTarget)가 false이면, TypeError exception을 throw한다.
  4. argList를 ? CreateListFromArrayLike(args)로 둔다.
  5. Construct(target, argList, newTarget)를 반환한다.

28.1.3 Reflect.defineProperty ( target, key, attrs )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. propertyDesc를 ? ToPropertyDescriptor(attrs)로 둔다.
  4. target.[[DefineOwnProperty]](propertyKey, propertyDesc)를 반환한다.

28.1.4 Reflect.deleteProperty ( target, key )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. target.[[Delete]](propertyKey)를 반환한다.

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

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. receiver가 present하지 않으면, 다음을 수행한다.
    1. receivertarget으로 설정한다.
  4. target.[[Get]](propertyKey, receiver)를 반환한다.

28.1.6 Reflect.getOwnPropertyDescriptor ( target, key )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. propertyDesc를 ? target.[[GetOwnProperty]](propertyKey)로 둔다.
  4. FromPropertyDescriptor(propertyDesc)를 반환한다.

28.1.7 Reflect.getPrototypeOf ( target )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. target.[[GetPrototypeOf]]()를 반환한다.

28.1.8 Reflect.has ( target, key )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. target.[[HasProperty]](propertyKey)를 반환한다.

28.1.9 Reflect.isExtensible ( target )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. target.[[IsExtensible]]()를 반환한다.

28.1.10 Reflect.ownKeys ( target )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. keys를 ? target.[[OwnPropertyKeys]]()로 둔다.
  3. CreateArrayFromList(keys)를 반환한다.

28.1.11 Reflect.preventExtensions ( target )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. target.[[PreventExtensions]]()를 반환한다.

28.1.12 Reflect.set ( target, key, value [ , receiver ] )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. propertyKey를 ? ToPropertyKey(key)로 둔다.
  3. receiver가 present하지 않으면, 다음을 수행한다.
    1. receivertarget으로 설정한다.
  4. target.[[Set]](propertyKey, value, receiver)를 반환한다.

28.1.13 Reflect.setPrototypeOf ( target, proto )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. target이 Object가 아니면, TypeError exception을 throw한다.
  2. proto가 Object가 아니고 protonull도 아니면, TypeError exception을 throw한다.
  3. target.[[SetPrototypeOf]](proto)를 반환한다.

28.1.14 Reflect [ %Symbol.toStringTag% ]

%Symbol.toStringTag% property의 initial value는 String value "Reflect"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }를 가집니다.

28.2 Proxy 객체

28.2.1 Proxy Constructor

Proxy constructor는:

  • %Proxy%입니다.
  • global object"Proxy" property의 initial value입니다.
  • constructor로 호출될 때 새 Proxy object를 생성하고 초기화합니다.
  • function으로 호출되도록 intended되지 않았으며 그런 방식으로 호출되면 exception을 throw합니다.

28.2.1.1 Proxy ( target, handler )

이 function은 호출될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. ProxyCreate(target, handler)를 반환한다.

28.2.2 Proxy Constructor의 Properties

Proxy constructor는:

  • value가 %Function.prototype%[[Prototype]] internal slot을 가집니다.
  • Proxy objects는 initialization이 required되는 [[Prototype]] internal slot을 가지지 않으므로 "prototype" property를 가지지 않습니다.
  • 다음 properties를 가집니다:

28.2.2.1 Proxy.revocable ( target, handler )

이 function은 revocable Proxy object를 생성합니다.

호출될 때 다음 steps를 수행합니다:

  1. proxy를 ? ProxyCreate(target, handler)라고 하자.
  2. revokerClosure를 매개변수가 없고 아무것도 캡처하지 않으며 호출될 때 다음 단계를 수행하는 새로운 Abstract Closure라고 하자.
    1. activeFunc활성 함수 객체라고 하자.
    2. revocableProxyactiveFunc.[[RevocableProxy]]라고 하자.
    3. revocableProxynull이면, NormalCompletion(undefined)을 반환한다.
    4. activeFunc.[[RevocableProxy]]null로 설정한다.
    5. Assert: revocableProxyProxy exotic object이다.
    6. revocableProxy.[[ProxyTarget]]null로 설정한다.
    7. revocableProxy.[[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 Module Namespace 객체

Module Namespace Object는 module의 exported bindings에 runtime property-based access를 제공하는 module namespace exotic object입니다. Module Namespace Objects에 대한 constructor function은 없습니다. 대신 그러한 object는 NameSpaceImport를 포함하는 ImportDeclaration에 의해 imported되는 각 module마다 생성됩니다.

10.4.6에 specified된 properties에 더하여, 각 Module Namespace Object는 다음 own property를 가집니다:

28.3.1 %Symbol.toStringTag%

%Symbol.toStringTag% property의 initial value는 String value "Module"입니다.

이 property는 attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }를 가집니다.