Repository navigation
Conversation
JSC casts to InternalFieldTuple (since oven-sh/WebKit#410) and to JSWeakSet by the JSType byte of a cell alone, the table in JSCast.h. A cell of another class that has one of those bytes passes for one. ErrorCodeCache and InternalModuleRegistry created their Structures with InternalFieldTupleType, and ActiveSpySet with JSWeakSetType. None of them is the class that owns the type. All three now use ObjectType. bun:sqlite writes the changes of a run() into the InternalFieldTuple it is given. With a handle to the ErrorCodeCache, which an inspector client can get, that write replaced the Structure of ABORT_ERR, and the next AbortError crashed.
|
Status: ready for review. Reproduction: run the two new tests of |
|
Updated 5:47 PM PT - Nov 13th, 2026
✅ @robobun, your commit 397b1b10b84b58c8f9fe385f56b2c166d7d785c6 passed in 🧪 To try this PR locally: bunx bun-pr 48869That installs a local version of the PR into your bun-48869 --bun |
|
No actionable comments were generated in the recent review. WalkthroughThree JSC structure definitions now use ChangesJSC Cell-Type Handling
Suggested reviewers: Merge Risk:
|
There was a problem hiding this comment.
Beyond the inline findings, I also checked for other Bun classes borrowing a JSC built-in JSType: the only remaining TypeInfo(JSFunctionType, ...) sites (src/jsc/bindings/JSFFIFunction.h:73, src/jsc/bindings/napi.h:967, src/jsc/bindings/sqlite/JSSQLStatement.h:73) are all final subclasses of JSC::JSFunction, so they are not the same defect. The two ActiveSpySet users in JSMockFunction.cpp (lines 941 and 1177) use uncheckedDowncast, so the type-byte change does not affect them. Not done here: the claim that JSCast.h casts InternalFieldTuple/JSWeakSet by the JSType byte alone could not be checked against WebKit sources (not vendored in this checkout), and no tests were run.
Extended reasoning...
The change is three one-token JSType edits in createStructure for ErrorCodeCache, InternalModuleRegistry and ActiveSpySet (InternalFieldTupleType/JSWeakSetType to ObjectType) plus two new subprocess tests in bun-jsc.test.ts; it touches no auth, crypto or input-parsing surface, and no CODEOWNERS entry covers the changed files. The two inline findings concern test robustness (a discarded callFunctionOn reply and an unordered Heap.snapshot after inspectee startup), which is why a human look remains worthwhile rather than approving outright.
Findings marked 🟡 are optional suggestions and need no follow-up push.
…hat run() returned The inspector takes commands before the inspectee has run its module. The fixture now waits for a line that the inspectee prints when its setup is done, so the heap snapshot has the ErrorCodeCache and the statement exists. The fixture also reads each reply of Runtime.callFunctionOn and counts the rows that the statement inserted. It passes only if run() returned for both cells.
There was a problem hiding this comment.
I re-reviewed after 397b1b1: both inline points from my earlier pass (asserting that run() actually returned, and ordering the snapshot after the inspectee's setup via a readiness line) are addressed in the current test, and I found no bugs in this version. Because the change alters the JSType of cells that live in every realm (InternalModuleRegistry is read by $getInternalField from every builtin) and leaves an ObjectType cell in vm.weakSetSpace, a human familiar with the JSC side should still take a look.
What was reviewed:
- Searched src/ for any other
Structure::create/createClassStructureusingInternalFieldTupleType,JSWeakSetTypeorJSWeakMapType— none remain; the remainingJSFunctionType/InternalFunctionType/FinalObjectTypesites belong to classes of those bases. - Confirmed nothing in src/ downcasts
ErrorCodeCache/InternalModuleRegistrytoInternalFieldTupleorActiveSpySettoJSWeakSet(allActiveSpySetuses areuncheckedDowncast<ActiveSpySet>), and thatputChangesin JSSQLStatement.cpp:1374 is the write the fixture exercises (fields 0 and 1 = ABORT_ERR / ERR_ACCESS_DENIED in ErrorCode.ts). - Not done here: running the new tests or the mock/sqlite suites, and checking the WebKit side (Heap.cpp's weakSetSpace finalization, JSCast.h table) — the WebKit sources are not in this checkout, so the claim that the collector is unaffected by
ActiveSpySetno longer carryingJSWeakSetTyperests on the PR's own measurements.
Extended reasoning...
The diff changes one token in each of three createStructure calls (src/jsc/bindings/ErrorCode.cpp, InternalModuleRegistry.cpp, JSMockFunction.cpp) from InternalFieldTupleType/JSWeakSetType to ObjectType, plus one explanatory comment, and adds two tests to test/js/bun/jsc/bun-jsc.test.ts: a heap-snapshot plus bun:ffi type-byte scan, and an inspector-protocol fixture that passes the two cells to Statement#native.run(). It touches no injection, auth or data-exposure surface; the bug it fixes is only reachable by an inspector client. The follow-up commit addressed both of my earlier inline findings, there is no CHANGES_REQUESTED review, and the changed paths have no CODEOWNER. Deferring rather than approving because the engine-level consequences (an ObjectType cell in weakSetSpace, DFG speculation on the registry) could not be verified against WebKit sources from this checkout and no tests were run in this review.
Problem
InternalFieldTupleandJSWeakSetby one byte of the cell header, the JSType. Three Bun classes have one of those bytes:ErrorCodeCache(src/jsc/bindings/ErrorCode.cpp:172),InternalModuleRegistry(InternalModuleRegistry.cpp:384),ActiveSpySet(JSMockFunction.cpp:147).stmt.native.run(cache)then writes into theErrorCodeCache, and the nextAbortErroris a SIGSEGV. Debug builds abort atASSERT(canCast == from->JSCell::inheritsSlow(To::info())).Fix
ObjectType. The release binary changes in 7 bytes and no instruction.test/js/bun/jsc/bun-jsc.test.ts. Bun 1.4.2 and a release build of main fail both. Also the mock,bun:sqliteand buffer suites.Background
ErrorCodeCacheholds a realm's Structures for Node error codes.InternalModuleRegistryholds its internal modules.ActiveSpySetholds the mocks thatclearAllMocks()visits.run()into theInternalFieldTupleit is given.Statement#nativeexposes that call.ActiveSpySetstays. This PR changes one token of it.JSC::JSWeakSetfor the mock sets, a debug assert inStructure::validateFlags, and a source lint. Each needs these edits first.Downsides
util.types.isWeakSet()is now false for a handle to anActiveSpySet. Only an inspector client has one.InternalFieldTupletostmt.native.run().Notes
History. oven-sh/WebKit#410 made the cast to
InternalFieldTuplea JSType compare, andInternalFieldTuple.h:14now says that nothing else may create a Structure with that type. Its description left the twoObjectTypelines to the Bun PR that bumped WebKit, which was #37728. Another bump (#38013) moved the pin first, and #37728 closed on inactivity with no review. This PR takes its two hunks unchanged and adds the third class and the tests.Why one token for
ActiveSpySet.getWeakSet(WeakSetPrototype.cpp:63) casts by JSType, so withObjectTypetheWeakSetfunctions refuse the cell. The collector is unaffected: the subspace comes from the C++ type (WeakMapImpl::subspaceFor), andHeap.cppreconciles every cell ofvm.weakSetSpacethroughWeakMapImpl, which the class still is. An earlier cut of this branch replaced the class withJSC::JSWeakSet. That makesWeakSet.prototype.addlegal on the sets, which needs a checked downcast inforEachInand a test for it, and it rewrites the code that #48098 replaces. The storage of the sets is #48098's question (its Question 2).WebKit side (oven-sh/WebKit at the pinned
de043228c294):JSCast.h:123hasJSWeakSetand:149hasInternalFieldTuple.inheritsJSTypeImplcompares the JSType. An assert build also compares theClassInfo.InternalFieldTuple.h:14.WeakSetfunctions cast by JSType:WeakSetPrototype.cpp:63.WeakMapImpl::subspaceForselectsvm.weakSetSpacefrom the C++ type.Heap.cpp:833reconciles each marked cell of that space through astatic_cast(:779) and aWeakMapImplmethod.@getInternalFieldand@putInternalFielddo not read the JSType. The interpreter loads the field (LowLevelInterpreter64.asm:3961) and the DFG usesKnownCellUse(DFGFixupPhase.cpp:2232).ObjectTypemaps toSpecObjectOther(JSType.h:79).InternalFieldTupleTypemaps toSpecCellOther(:168), which does not fit aJSObject.Self-review. Five concerns: use the same token at the third site (done), add a fixture for the crash (done, the second test), the inspector test of the earlier cut could not fail on a release build (dropped with the check it tested), the check covered one of two sites (dropped), and the description (rewritten). Not taken: deleting
static_assert(std::is_final<ActiveSpySet>...). It still holds, and #48098 deletes the class.Measurements (linux x64,
bun run build:releaseat b6e7b9c and at this branch, same machine):bunis 155,269,392 bytes before and after. Every loaded section has the same size (size -A), and no symbol changes size (nm -S). Seven bytes of.textdiffer: the JSType operand inErrorCodeCache::createStructureandInternalModuleRegistry::createStructure(0x66to0x22) and in the initializer ofactiveSpySetStructure(0x5dto0x22), and four__LINE__operands inJSMockFunction.cpp(the added comment line).ErrorCodeCache::createStructureandInternalModuleRegistry::createStructure: 59 instructions and 222 bytes each, before and after.heapStats().objectTypeCountsdelta): +146 cells and +85 Structures, before and after.restoreAllMocks()orclearAllMocks()entry: 0.bun:internal-for-testingentries added: 0. Codegen inputs changed: 0.ErrorCodeCache,InternalModuleRegistryandActiveSpySet. Reverting one token alone brings back exactly its class.ErrorCode.cppfixed it fails with"ffi":"number". On a debug build of main it fails by its timeout: the inspectee needs about 7 s to print the assertion's backtrace and abort.--inspect).The type-byte test. It takes
generateHeapSnapshotForDebugging(), which has each cell's address and class name, and readsJSCell::m_type(offset 5, whichJSCell.hpins with astatic_assert) withbun:ffi. It reads only the cells that the global object references, because those stay alive between the snapshot and the read.The crash fixture. It attaches to a child with
--inspectafter the child prints that its setup is done, takesHeap.snapshot, gets theErrorCodeCacheand theInternalModuleRegistrywithHeap.getRemoteObject, and passes each tostatement.native.run(). It passes only if eachrun()returned and inserted its row.run()writes fields 0 and 1. In the cache those are the Structures ofABORT_ERRandERR_ACCESS_DENIED. In the registry field 1 isbun:ffi, so that half stops testing if a new module sorts beforebun/ffi.ts. The type-byte test still covers the registry then.Suites.
bun bd test(debug+ASAN):bun-jsc.test.ts,mock-fn.test.js,spyMatchers.test.ts,mock-disposable.test.ts: 1054 pass.test/js/bun/test/mock/,sqlite.test.js,vi-utils.test.ts,vitest-flavor.test.ts: 1515 pass and 3 failures that this change does not cause:#13082runs 198 full collections and passes the 5 s timeout, andmacros-beside-tests.test.tsfails twice on debug log lines in the child's stdout. The same files andbuffer.test.json the release build of this branch: 3293 pass, 0 fail. Debug builds of main need the include from #48722 to compile. I applied it locally and it is not part of this PR.Left for later. A debug assert in
Structure::validateFlagsthat JSType andClassInfoagree with theJSCast.htable would catch a fourth class at creation. It needs a WebKit PR and can land only after this one, because every realm creates the registry's Structure.JSType.hmapsInternalFieldTupleTypetoSpecCellOtheralthough the class is aJSObject.no test proof · iteration 1 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/jsc/bun-jsc.test.ts