Repository navigation
Conversation
An error that JSC raises in a builtin with a source URL (one of the embedder's modules) quotes the wrong source text. Bun prints "undefined is not an object (evaluating 'stream')" where the access that failed is `stream._writableState`. The line and the column of the error are right. FindFirstCallerFrameWithCodeblockFunctor, behind getBytecodeIndex(), takes the code block of the frame it stops at, but leaves the bytecode index at 0 when that code block is a builtin. Upstream never reads that pair: a builtin has no expression info there. Here a builtin with a source URL has expression info in every build (BytecodeGenerator::emitExpressionInfo), and appendSourceToErrorMessage() quotes from it. ExpressionInfo maps an index before the first entry to the first entry, so the text was that of the first expression of the function. With debugger hooks in the bytecode it was the head of the function, as "(near '...')". The functor now takes the index from the frame that gives the code block, so both callers get the index of the frame it stops at. appendSourceToErrorMessage() reads the expression info and the text from that one code block: its text is now that of the expression that failed, as for user code. It still returns early for a private builtin. slow_path_check_tdz gets the same index. A TDZ error raised in the frame the functor stops at now names the binding of the check, where it named the first expression of the function. Its other defects stay: it uses a null code block when the functor finds no frame, it takes the text from its own code block when the functor stops at another frame, and some checks have no expression info of their own.
|
Status: open, waits for review. How I reproduced it (Bun 1.4.3-canary.1+367d939d9, Linux x64): The code at that position is |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Since it changes the text of every engine error raised inside a Bun builtin module (a user-visible message change that downstream tests may match on), a human look at that product decision would still be worthwhile.
What was reviewed:
- The Error.cpp hunk against both consumers: ErrorInstance::finishCreation still returns early for private builtins via isPrivateBuiltinFunction() in appendSourceToErrorMessage(), and slow_path_check_tdz on a code block with no expression info decodes an empty entry exactly as it did at index 0.
- Confirmed BytecodeGenerator::emitExpressionInfo in this fork emits info for non-private builtins in release, so the real index is meaningful; visitor->bytecodeIndex() already maps DFG/FTL frames via code origin, so no per-tier change is needed.
- Checked that builtinFromBytecodeCache() (jsc.cpp) and $vm.createBuiltin() exist in this fork's shell; the new test is fork-only and does not alter an upstream test, so BUN-TEST-DIFFERENCES.md is not required by the stated rule, though an entry would help triage after the next sync.
Extended reasoning...
The change is a five-line C++ hunk in Source/JavaScriptCore/runtime/Error.cpp (FindFirstCallerFrameWithCodeblockFunctor) gated under USE(BUN_JSC_ADDITIONS) with upstream code preserved in #else, plus a new 93-line JSTests/stress test. It touches no security-sensitive surface; it only affects which source range an error message quotes. The logic is correct and consistent with the fork's existing design (expression info for builtins with a source URL, private-builtin exclusion in appendSourceToErrorMessage). Deferring rather than approving because the change alters a large number of user-visible Bun error messages (the author counts 160 of 339), which is a product-level decision, and because .github/CODEOWNERS lists Source/JavaScriptCore and JSTests under a reviewer group.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review. WalkthroughBun builds now record bytecode indices for builtin frames. A new stress test checks error messages for builtins created from source or bytecode cache, including repeated calls, private builtins, and several failing expressions. ChangesBuiltin error source quoting
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No actionable issue is established that would prevent merging after normal checks. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Comment |
|
Preview build of b1aafd7: |
Problem
dgramsocket,s.getSendQueueSize()saysnull is not an object (evaluating 'kStateSymbol')forthis[kStateSymbol].handle.getSendQueueSize(). The position is right.FindFirstCallerFrameWithCodeblockFunctor(runtime/Error.cpp:153), behindgetBytecodeIndex(), returns a builtin's code block with bytecode index 0.appendSourceToErrorMessage()quotes the text at that index: the function's first expression, or its head under a debugger.Fix
USE(BUN_JSC_ADDITIONS)the functor takes the index from the frame that gives the code block.appendSourceToErrorMessage()reads info and text from that one code block, like user code. Private builtins get no text (CI: one workflow, planned lanes, toolchain images, and the JavaScriptCore tests #645).JSTests/stress --quick: no new failure.Background
createBuiltinExecutable. JSC's own have no source URL (private). Bun'snode:*modules have one.Error.stackTraceLimit), and no text for any builtin (appendSourceToErrorMessage: skip builtin code blocks #369, reverses CI: one workflow, planned lanes, toolchain images, and the JavaScriptCore tests #645).Downsides
Notes
Repro.
const s = require("node:dgram").createSocket("udp4"); s.close(); s.getSendQueueSize();on Bun 1.4.3-canary.1. Upstream's two gate lines stay as they are under#else.Supersedes #369. That PR removes the source text for every builtin and gives this gate as its reason. #645 later kept the text for builtins with a source URL and removed it for private builtins only.
Reports with the wrong text. oven-sh/bun#18869 has such a message as its title (
null is not an object (evaluating 'http'), the access that failed isresponse.writeHead). The same function was reported again with other text in oven-sh/bun#39766.More examples on Bun 1.4.3-canary.1 (release)
stream.Readable.prototype.read.call(undefined)(evaluating 'n')this._readableStatestream.Writable.prototype.write.call(undefined, "x")(evaluating 'stream')stream._writableStatefs.WriteStream.prototype._write.call(undefined, Buffer.alloc(1), "utf8", () => {})(evaluating 'kWriteStreamFastPath')this[kWriteStreamFastPath]net.Server.prototype.close.call(undefined)(evaluating 'kClusterListeningId')this[kClusterListeningId]new stream.Readable({ read() {} }).pipe(undefined)(evaluating 'src')dest.onnew http.OutgoingMessage().addTrailers()(evaluating 'this._trailer = ""')ObjectKeys(headers), a host function makes the errornet.Socket.prototype.setTimeout.call(undefined, 1)is right today (this.destroyed), because that access is the first expression of the function.Census. A script calls 744 prototype methods of 33 builtin modules with an undefined receiver. 356 calls end in an engine error whose top frame is a builtin module. 339 messages carry source text: 179 contain the reported column, 160 do not. With
BUN_JSC_forceDebuggerBytecodeGeneration=1(what an attached debugger turns on) every such message quotes the head of its function, thesetTimeoutone included:(near '...function _write(stream, chunk, enco...').Why upstream is not affected. Upstream's
BytecodeGenerator::emitExpressionInforeturns for every builtin, sohasExpressionInfo()is false andappendSourceToErrorMessage()returns first. The gate is from 87b1e4a822c7 (bug 243103). It mirrorsInterpreter::getStackTrace, which gave a builtin frame no bytecode index. This fork already lifted that one underUSE(ALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS)(interpreter/Interpreter.cpp:678), which is why the position is right.ExpressionInfo::Decoder::decodemaps an index before the first entry to the first entry.Proof in a debugger. On a debug Bun,
bytecodeIndexarrives inappendSourceToErrorMessage()as 0 while the frame is at offset 7, 131 and 49 for the first three rows of the table. With the frame's offset written into the argument, the messages arestream._writableState,this._readableStateandthis[kWriteStreamFastPath].The stress test makes builtins with a source URL through the
jscshell'sbuiltinFromBytecodeCache(), from source and from encoded bytecode. It checks two fixed messages through the JIT tiers, that a private builtin keeps no text, and that ten ways to fail give the same message as the same function in user code. On ajscwithout the hunk 7 of the 10 differ. The extradebugger-bytecoderun uses--forceDebuggerBytecodeGeneration=true.Test runs. Release
jsc(-O2,USE_BUN_JSC_ADDITIONS,ALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS), built at 0c06faa with and without the hunk, and again on this branch.JSTests/stress --quickat 0c06faa: 21,898 pass and 13 fail without the hunk (4 are the new test), 21,903 pass and 8 fail with it. The 8 are memory-limit failures of my machine on both builds. No lane runs JSTests with assertions (lanes.mjstests the two Linux lto lanes). Ajscof this branch withENABLE_ASSERTS=ONpasses the new test in all 18 modes. I did not run the rest of JSTests with it.Not run against Bun. No Bun was built with this change. The Bun test below fails on 1.4.3-canary.1 with
'n','stream'and'kWriteStreamFastPath'. Its three expected strings come from the debugger session above. It belongs in the Bun PR that first pins a commit with this change (test/js/bun/jsc/webkit-upgrade-9b02218df6.test.ts, beside the private-builtin case):Cost, measured (release
jsc,--useJIT=0, gdbstepicounts from entry to return)getBytecodeIndex(), user framegetBytecodeIndex(), builtin frameappendSourceToErrorMessage(), user frame, first and later errorappendSourceToErrorMessage(), builtin frame, first and later errorExpressionInfo::Decoder::decodecalls, 4 failing indices in one builtin, then 100 more roundsgetBytecodeIndex/appendSourceToErrorMessage/StackVisitorfor 12 engine errorsnew Errorwith no engine error.textofjscbuiltinBytecodeSize()of the two test sourcesThe functor differs from upstream by +5/-0 lines. Before this change it was identical to upstream main.
What else changes.
slow_path_check_tdz, the other caller, gets the same index. A TDZ error raised in the frame the functor stops at now names the binding of the check (Cannot access 'later' before initialization., it said'callback'). In a build with assertions a private builtin has expression info, and this reader has no private-builtin rule. A TDZ error in a$vm.createBuiltin()function says'later'there now (it said'callback'), and''in a release build as before. No builtin that ships can fail such a check. An error that a host function or a wasm trap makes while a builtin-module frame is the nearest JS frame now quotes the call in that frame.What stays wrong
slow_path_check_tdztakes the name from the expression info at the check.x++beforelet xnames an earlier expression, a class field initializer gives'', and the repro of misleading error message 'Cannot access x before initialization' bun#29514 gives', exists2: '. User code has the same defect, and so does upstream. Error for accessing classes before initialization displays empty name bun#25569 was closed as fixed on 1.4.0 and its repro prints''again on 1.4.3-canary.1.setTimeout(async (cfg = cfg) => { await null }, 0)ends inSegmentation fault at address 0x38on Bun 1.4.2 and 1.4.3-canary.1, and in ajscwith or without this change.getBytecodeIndex()skips the async wrapper (private visibility) and returns no code block, and the reader does not check. With a JS caller the name is the caller's call expression.f.@call(...)andf.@apply(...)inis not a functionmessages, for examplelistener.@call is not a function. (In 'listener.@call(this, args[0])', 'listener.@call' is 5)fromnode:events. That text comes from the Call IC (bytecode/RepatchInlines.h:57), which passes its own index. It is the kind of message appendSourceToErrorMessage: skip builtin code blocks #369 was opened for.bytecompiler/NodesCodegen.cppgive the op no expression info.@arrayPush(c.list, v)withc.listundefined quoted'o'and now quotes'v'.Other open PRs near this code: #642 (wasm trap messages), #721 (
setStackFrames). The code frame that Bun prints above these errors skips a line. That is Bun's printer (oven-sh/bun#38244).