28.2 Proxy Objects
28.2.1 The Proxy Constructor
The Proxy
- is %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.
28.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).
28.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:
28.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 length be the number of non-optional parameters of the function definition in
Proxy Revocation Functions . - Let revoker be !
CreateBuiltinFunction (steps, length,"" , « [[RevocableProxy]] »). - Set revoker.[[RevocableProxy]] to p.
- Let result be !
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (result,"proxy" , p). - Perform !
CreateDataPropertyOrThrow (result,"revoke" , revoker). - Return result.
28.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]] to
null . Assert : p is a Proxy object.- Set p.[[ProxyTarget]] to
null . - Set p.[[ProxyHandler]] to
null . - Return
undefined .
The