fix(node/repl): gate preview through V8 inspector throwOnSideEffect (#34566)
## Summary
- Plumbs a private V8 inspector session into `node:repl`'s inline
preview so the re-evaluation goes through `Runtime.evaluate({
throwOnSideEffect: true })` -- matching Node's
`lib/internal/repl/utils.js`. Typing the closing paren of
`console.log("hi")` no longer prints "hi" before Enter (#34360).
- The inspector is used purely as a side-effect *oracle*. If the probe
passes, the value is still rendered via `vm.Script` so `util.inspect`
sees the real JS object (prototype, getters, class info) rather than the
CDP wire shape. If the probe trips on a side effect / syntax / reference
error, the preview is silently skipped -- nothing executes.
- Re-enables preview for custom-eval REPLs: `preview: true` no longer
gets silently dropped when a consumer (e.g. `@babel/node`) passes an
`eval` option. The default for `preview` now matches Node: off when a
custom `eval` is supplied, on otherwise.
- Re-enables the upstream `parallel/test-repl-custom-eval-previews.js`
node-compat test.
Follow-up to #34498 / #34360.
## Implementation notes
- New op `op_node_repl_inspector_connect` mirrors `op_inspector_connect`
but skips the `--allow-sys=inspector` permission check. It's for
internal REPL preview use only; the session can only inspect the current
runtime, which user code can already do via other JS APIs.
- The polyfill bit lives in `ext/node/polyfills/_repl_preview.js`
(IIFE-loaded) because ES-module polyfills only see the
post-`removeImportedOps` view of `core.ops`, which doesn't include the
deno_node ops.
- Inspector messages are processed synchronously via a raw callback on
`op_node_repl_inspector_connect`, so `Runtime.enable` (which replays
`executionContextCreated` for the main realm) and `Runtime.evaluate`
(which returns the response synchronously for non-promise expressions)
both complete inline. The preview path stays keystroke-fast.
## Test plan
- [x] `cargo test --test node_compat -- test-repl-preview` -- 4 tests
pass (`test-repl-preview`, `test-repl-preview-timeout`,
`test-repl-preview-without-inspector`, `test-repl-preview-newlines`).
- [x] `cargo test --test node_compat -- test-repl-custom-eval` -- 2
tests pass (including the re-enabled
`test-repl-custom-eval-previews.js`).
- [x] `deno test tests/unit_node/repl_test.ts` -- 4 tests pass.
- [x] Full node_compat suite: 3642/3653 passed -- the 11 failures are
preexisting flakes in cluster/http/dgram tests, none REPL-related.
- [x] `./tools/lint.js` passes.
Closes denoland/orchid#331
Fixes https://github.com/denoland/deno/issues/34522
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com> E
em committed
847e6a94aa700277e09f23e881650874f56a62c2
Parent: fb5ad03
Committed by GitHub <noreply@github.com>
on 5/31/2026, 5:12:47 AM