Files
reverse-engineering-anything/docs/guides
9b3586e933 fix(javascript): keep parameter members a function overwrites unresolved (#9508)
* fix(javascript): keep parameter members a function overwrites unresolved

Wrapper tracing binds a traced function's parameters to the call-site
arguments. JavaScriptSymbolicBindings#identifier returned that bound value
before consulting the binding's recorded member writes, so a member the
function writes, deletes or redefines was still read from the argument. A
wrapper that rewrites def.channel before ipcMain.handle(def.channel, ...)
produced an exact wrapper-substituted channel from the stale argument
member, and a preload wrapper that replaces api.ping before exposing api
produced a call path through the replaced function.

Apply the binding's existing write facts to the bound value per member. A
written member reads as "overwritten object members" wherever the value
flows (aliases, destructuring, spreads, returns, forwarded arguments), and
members() lists it, so spreads and exposed-API inventories do not fall back
to an earlier value. Unwritten members, and loader calls through a
parameter whose properties a module sets, keep their values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(javascript): share parameter member-write views across reads

#withMemberWrites rescanned a binding's writes and copied the bound value
on every read, so W writes and R reads of one parameter did W x R work
outside the symbolic evaluation budget and left R copies in the
evaluation cache.

Collect each binding's written top-level members once, and keep one view
per bound value and binding that every read returns. Building a view is
charged against the evaluation budget before its copies and merged
member sets are allocated, as added conditions already are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): apply rest parameter writes to spread elements

A rest parameter's view recorded its written members, but a call spread
expanded the array's elements unchanged, so a wrapper that rewrites
args[0] before ipcMain.handle(...args) still supplied the caller's
channel. An index read after a written length also returned an element
the write may have removed.

Rewrite the array's elements when building the parameter's view: a
written index becomes unknown, and a written length or an index past the
end leaves one unknown element for the rest, as for any dynamic spread.
Unwritten elements before that point keep their values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(javascript): state how rest parameter writes resolve

The wrapper-substitution passage said that an argument's unwritten members
keep their values. For a rest parameter, a written length leaves every
element unresolved, and an index written past the end leaves the elements
after the known ones unresolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): leave arguments after an unknown-length spread unplaced

arguments() expanded a spread of unknown length as exactly one unknown
element, so the arguments after it kept fixed positions. With
function f(...a){a.length=2; return g(...a, "fallback")}, g's second
parameter read "fallback", although at runtime it is the original second
argument; a helper that picks an argument this way supplied a false
wrapper-substituted IPC channel. The same held for any spread whose value
is not a known array.

Mark the element that stands for an unknown number of further elements
(unknownCount), and stop the argument list after it, so later parameters
read as unknown. A rest parameter bound past that point is the same
open-ended unknown, and a rest array's written length or index past its
known elements produces the marker instead of a fixed-length element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): pass one element of an unknown-length list as one argument

A fixed parameter bound from a spread of unknown length, and an index
read of a rest array whose length the function writes, kept the
unknown-count marker that stands for the rest of a list. Passed on as an
ordinary argument, that one value made the callee's argument list look
open, so a later rest parameter took the marker and a spread of it
dropped the arguments after it. With function first(x){return x} and
function h(x,...rest){return k(...rest,"app:ping")}, h(first(...xs))
lost "app:ping", although rest is always empty there.

A value selected from one position of an argument list or array is now a
plain unknown, so it supplies exactly one argument wherever it goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(javascript): resolve a channel after a rest list left empty by one value

The symbolic tests for one value selected from a list of unknown length
check the resolver, but the loss shows at the wrapper boundary. A rest
parameter that one selected value leaves empty looked open, so a channel
placed after it in a helper call went unresolved and the wrapper's
app:ping registration disappeared.

Add two wrapper rows to electronWrappedCallPaths.test.ts. In the first,
register(first(...extraArguments)) supplies one argument, so the rest
parameter of register is empty and choose(...extra, "app:ping") picks
app:ping. In the second, forward(args[0]) after args.length = 0 supplies
one argument, so choose(...rest, "app:ping") picks app:ping. Node with a
stub electron module registers app:ping in both cases for every
extraArguments list tried ([], ["x"], ["x", "y"]).

Validation: with the source of the previous commit reverted, these two
rows and the two symbolic rows fail (4 of 322 tests in
javascriptSymbolicBindings.test.ts and electronWrappedCallPaths.test.ts,
the app:ping row is missing) and every other test passes. With the source
as committed, all 322 pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* docs(javascript): state that one value read from a list is one argument

The guide says arguments after a spread of unknown length stay
unresolved because their positions are unknown. A reader can take that to
cover a value read from such a list, but a value read from one position of
a spread or of a rest array supplies exactly one argument, so a rest
parameter after it is empty and a channel placed after that rest list
still resolves.

State the rule beside the spread rule it qualifies. The behavior comes
from the selected-element rule of "pass one element of an unknown-length
list as one argument". The symbolic rows of that commit and the wrapper
rows of the test commit after it assert it.

Validation: npx oxfmt --check on the guide passes. node
scripts/check-doc-facts.mjs needs a built dist/ and did not run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(javascript): do not grow a rest array for an out-of-range delete

`function f(...args) { delete args[2]; return pick(...args, "fallback") }`
with two known rest arguments always passes `fallback` third: `delete`
neither creates the element nor changes the length. The written member
set lost the operation, so the index past the end appended an
unknown-count element and the fixed-position argument was dropped.

Only members that a write other than `delete` reaches can now grow the
array. A delete inside the known elements still makes that element
unknown, and a delete plus an assignment of the same index still grows.

Validation: the two delete rows fail on the previous head and pass now;
the delete-then-assign control stays unknown. vitest on
electronWrappedCallPaths.test.ts and javascriptSymbolicBindings.test.ts:
365 passed (365). tsc --noEmit is clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): separate member enumeration from value invalidation

* fix(javascript): preserve rest-array enumeration and snapshot order

* fix(javascript): preserve conditional writes and pre-mutation array membership

* fix(javascript): invalidate added array indices after length writes

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-12-01 00:03:33 +08:00
..