Repository navigation
node:repl: domain routing, newListener throws, namespace inspect (+4 tests) - #35388
Draft
cirospaciari wants to merge 9 commits into
Draft
cirospaciari wants to merge 9 commits into
cirospaciari wants to merge 9 commits into
Conversation
…ke node
A throwing 'newListener' handler is how node lets code veto a listener
registration: emit('newListener') runs before the listener is stored, and
the throw comes back out of .on(). Bun's native EventEmitter routed the
exception to the 'error' listener / unhandled-error reporter instead, so
the listener was registered anyway and the caller saw nothing. Add an
emit variant that leaves the exception pending and use it for the
newListener emit only.
util.inspect printed ESM namespace objects as
'Module <[Object: null prototype] {}> [Module] { ... }' because Bun hangs
an internal '{ __esModule: true }' object off them for CJS interop and
the constructor walk picks it up. Node prints
'[Module: null prototype] { ... }'.
Adds test-repl-uncaught-exception-async.js and test-repl-import-referrer.js.
node:domain's run() was swallowing synchronous throws and emitting 'error' itself. Node does not: the throw leaves run() with the domain still entered, reaches the fatal-exception handler, and Domain's _errorHandler decides what to do. That difference is observable — the statement after the throwing d.run(...) keeps running under Bun — and it hides the error from anything that inspects process.domain afterwards, which is how node:repl decides whether an eval error belongs to a user domain. Port Domain.prototype._errorHandler, including the nested case where the 'error' handler itself throws and the next domain on the stack gets a turn, and drop the try/catch from run(). Both node:domain and node:repl need to own process's single uncaught-exception capture slot, so the dispatcher node:repl had is now a shared internal module that either can install into. Two more fixes the vendored tests pin: - process.setUncaughtExceptionCaptureCallback was dead under `bun test`; uncaught exceptions went straight to the test reporter. A user callback now gets the exception first, as it does outside the test runner. - Errors from the ported REPL's error-code shims now carry [CODE] in their stack, which is what node prints. Adds test-repl-domain.js and test-repl-user-error-handler.js.
Collaborator
|
Updated 10:21 PM PT - Aug 20th, 2026
⏳ @robobun, your commit 1e4539e is still building in
Add |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
|
Found 2 issues this PR may fix:
🤖 Generated with Claude Code |
oxlint's no-duplicate-conditional-property-access rejects reading stack.length in the condition and again in the body. [allow size]
…into claude/node-repl-v26b # Conflicts: # src/js/internal/repl/node-shims.js
…into claude/node-repl-v26b No-Verification-Needed: automatic base-branch sync merge, no hand-authored changes
…into claude/node-repl-v26b
This was referenced Oct 16, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #34642 — review that first. Base branch:
claude/repl-tab-complete-unary.What this adds
Four more Node v26.3.0 REPL tests, vendored verbatim, plus the runtime fixes they needed:
test/js/node/test/parallel/test-repl-domain.jstest/js/node/test/parallel/test-repl-import-referrer.jstest/js/node/test/parallel/test-repl-uncaught-exception-async.jstest/js/node/test/parallel/test-repl-user-error-handler.jsWhy now
The base stack replaced Bun's REPL stub with Node v26's
lib/repl.js, so what is left in thenode:repltest cluster is not missing REPL code — it is the runtime underneath the REPL behavingdifferently from Node. Each fix below is a general Bun bug that the REPL happens to be the first
caller to notice.
What changed
A throwing
newListenerhandler now aborts the registration (EventEmitter.cpp,EventEmitter.h,JSEventEmitter.cpp). Node emitsnewListenerbefore storing the listener, and athrow from that handler comes back out of
.on()with the listener never added. Bun's nativeEventEmitter routed the exception to the
'error'listener / unhandled-error reporter, so thelistener was added anyway and the caller saw nothing:
emitPropagatingExceptionsleaves the exception pending on the VM instead; only thenewListeneremit inside
addListeneruses it, so every other native emit keeps its current behaviour.node:repluses exactly this mechanism to rejectprocess.on('uncaughtException')typed into aREPL.
util.inspectprints ESM namespace objects like Node (internal/util/inspect.js). Bun hangs aninternal
{ __esModule: true }object off module namespaces for CJS interop, where the spec (andV8) uses a null
[[Prototype]].getConstructorName's prototype walk picked that up, soawait import('./message.mjs')printedModule <[Object: null prototype] {}> [Module] { message: 'A message' }instead of Node's[Module: null prototype] { message: 'A message' }. The interop prototype is an implementationdetail, so namespaces are now treated as having no constructor, matching
getPrefix(null, 'Module', 'Module').node:domainno longer swallows synchronous throws (node/domain.ts).Domain.prototype.runhas notry/catch and does not
exit()on the throwing path: the exception leavesrun()with the domainstill entered, reaches the fatal-exception handler, and
_errorHandlerdecides whathappens. Bun caught it inside
run()and emitted'error'itself, which is observable — thestatement after a throwing
d.run(...)kept executing — and it hides the error from anything thatreads
process.domainafterwards, which is hownode:repldecides whether an eval error belongs toa user domain.
_errorHandleris ported including the nested case where the'error'handleritself throws and the next domain on the stack gets a turn (covered by the already-vendored
test-domain-nested-throw.js).Shared uncaught-exception capture slot (
internal/uncaught_exception_capture.ts).process.setUncaughtExceptionCaptureCallbackis exclusive;node:domainandnode:replboth needit, and upstream relies on an internal stacking variant so they coexist. The dispatcher
node:replalready had is now a small shared internal module both install into. No behaviour change for
node:repl; the code moved.process.setUncaughtExceptionCaptureCallbackworks underbun test(VirtualMachine.rs,BunProcess.cpp).uncaught_exceptionshort-circuited to the test reporter wheneverisBunTestwas set, so a user-installed capture callback was silently dead:
The callback now gets the exception first, exactly as it does outside the test runner. When no
callback is installed — every existing test — the path is unchanged.
REPL error-code stacks carry
[CODE](internal/repl/node-errors.js). Node's stacks readError [ERR_INVALID_STATE]: …; JSC materialises.stackfrom the bare.name. The shim alreadyhad a
decorateNodeErrorStackhelper for some codes; it now applies to all of them, since the REPLprints stacks verbatim.
How this was verified
Every vendored file was run one-process-per-file the way
scripts/runner.node.mjsdoes it(
bun run/bun test+--config=bunfig.node-test.toml,BUN_GARBAGE_COLLECTOR_LEVEL=1,BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1,NO_COLOR=1,FORCE_COLOR=0) against a debug build, andeach is byte-identical to
~/code/node/test/parallel/.test/expectations.txtis untouched.Regression sweep, same harness, 211 files — every vendored
test-repl-*,test-domain*,test-readline*,test-event*andtest-process-*: 209 pass. The two that did not are pre-existingdebug-build timeouts unrelated to this change and pass with a longer deadline
(
test-repl-tab-complete-buffer.jsspends ~31 s per completion of a 1e6-element buffer in a debugbuild;
test-process-exit-code-validation.jstakes ~63 s because it spawns ~30 children).Two caveats worth knowing before merge:
test-repl-domain.jsdoes not fail when athrowis appended to it, i.e. it looks like asilent pass to a canary check. It is not: the test prints
ok, and the appended throw isswallowed by the user domain the test leaves entered. Real
node v26.3.0behaves identically(
ok,ok, exit 0) — Bun now matches it byte for byte, which is the point of the domain change.async: true, handleErrorReturn: badvaluecase intest-repl-user-error-handler.jsspawns achild interpreter, and loading
node:replin a debug build costs ~3.8 s, close tobun test's5 s per-test default. It passed 4 of 5 local runs on a machine at load average 130+. A release
interpreter starts ~25x faster (0.014 s vs 0.36 s for
-e 1), so this should not be marginal inCI — but it is the one file here with a timing dependency.
Still failing in this cluster
16 of the 20
node:replupstream files are not vendored. Grouped by what blocks them:Runtime.evaluatewiththrowOnSideEffect—test-repl-preview.js,test-repl-preview-newlines.js,test-repl-strict-mode-previews.js,test-repl-custom-eval-previews.js,test-repl-mode.js(itstestStrictModeTerminalthird),test-repl-inspector.js. Bun'snode:inspectoranswers everyRuntime.*method withInspector method "Runtime.evaluate" is not supported, which is whyinternal/repl/node-shims.js'ssendInspectorCommandis a stub. Previews evaluate thehalf-typed line on every keystroke, so they are only safe with V8's side-effect-free evaluation;
JSC's inspector protocol has no equivalent flag.
test-repl-inspector.jsadditionally asserts ona
Runtime.evaluateresponse shape.test-repl.jsandtest-repl-pretty-stack.jseach fail on oneline, in opposite directions, because the REPL prefixes
UncaughtvsUncaught:\ndepending onwhether the message fits in
breakLength(80). JSC'sJSON Parse error: Expected '}'is shorterthan V8's
Expected property name or '}' in JSON at position 1 …, and JSC'sUnexpected identifier 'y'. Expected ';' after variable declaration.is one character longer thanthe 80-column budget where V8's
Unexpected identifier 'y'fits.test-repl-unsafe-array-iteration.jsis the same class ({} is not iterablevs[3,2,1] is not iterable), andtest-repl-underscore.jswants V8's receiver-qualified frame nameObject.readdirSync, which JSC does not produce.module.builtinModulescontains Bun's own builtins —test-repl-tab-complete-require.js,test-repl-tab-complete-import.js. Both iteratebuiltinModulesminus_*/node:*and requireeach entry to appear in completions together with
node:<entry>. That would mean offeringnode:bun:ffi,node:undici,node:ws. Passing means droppingbun,bun:*,undiciandwsfrom
module.builtinModules— a user-visible Bun API change that does not belong in a REPL PR.common.hasIntlis false —test-repl-tab-complete.js(27 of 29 subtests pass). It gatesIntlin the expected completion list onprocess.config.variables.v8_enable_i18n_support, whichBun leaves undefined. The base stack has a commit that fixes exactly this key and then reverts it
(
ce31de7797) because flippinghasIntlexposes 11 other vendored tests; that fix is the baseauthor's to land. The other failing subtest needs
Runtime.globalLexicalScopeNames, sameinspector gap as above.
test-repl-require.jswantsUncaught Error: Cannot find module './bar'plusrequireStack: [ '<repl>' ]. Bun throwsResolveMessage(correctcode: 'MODULE_NOT_FOUND', norequireStack) from everyrequire, notjust the REPL's.
fscallbacks that throw do not become uncaught exceptions —test-repl-timeout-throw.js.See below; this one is a general Bun bug, not a REPL one.
Error.prepareStackTraceset outside the REPL context is not applied to REPL errors —test-repl-pretty-custom-stack.js.Cross-cutting bug found, not fixed here
A throw from a
node:fsasync callback bypassesprocess.on('uncaughtException')and takes theprocess down, because
src/js/node/fs.tsdelivers callbacks from a promise continuation(
fs.readFile(...).then(d => callback(null, d), callback)) rather than from a completion hook:Fixing it means changing how every async
node:fsentry point invokes its callback, which is anode:fschange rather than a REPL one.