Repository navigation
Conversation
… receiver A setter for the index on the prototype chain of the global object, or on the global object itself, gets globalThis as `this`. A Proxy there gets it as the receiver of its `set` trap. The tests cover node:vm contexts, the main realm, a Worker, a ShadowRealm, napi_set_element and v8::Object::Set, and a matrix of 35 ways to store whose output is compared with Node.js. The two tests named "in every JIT tier" lower the FTL threshold, so that their loops reach the FTL.
|
Status: draft. It waits for oven-sh/WebKit#1049, which CI has built and tested. After that merges, How it was reproduced. The program under "Repro" in the PR body prints CI, build 141327. Every job that ran passed. The changed test files pass on each lane that runs them: Debian and Ubuntu (x64, aarch64, ASAN), Alpine, Windows (x64, aarch64) and macOS aarch64. PR: #48892 |
|
Updated 11:10 PM PT - Nov 13th, 2026
✅ @robobun, your commit 4930eb5bbf3db5feb529a7c97844ea63c8e7afde passed in 🧪 To try this PR locally: bunx bun-pr 48892That installs a local version of the PR into your bun-48892 --bun |
Draft:
WEBKIT_VERSIONis the preview build of oven-sh/WebKit#1049, for CI only. It goes when main's WebKit has the change.Problem
globalThis[0] = vcalls a setter with the wrongthis:undefinedin a strict setter. A Proxy'ssettrap getsundefinedtoo. Node.js passesglobalThis, as Bun does for a name key.main, an index store to a jsdom 27 window fails:TypeError: Proxy object's 'set' trap returned falsy value for property '0'. Bun 1.4.4 stores it. The cause, bun test: Vitest compatibility #44833, is in no release.JSObject::putByIndextakes no receiver and hands theJSGlobalObjectto script.Fix
test/js/node/vm/,test/js/bun/jsc/,test/napi/,test/v8/). All fail with main's WebKit.Background
globalThisis a proxy in front of the global object, which is also the global scope. A callee reads a scope as nothis.node:vm: "Setters and Proxy traps must see globalThis" (src/jsc/bindings/NodeVM.cpp:1162).Downsides
.textgrows by 192 bytes.Object.create(globalThis)[0] = v.Notes
Repro.
Node.js v26.3.0 prints
globalThis of the contexttwice. Bun onmainprints it fornameandundefinedfor0. With this pin Bun prints it twice.jsdom. jsdom 27.0.0 and later, with
runScriptsset, makes its window fromvm.constants.DONT_CONTEXTIFYand puts a Proxy on the window's prototype chain. Thesettrap of that Proxy refuses a receiver that is no object. #44833 put the prototype chain of anode:vmglobal on the global object, where the engine's index store walks it, and corrected the receiver for name keys. jsdom 27.0.0 and 31.0.1 withrunScripts: "dangerously":window[0] = vfrom a modulewindow[2] = vin a sloppy page scriptReflect.set(window, 7, v)truetrueTypeError: Proxy object's 'set' trap returned falsy value for property '0'falsetrueWith jsdom 26.1.0, which makes its window with
vm.createContext(window), all four store. The repository's tests use jsdom 25.0.1, so the test here has a window shaped like that of jsdom 27.The pin.
autobuild-preview-pr-1049-88d4fd5bis WebKit de043228c2 plus oven-sh/WebKit#1049.mainpinned de043228c2 when this branch was cut. Each timemainmoves its pin, this branch conflicts on that one line until the pin here is replaced. After oven-sh/WebKit#1049 merges,WEBKIT_VERSIONhas to name the build of the merge commit. If another PR pins a WebKit with the change first, the line inscripts/build/deps/webkit.tsdrops out of this PR and the tests stay. The fix is in the pinned engine, outsidesrc/: with this branch's pin and thesrc/ofmainthe new tests pass too. They fail onmainas it is.What the tests hold.
vm.test.ts, for aDONT_CONTEXTIFYcontext and for a contextified object: a strict setter and a sloppy setter made in the outer realm and a strict setter made in the context, on the context'sObject.prototype, reached from inside the context (globalThis[0] = v, a string key,Reflect.set,Object.assign, strict code) and from outside. A Proxy on the prototype chain with asettrap, and one without a trap in front of a setter. An index setter that is the global's own (DONT_CONTEXTIFY), and a loop through the JIT tiers.vm.test.tswithvm-global-index-stores-fixture.cjs: 35 ways to store to an index key ofglobalThis(assignment and compound assignment, destructuring,for-ofandfor-intargets,Reflect.setwith four receivers,Object.assign,super[key], eight functions ofArray.prototype,with, global code, a class field,Array.from), each with 4 things in the way (an accessor onObject.prototype, an accessor ofglobalThis, a Proxy with traps, a Proxy without traps in front of an accessor), in the main realm and in aDONT_CONTEXTIFYcontext. The test runs the file with Node.js and with Bun and compares the output. Node.js v22.8.0, v26.3.0 and v26.12.1 print the same 140 lines. Bun 1.4.5-canary.1 differs in 111 of them in each realm.vm-proxy-in-global-prototype.test.ts: index stores on a window shaped like jsdom's land as own properties.index-stores-to-globalthis.test.ts: the main realm, a Worker and a ShadowRealm, also through thetargetof an event onglobalThis.napi.test.tsandv8.test.ts:napi_set_element,napi_set_property,napi_set_named_propertyandv8::Object::Seton the global object, for index 0 and for 4294967295. 4294967295 is no array index: script stores it by name, and onlynapi_set_elementandObject::Set(context, index, value)reach the arm of the engine's index store for it. The output is compared with Node.js.BUN_JSC_thresholdForFTLOptimizeAfterWarmUp=1000. Without it their loops end in the DFG.Counts of the wrong call. gdb breakpoints at the entry of
GetterSetter::callSetterandProxyObject::putByIndexCommon, with the condition thatthisValueis the global object itself, on debug builds running the programs behind these tests (node:vmcontexts, a window shaped like jsdom's, the main realm with a Worker and a ShadowRealm, N-API): 40073 setter calls and 18 Proxy hand-offs onmain, 0 of 40079 setter calls and 0 hand-offs on this branch.Cost. Measured on the
jscof the engine's CI, parent against oven-sh/WebKit#1049,--useJIT=0, user instructions per store of a loop: six kinds of index store that reach no setter (arrays, sparse objects,globalThis, string keys) run the same number of instructions in thelto-aotbuild. A store that calls an index setter runs 10 more (1007 to 1017). One that reaches a Proxy'ssettrap runs 5 more (1180 to 1185). On a global object these are 12 and 9 more..textofjscgrows by 192 bytes on x64 and 256 on arm64. A release Bun was not built for this.Leftovers. This change causes none of them.
x = 1gives a strict setter ofxon the prototype chainundefined. The engine passes the scope as the receiver (put_to_scope). bun test: Vitest compatibility #44833 corrected it fornode:vmcontexts only.Object.create(globalThis)[0] = vdoes not find an index setter that isglobalThis's own: the setter is not called, and the child gets an own property. The engine's walk does not look behind a global's proxy. For aDONT_CONTEXTIFYglobal, Bun 1.4.3 called the setter and Bun 1.4.4 does not. In the main realm it was never called. The remedy is another rule in the engine (where the walk looks), so it is not in [JSC] A store to an index of a global object hands globalThis to a setter and to a Proxy WebKit#1049.node:vmtimeout orworker.terminate()does not stop a script that loops in an index setter that is the object's own (var o = {}; Object.defineProperty(o, 0, { set() { for (;;); } }); o[0] = 1). Node.js throwsERR_SCRIPT_EXECUTION_TIMEOUT. The engine calls that setter insideDeferTerminationForAWhile. An inherited setter is stopped.targetof an event on the global object is the object behindglobalThis(Report globalThis as the target of events dispatched on the global scope #39102). An index store through it now getsglobalThis. A name store through it still getsundefined.globalThisthere is not called (node:vm: put the sandbox in front of global variables the way Node's contextify does #39588, node:vm: make the put and defineOwnProperty hooks of a context ask their own global #48852). As they are written today, both end an index store at the contextified object and do not go on to the engine's store, as the name path does withBase::put. The three tests here for "a contextified object" would then fail (by reading, not run). Node.js v26.3.0 agrees with these tests.Reflect.set(globalThis, 3, v, other)in a contextified context calls no setter, givesotheran own property and writes the contextified object. Node.js calls the setter withother. node:vm: make the put and defineOwnProperty hooks of a context ask their own global #48852 has this."use strict"of a function in a CommonJS file (Strict mode does not work at function-level granularity #14251). Today such a setter is sloppy and seesglobalThisby accident, where it is of the same realm. The tests here make their strict setters withnew Function,evalandnode:vm, which Bun does not transpile.Self-review. Two of its 16 points are not taken.
Object.create(globalThis)[0] = vinto [JSC] A store to an index of a global object hands globalThis to a setter and to a Proxy WebKit#1049: it is another rule of the engine, with its own cost and tests. It is the second leftover above.Local runs. Bun 1.4.5-canary.1+b6e7b9cdc, a release build of
main, fails all 15 new tests.bun bd testof the changed files with this pin:index-stores-to-globalthis.test.ts2 pass.vm-proxy-in-global-prototype.test.ts16 pass, 1 skip.vm.test.ts377 pass and 5 fail: the 5 are time limits of 5 s that a debug build ofmainexceeds too (the four "reads the same in every tier" tests and the test with a 2^27-character string).napi.test.ts225 pass and 1 fail ("should crash on duplicate hooks", a time limit, also onmain). TheObjecttests ofv8.test.ts: 8 pass. The debug profile ofmaincompiles only with two more includes inBunPlugin.cpp(#48722). The build had them. This branch does not.no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/v8/v8.test.ts, test/napi/napi.test.ts, test/js/node/vm/vm.test.ts