JS RuntimeBaseline · Widely

Proxy Traps and Reflect Internals

Mental Model

Proxy intercepts ECMAScript's internal operations ([[Get]], [[Set]], [[Apply]]) before ordinary Prototype Chain Lookup runs. Always pair traps with Reflect to preserve receiver binding for getters, while accepting that every trapped read bypasses V8 Inline Caches.

Interactive Simulator

Proxy Trap Interception & Reflect Forwarding

Trace [[Get]] interception, Receiver forwarding, and invariant enforcement.

IC Fast-Path (Skipped)
handler.get()
Target Object
Step 1 / 3: 1. Exotic [[Get]] Dispatch

Engine bypasses standard Inline Cache lookup because receiver is a Proxy exotic object.

proxy.count;
Internal State / Memory
trap
get(target, 'count', receiver)
icBypassed
true

Under the Hood

V8 marks a Proxy as an exotic JSProxy object, routing [[Get]], [[Set]], and [[OwnPropertyKeys]] out of V8 Inline Caches into JS trap functions. Every intercepted read pays trap dispatch and invariant-verification overhead, and forwarding via Reflect preserves the receiver binding for inherited getters.

  1. Exotic Dispatch: V8 marks the wrapper as a JSProxy, routing property reads out of Inline Caches into JS trap handlers.
  2. Receiver Preservation: Passing receiver to Reflect.get(target, key, receiver) ensures inherited getters read reactive properties on the proxy, not the raw target.
  3. Invariant Checks: After a trap returns, the engine enforces spec invariants (e.g., a non-writable, non-configurable property cannot report a different value).
JS
function trackReads(target, onRead) {
  return new Proxy(target, {
    get(obj, key, receiver) {
      onRead(key);
      return Reflect.get(obj, key, receiver);
    },
  });
}

Problem Genealogy

  • 2009 (ES5 Object.defineProperty): Required pre-registering every known key; could not detect new properties or array index writes.
  • 2015 (ES6 Proxy & Reflect): Exposed 13 meta-programming traps covering dynamic keys, in, delete, and function calls.
  • 2020+ (Fine-Grained Reactivity): Vue 3 and Solid stores replaced defineProperty walking with lazy Proxy traps.

Production Pitfalls

Production Pitfall
  • Private Field #x Crash: Calling a method on a proxied class with #private fields throws TypeError because the Proxy lacks the target's private slot.
  • Built-in Slot Mismatch: Map, Set, and Date methods fail when this is a Proxy unless bound to the raw target.
When Not to Use
  • When not to use Proxy: Never wrap large numerical arrays or 60 fps particle buffers in a Proxy; the trap overhead dwarfs the computation.

Connections & Logical Next Steps

Mechanical Comparisons