28.2 Proxy Objects

28.2.1 The Proxy Constructor

The Proxy constructor:

  • is %Proxy%.
  • is the initial value of the "Proxy" property of the global object.
  • creates and initializes a new Proxy exotic object when called as a constructor.
  • 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:

  1. If NewTarget is undefined, throw a TypeError exception.
  2. Return ? ProxyCreate(target, handler).

28.2.2 Properties of the Proxy Constructor

The Proxy constructor:

  • 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:

  1. Let p be ? ProxyCreate(target, handler).
  2. Let steps be the algorithm steps defined in Proxy Revocation Functions.
  3. Let length be the number of non-optional parameters of the function definition in Proxy Revocation Functions.
  4. Let revoker be ! CreateBuiltinFunction(steps, length, "", « [[RevocableProxy]] »).
  5. Set revoker.[[RevocableProxy]] to p.
  6. Let result be ! OrdinaryObjectCreate(%Object.prototype%).
  7. Perform ! CreateDataPropertyOrThrow(result, "proxy", p).
  8. Perform ! CreateDataPropertyOrThrow(result, "revoke", revoker).
  9. 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:

  1. Let F be the active function object.
  2. Let p be F.[[RevocableProxy]].
  3. If p is null, return undefined.
  4. Set F.[[RevocableProxy]] to null.
  5. Assert: p is a Proxy object.
  6. Set p.[[ProxyTarget]] to null.
  7. Set p.[[ProxyHandler]] to null.
  8. Return undefined.

The "length" property of a Proxy revocation function is +0𝔽.