26 Reflection
26.1 The Reflect Object
The Reflect object:
- is the intrinsic object
%Reflect% . - is the initial value of the
"Reflect" property of theglobal object . - is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Object.prototype% . - is not a
function object . - does not have a [[Construct]] internal method; it cannot be used as a
constructor with thenewoperator. - does not have a [[Call]] internal method; it cannot be invoked as a function.
26.1.1 Reflect.apply ( target, thisArgument, argumentsList )
When the apply function is called with arguments target, thisArgument, and argumentsList, the following steps are taken:
- If
IsCallable (target) isfalse , throw aTypeError exception. - Let args be ?
CreateListFromArrayLike (argumentsList). - Perform
PrepareForTailCall (). - Return ?
Call (target, thisArgument, args).
26.1.2 Reflect.construct ( target, argumentsList [ , newTarget ] )
When the construct function is called with arguments target, argumentsList, and newTarget, the following steps are taken:
- If
IsConstructor (target) isfalse , throw aTypeError exception. - If newTarget is not present, set newTarget to target.
- Else if
IsConstructor (newTarget) isfalse , throw aTypeError exception. - Let args be ?
CreateListFromArrayLike (argumentsList). - Return ?
Construct (target, args, newTarget).
26.1.3 Reflect.defineProperty ( target, propertyKey, attributes )
When the defineProperty function is called with arguments target, propertyKey, and attributes, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - Let desc be ?
ToPropertyDescriptor (attributes). - Return ? target.[[DefineOwnProperty]](key, desc).
26.1.4 Reflect.deleteProperty ( target, propertyKey )
When the deleteProperty function is called with arguments target and propertyKey, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - Return ? target.[[Delete]](key).
26.1.5 Reflect.get ( target, propertyKey [ , receiver ] )
When the get function is called with arguments target, propertyKey, and receiver, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - If receiver is not present, then
Set receiver to target.
- Return ? target.[[Get]](key, receiver).
26.1.6 Reflect.getOwnPropertyDescriptor ( target, propertyKey )
When the getOwnPropertyDescriptor function is called with arguments target and propertyKey, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - Let desc be ? target.[[GetOwnProperty]](key).
- Return
FromPropertyDescriptor (desc).
26.1.7 Reflect.getPrototypeOf ( target )
When the getPrototypeOf function is called with argument target, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Return ? target.[[GetPrototypeOf]]().
26.1.8 Reflect.has ( target, propertyKey )
When the has function is called with arguments target and propertyKey, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - Return ? target.[[HasProperty]](key).
26.1.9 Reflect.isExtensible ( target )
When the isExtensible function is called with argument target, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Return ? target.[[IsExtensible]]().
26.1.10 Reflect.ownKeys ( target )
When the ownKeys function is called with argument target, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let keys be ? target.[[OwnPropertyKeys]]().
- Return
CreateArrayFromList (keys).
26.1.11 Reflect.preventExtensions ( target )
When the preventExtensions function is called with argument target, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Return ? target.[[PreventExtensions]]().
26.1.12 Reflect.set ( target, propertyKey, V [ , receiver ] )
When the set function is called with arguments target, V, propertyKey, and receiver, the following steps are taken:
- If
Type (target) is not Object, throw aTypeError exception. - Let key be ?
ToPropertyKey (propertyKey). - If receiver is not present, then
Set receiver to target.
- Return ? target.[[Set]](key, V, receiver).
26.1.13 Reflect.setPrototypeOf ( target, proto )
26.2 Proxy Objects
26.2.1 The Proxy Constructor
The Proxy
- is the intrinsic object
%Proxy% . - is the initial value of the
"Proxy" property of theglobal object . - creates and initializes a new proxy
exotic object when called as aconstructor . - is not intended to be called as a function and will throw an exception when called in that manner.
26.2.1.1 Proxy ( target, handler )
When Proxy is called with arguments target and handler, it performs the following steps:
- If NewTarget is
undefined , throw aTypeError exception. - Return ?
ProxyCreate (target, handler).
26.2.2 Properties of the Proxy Constructor
The Proxy
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - does not have a
"prototype" property because proxy exotic objects do not have a [[Prototype]] internal slot that requires initialization. - has the following properties:
26.2.2.1 Proxy.revocable ( target, handler )
The Proxy.revocable function is used to create a revocable Proxy object. When Proxy.revocable is called with arguments target and handler, the following steps are taken:
- Let p be ?
ProxyCreate (target, handler). - Let steps be the algorithm steps defined in
Proxy Revocation Functions . - Let revoker be !
CreateBuiltinFunction (steps, « [[RevocableProxy]] »). Set revoker.[[RevocableProxy]] to p.- Let result be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (result,"proxy" , p). - Perform !
CreateDataPropertyOrThrow (result,"revoke" , revoker). - Return result.
26.2.2.1.1 Proxy Revocation Functions
A Proxy revocation function is an anonymous built-in function that has the ability to invalidate a specific Proxy object.
Each Proxy revocation function has a [[RevocableProxy]] internal slot.
When a Proxy revocation function is called, the following steps are taken:
- Let F be the
active function object . - Let p be F.[[RevocableProxy]].
- If p is
null , returnundefined . Set F.[[RevocableProxy]] tonull .Assert : p is a Proxy object.Set p.[[ProxyTarget]] tonull .Set p.[[ProxyHandler]] tonull .- Return
undefined .
The
26.3 Module Namespace Objects
A Module Namespace Object is a
In addition to the properties specified in
26.3.1 @@toStringTag
The initial value of the @@toStringTag property is the String value
This property has the attributes { [[Writable]]: