Proxy Traps and Reflect Internals
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.
Proxy Trap Interception & Reflect Forwarding
Trace [[Get]] interception, Receiver forwarding, and invariant enforcement.
Engine bypasses standard Inline Cache lookup because receiver is a Proxy exotic object.
proxy.count;- 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.
- Exotic Dispatch: V8 marks the wrapper as a
JSProxy, routing property reads out of Inline Caches into JS trap handlers. - Receiver Preservation: Passing
receivertoReflect.get(target, key, receiver)ensures inherited getters read reactive properties on the proxy, not the raw target. - Invariant Checks: After a trap returns, the engine enforces spec invariants (e.g., a non-writable, non-configurable property cannot report a different value).
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
definePropertywalking with lazyProxytraps.
Production Pitfalls
- Private Field
#xCrash: Calling a method on a proxied class with#privatefields throwsTypeErrorbecause theProxylacks the target's private slot. - Built-in Slot Mismatch:
Map,Set, andDatemethods fail whenthisis aProxyunless bound to the raw target.
- When not to use
Proxy: Never wrap large numerical arrays or 60 fps particle buffers in aProxy; the trap overhead dwarfs the computation.
Connections & Logical Next Steps
Runtime reactive stores intercept property reads and writes via ES6 Proxy get/set traps.
Proxy traps intercept [[Get]] and [[GetPrototypeOf]] before ordinary prototype traversal runs.
Proxy exotic objects bypass V8 Inline Cache fast-paths on every intercepted property access.
Plain objects hit monomorphic Inline Caches via Shapes, whereas Proxy traps intercept lookups and bypass ICs.