Repository navigation
fix(ext/node): node:repl improvements - #33930
Conversation
7e9aedb to
38036ce
Compare
fibibot
left a comment
There was a problem hiding this comment.
Substance walk on the node:repl improvements + internal/repl polyfill — good shape, addresses several concrete Node-compat gaps. Holding at COMMENT pending the in-progress CI shards (28 still building); an earlier run had 5 node_compat (3/3) debug failures so I want to see how this one lands before APPROVE.
What I verified
internal/repl.ts polyfill — minimal createInternalRepl(env, opts, cb) that honors NODE_NO_READLINE / NODE_REPL_MODE / NODE_REPL_HISTORY_SIZE / NODE_REPL_HISTORY env vars exactly as Node does, sets kStandaloneREPL, and routes through repl.start(opts).setupHistory({...}). The --expose-internals test suite reaches for this, so the polyfill is the right shape. ✓
Stable REPL{n} resource name at polyfills/repl.ts:46-51 — matches Node's per-instance scheme, used as the source filename for compiled scripts so stack-trace assertions in node_compat tests reproduce. ✓
Async-error capture via setUncaughtExceptionCaptureCallback at :53-110 — refcounted via _activeREPLs[], installs on first non-standalone REPL, uninstalls on last. Crucially uses the capture callback (single-slot, JS-invisible) rather than process.on('uncaughtException') so user code reading process.listenerCount('uncaughtException') sees 0 — matches Node's domain-based REPL. The previous-callback save/restore (_prevCaptureCallback) handles the case where another subsystem already had a capture callback installed. Domain integration at _replCaptureCallback:67-78 correctly forwards to repl._domain when listeners exist. ✓
newListener guard at :112-138 — refcounted prepend-listener that throws ERR_INVALID_REPL_INPUT if anything but the REPL's own _replUncaughtHandler tries to listen to uncaughtException. Mirrors Node's user-listener rejection. The function-name check (listener.name !== "_replUncaughtHandler") is the exact gate Node uses. ✓
_shouldColorize at :142-167 — covers FORCE_COLOR (with the Node-20+ behavior of any non-empty/non-"0" value winning over NO_COLOR/NODE_DISABLE_COLORS/TERM=dumb), stream.getColorDepth() > 2, and TTY-without-getColorDepth defaulting to colorful. Each branch matches Node's internal/util/colors.shouldColorize. ✓
filterReplStack at :172-200 — drops ext: and node: polyfill frames, then walks bottom-up to find the last anonymous frame and truncates from there (mirrors Node's overrideStackTrace + ArrayPrototypeFindLastIndex). The bracketed-vs-non-bracketed paren check distinguishes named frames from at FILE:line:col synthetic top-level evals. ✓
_getPropertyNames size guard at :235-250 — skips Object.getOwnPropertyNames(arr) when arr is an Array or ArrayBuffer view with length > 100_000 (would otherwise allocate millions of index strings and trip a v8 internal assertion). Falls back to Object.keys(obj).filter which won't enumerate dense numeric indices. Reasonable threshold; would be worth confirming at exactly length === 100_000 boundary on a real Array(100_000). ✓
testing.ts Node-style (t, done) for nested tests at :392-422 — closes a gap I flagged equivalent to in #33929: wrapTestFn already had this for top-level tests, but TestSuite.addTest was using await prepared.fn(newNodeTextContext) directly without the done-callback shape. The added branch checks prepared.fn.length >= 2 and routes through the same pendingCallbackReject + done(err) machinery. Promise-vs-callback hybrid handling (calling done(undefined) on resolve, testReject(err) on reject) is correct. ✓
The disabled test-esm-repl-imports.js with the comment "previously passed only because the test runner did not await Node-style done callbacks, which masked the failing assertion" is a nice catch — the prior false-positive is now visible thanks to the (t, done) fix above.
CI
57 success | 28 in_progress | 1 skipped (current run)
The ci workflow re-ran at 01:35 (the prior run had 5 node_compat (3/3) debug failures across all platforms; need to see if this run reproduces or clears them). The in-progress shards are mostly the slow node_compat (3/3) + Windows builds.
Substance is APPROVE-quality — will re-confirm with APPROVE once CI lands clean. If the new run still has node_compat failures, I'll post a follow-up with the specific failing test.
Gets 21 additional node:repl tests passing
Gets 21 additional node:repl tests passing