Skip to main content

Module proxy

Module proxy 

Source
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.14 ProxyCreate).
define_property
[[DefineOwnProperty]].
delete
[[Delete]].
get
[[Get]]. Ok(None) → not a proxy; the caller proceeds normally.
get_own_descriptor
[[GetOwnProperty]] — the descriptor object (or undefined).
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.stringify serializes a proxy as. SerializeJSONArray and SerializeJSONObject both 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 the get trap, as the spec’s CreateDataPropertyOrThrow(…, 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 and JSON.stringify all need this shape. 10.5.11 defines it as ownKeys filtered 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) when v is 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.toString and typeof classify by (10.5.x defer those to [[ProxyTarget]], and a proxy of a proxy defers again).