fix(node/util): don't invoke Proxy traps in util.inspect (#34373)
Match Node.js's behaviour: when
[`showProxy`](https://nodejs.org/api/util.html#utilinspectobject-options)
is `false` (the default), `util.inspect` (and `Deno.inspect`) now
operate on the proxy target rather than the proxy itself, so proxy traps
(`get`, `has`, `ownKeys`, ...) are never invoked during inspection.
## Before
```js
import util from "node:util";
util.inspect(new Proxy({ x: 1 }, { ownKeys: () => undefined }));
// Uncaught TypeError: CreateListFromArrayLike called on non-object
```
The default-mode path in `formatValue` never unwrapped proxies (the
relevant lines were commented out, and only a handful of type-specific
branches in `formatRaw` consulted `proxyDetails`). The generic-object
path eventually called `Object.keys(proxy)` inside `getKeys`, which
dispatches to the proxy's `ownKeys` trap and throws when that trap
violates the spec invariant.
## After
```js
util.inspect(new Proxy({ x: 1 }, { ownKeys: () => undefined }));
// "{ x: 1 }"
```
In `formatValue`, when `ctx.showProxy` is `false`, we replace `value`
with the proxy's immediate target and null out `proxyDetails`. All the
downstream branches in `formatRaw` (Set/Map/TypedArray/Date/Error/...)
keep working because they already had `proxyDetails === null` fallbacks
that use `value`. This is the same approach Node.js uses
(`getProxyDetails(value, !!showProxy)`).
## Tests
- `tests/unit_node/util_test.ts` — new `[util] inspect on Proxy doesn't
invoke traps` test covering the exact case from #26355 plus a
`get`-throws regression.
- `tests/unit/console_test.ts` — the existing `inspectProxy` test had an
expectation reflecting Deno's pre-fix (non-Node-conforming) behaviour;
updated to expect `{}` (matching Node) and added an issue-specific
assertion.
Fixes #26355.
Closes denoland/orchid#230
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>