Expand description
Proxy — the ECMAScript exotic object (10.5) whose essential internal
methods are redirected to a handler’s traps.
A Proxy is not a shape node-js could fake with a property map: every one of
its internal methods has to be diverted, so it is its own heap variant
(JsObj::Proxy) and this module is the single place the diversion happens.
The funnels the rest of the runtime already routes through —
builtins::get_property / set_property / has_property /
delete_property / object_keys, host::invoke / construct_nt — each
call into here first; when the handler has no trap for the operation, the
no_trap fallback re-runs the SAME funnel against the target, which is what
makes new Proxy(t, {}) observationally indistinguishable from t.
Not implemented, deliberately, and recorded in BUGS.md rather than faked: the spec’s trap-result invariant checks (10.5.x steps that throw when a trap contradicts a non-configurable/non-extensible target property). node-js reports the trap’s answer as given. Every trap itself is real.
Functions§
- apply
[[Call]].- construct
[[Construct]].- create
new Proxy(target, handler)(10.5.14ProxyCreate).- define_
property [[DefineOwnProperty]].- delete
[[Delete]].- get
[[Get]].Ok(None)→ not a proxy; the caller proceeds normally.- get_
own_ descriptor [[GetOwnProperty]]— the descriptor object (orundefined).- get_
prototype_ of [[GetPrototypeOf]].- has
[[HasProperty]](key in proxy).- is_
extensible [[IsExtensible]].- iterate
[...proxy]/for (… of proxy).Ok(None)→ not a proxy.- json_
snapshot - The plain value
JSON.stringifyserializes a proxy as.SerializeJSONArrayandSerializeJSONObjectboth read every member through[[Get]], so the snapshot is taken through the traps rather than off the target. - key_
value - An internal property key as the JS value a trap receives: the SYMBOL for a
symbol-keyed property (
@@sym:7,@@iterator), a string otherwise. A trap that inspects its key argument must see what the script wrote. - own_
enum_ entries (key, value)for every own enumerable string key — spread /Object.assign/Object.entries/JSON.stringify. Each value is read through thegettrap, as the spec’sCreateDataPropertyOrThrow(…, Get(from, key))requires.- own_
enum_ string_ keys - The own keys of a proxy that are ENUMERABLE string keys —
Object.keys,for-in’s own half, object spread andJSON.stringifyall need this shape. 10.5.11 defines it asownKeysfiltered by each key’s[[GetOwnProperty]], so both traps really do run, in that order. - own_
keys [[OwnPropertyKeys]], as INTERNAL key strings (so a symbol key comes back as@@sym:<id>— the form the rest of the runtime indexes by).- parts
(target, handler)whenvis a Proxy — revoked or not.- prevent_
extensions [[PreventExtensions]].- revocable
Proxy.revocable(target, handler)→{ proxy, revoke }. The revoker is a builtin thunk keyed by the proxy’s heap index, so calling it twice is the no-op the spec asks for rather than a second teardown.- revoke
- Run a
@@prevoke:<idx>thunk: mark the proxy dead so every trap throws. - set
[[Set]].Ok(true)means the write was handled here.- set_
prototype_ of [[SetPrototypeOf]].- ultimate_
target - The proxy chain’s ultimate non-proxy target — what
Array.isArray,Object.prototype.toStringandtypeofclassify by (10.5.x defer those to[[ProxyTarget]], and a proxy of a proxy defers again).