Skip to content

Proxy and Reflect — intercepting property access

Level: 301 · for anyone who wants to log, check or fake property access

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.

One line: A Proxy sees only the operations you trap — "a" in p never reaches a get trap, because in is the has trap — and it cannot lie about a frozen target: returning 0 for a frozen answer: 42 throws a TypeError.

Keywords: Proxy, Reflect, Proxy.revocable

What the finished page will answer

  • Which operations does a get trap see: does "a" in p, Object.keys(p) or p.missing go through it?
  • Why does a trap that returns 0 for a frozen answer: 42 throw a TypeError, and which other invariants does the engine check?
  • What does Reflect.get(target, key, receiver) do that target[key] does not, when the target has a getter?
  • Why does Reflect have exactly 13 functions?
  • What does a revoked proxy from Proxy.revocable throw, and can a program tell a proxy from its target?

Examples it will need

  • proxy_and_reflect_trap_log_js.js — a log of which traps fire for a read, in, Object.keys, an assignment and delete on one proxy
  • proxy_and_reflect_invariants_js.js — the TypeError from a get trap that lies about a frozen property, and the error from a revoked proxy

See also

Sources to start from