You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JSC] OrdinarySet calls a CustomValue setter only for a receiver that holds the property - #993
Reworked at 68490ed. Earlier reviews and preview builds are of the first version.
Problem
A store can call a CustomValue setter with an object that does not hold the property. No user reported this.
definePropertyOnReceiverSlow (runtime/JSObject.cpp:876) asks the receiver for its own property and calls that slot's setter with the receiver. Bun's node:vm global answers with the slot of its contextified object.
In Bun, Reflect.set({}, "require", f, g) loses f if g is the global of vm.createContext(Module.prototype). With Error, which Node.js refuses, prepareStackTrace aborts: ASSERTION FAILED: !source || is<Target>(*source) in Zig::errorConstructorPrepareStackTraceSetter.
Fix
The arm calls the setter only if slot.slotBase() is the receiver. Every other receiver gets [[DefineOwnProperty]], as a Proxy does since 23777f3.
Verified: JSTests/stress/reflect-set-receiver-custom-value-of-another-object.js, which aborts the parent's jsc.
Background
A CustomValue is a data property that native code keeps. Its setter takes a realm and the holder: the object that has the property.
OrdinarySet step 3 defines the property on the receiver when nothing on the chain takes the store.
Considered: pass slot.slotBase() to the setter (the first version: it skips a defineProperty trap), or hide the setter in the slot that Bun's node:vm global forwards (1 of 3 such receivers).
Downsides
A $vm.createImpureGetter(delegate) receiver takes an own property, and the delegate's setter no longer runs.
Release x64: a store whose receiver holds the CustomValue reaches the setter in 203 instructions, not 201. The function grows from 709 to 726 bytes.
Notes
What changed since the first version. The first version gave the setter slot.slotBase() and its realm. #1015 then brought upstream 23777f3, which sends a Proxy receiver to [[DefineOwnProperty]], and the fork's rule that a definition of a value calls the setter of a custom value (A11 in JSTests/BUN-TEST-DIFFERENCES.md). So the Proxy receivers are right on main. What is left is a receiver that is no Proxy and answers with the slot of another object. This version sends it the same way. The branch is on main (de04322).
Receivers that answer with the slot of another object. There are three. NodeVMGlobalObject::getOwnPropertySlot in Bun, for every internal method type but Get. DebuggerScope::getOwnPropertySlot, which an inspector can reach. $vm.createImpureGetter(delegate) in the jsc shell. A script in Bun reaches the call only through the first. A JSGlobalProxy is not one here, because receiverForDefinePropertyOnReceiver takes its target first.
What the setters did with the receiver. Bun has 7 CustomValue properties with a setter.
Error.prepareStackTrace: the setter casts the realm to Zig::GlobalObject without a check. The realm was the NodeVMGlobalObject. This is the assertion above. A release build has no check. In a release build of oven-sh/bun 7aebd750bc the field is at offset 6,672 of Zig::GlobalObject, and a NodeVMGlobalObject has 4,088 bytes, so the store is out of bounds. On release 1.4.3-canary.1+367d939d9, 1 to 20,000 such stores printed the default stack and exited 0.
Module.prototype.require: the setter keeps the override on the realm. The override went to the global object of the context, and require() of the main realm did not call it. Node.js v26.3.0 calls it. This is the case with input that Node.js accepts.
prototype of a bun:test mock and exports of a compiled module: the setters check thisValue and refused the store.
The two shapes that were not taken.
Pass slot.slotBase() and its realm to the setter. The store then never reaches the receiver's [[DefineOwnProperty]]. With a Proxy that has a defineProperty trap as the contextified object, Node.js v26.3.0 runs the trap once. So does this version. That shape runs no trap.
In Bun only: after NodeVMGlobalObject::getOwnPropertySlot forwards the lookup, take the setter out of a CustomValue slot. The store then also ends in the definition. It was not built. It changes one of the three receivers, so DebuggerScope and the test object still reach the call, and it gives out a slot without a setter that the property has. It adds a test and a branch to every lookup that the contextified object answers. The operand here runs only on the slow path of a store, and only for a CustomValue.
Tests run. A debug and ASAN jsc built from b553971 aborts in the new test, and so does a release jsc:
With the change the test passes in the default mode, with --useJIT=0, --useLLInt=0, --useFTLJIT=0, with --collectContinuously=1 --useConcurrentJIT=0, and with low tier-up thresholds. On a release jsc the slowest of these takes 180 ms. 82 related tests pass in the default mode: the files of JSTests/stress that use $vm.createCustomTestGetterSetter, $vm.createStaticCustomValue, $vm.createImpureGetter, $vm.makePropertiesImmutable, $vm.createGlobalProxy or Reflect.set(.
Where the numbers come from. I built and measured on b553971, which was main at that time, with oven-sh/bun 7aebd750bc. runtime/JSObject.cpp and tools/JSDollarVM.cpp are the same files on de04322. "Parent" below is b553971.
Bun with this change.oven-sh/bun#48840 is the Bun half: it pins the preview build of this PR and has the tests. On a debug build of it against 68490ed, test/js/node/vm/ has 427 passes and no failure, and the 98 test-vm-*.js files of Node's suite pass. capture-stack-trace.test.js, node-module-module.test.js, web-globals.test.js, webkit-upgrade-8156ba68ef.test.ts, mock-fn.test.js and worker.test.ts pass.
Cost, measured.
Release x64 jsc, with the change against the parent. nm -S: definePropertyOnReceiverSlow is 709 bytes before and 726 after. objdump -d: the difference is one cmp and one jne. The .text of jsc is 37,657,804 bytes before and after.
gdb, instructions from the 30th entry into the function to the entry into the setter, for Reflect.set({}, "customValue2", i, target) with the custom value on target: 201 before, 203 after.
Release Bun (LTO off) linked against both: the .text is 119,191,104 bytes before and after.
Debug Bun, gdb hit counts. definePropertyOnReceiverSlow is entered 0 times on main and 0 times with the change in each of these four runs: hello world, 1,000 requests to Bun.serve, a bun test file, and 30,000 direct stores to Error.prepareStackTrace, Module.prototype.require and onmessage.
The changed path, 200 stores of require through a node:vm global (100 new values, 100 repeats). Calls of NodeVMGlobalObject::defineOwnProperty, validateAndApplyPropertyDescriptor, the getter and the setter: 200, 253, 202 and 100 with the change, 0, 53, 2 and 200 on main. A store that repeats the value defines nothing, so it calls no setter.
Objects kept after 100,000 such stores and a full GC: 4 with the change, 2 on main. After 1,000 first stores to prototype of a fresh mock, one context each: 1,004 and 1,002.
Node.js parity. 100 probe stores with a node:vm global in the path (entry form, receiver chain, state of the holder), one process each, compared with Node.js v26.3.0 by output and exit code: 69 are equal with the change, 32 on main. Of the 31 that still differ, 21 print the same on main. 6 differ for a reason that a plain data property shows too: NodeVMGlobalObject::put also stores on the sandbox of a target that is a context global, vm.runInNewContext() makes a second context for an object that has one, and a refusing defineProperty trap makes the store answer false. 4 were equal on main only because the write was lost there: 3 stores through 3 or more nested contexts, which Node.js does not pass on, and 1 strict store with a refusing trap. A defineProperty trap of a Proxy as the contextified object runs once in Node.js, once with the change, and not at all on main.
Not changed.
NodeVMGlobalObject::defineOwnProperty asks the calling realm, not the context, whether the name is a global that is read-only and not configurable (src/jsc/bindings/NodeVM.cpp:1336). A store through a context global now takes that path, so such a global in the calling realm makes the store answer true and install nothing. Node.js asks the context. That line is a fix for Bun.
A custom value of a static table that is not reified, behind such a receiver: the definition replaces it. Only $vm has one.
Upstream WebKit has the same call. Only DebuggerScope and $vm objects reach it there.
No actionable comments were generated in the recent review.
Walkthrough
The runtime now calls a custom-value setter only when the original receiver is not a proxy and the property slot is held by the resolved receiver. Added stress-test cases and test-difference documentation describe behavior for other-holder and same-holder receivers.
definePropertyOnReceiverSlow now checks that the slot holder is the resolved receiver before calling a custom-value setter. If the original receiver is a proxy or the holder differs, processing continues to the existing property-definition path.
Receiver behavior tests and documentation JSTests/stress/reflect-set-receiver-custom-value-of-another-object.js, JSTests/BUN-TEST-DIFFERENCES.md
The stress test covers stores when another object holds the custom value, when the receiver holds it, and related static-table, proxy-chain, and plain-value cases. The documentation describes the other-holder behavior.
Suggested reviewers: jarred-sumner
Merge Risk: Minimal · up to 68490
This change makes a native custom-value setter receive the object that holds the property instead of a receiver that does not, which fixes a reported abort. Proxy receivers no longer use the setter shortcut. No concrete merge-blocking risk remains.
Pre-merge checks: 3 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Description check
The description is detailed and follows the WebKit intent of explaining the problem, fix, and tests. It is not a bug-tracker template, though. It has no Bugzilla link, no bug title, no 'Reviewed by' l…
Reformat the description to the repository template. Add the Bugzilla bug title and the https://bugs.webkit.org/show_bug.cgi?id=##### link. Add the 'Reviewed by' line. Keep the explanation of the fix. Add the changed-file list with the func…
Passed checks: 3 passed
Check name
Status
Explanation
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Title check
The title names the main change: OrdinarySet calls a CustomValue setter only when the receiver holds the property. The raw summary confirms that definePropertyOnReceiverSlow now invokes the setter onl…
Full details: Title check
Explanation
The title names the main change: OrdinarySet calls a CustomValue setter only when the receiver holds the property. The raw summary confirms that definePropertyOnReceiverSlow now invokes the setter only when slot.slotBase() is the resolved receiver, and the other changes (test and documentation) support this fix. The title is specific and accurate, though it is long (88 characters).
Full details: Description check
Explanation
The description is detailed and follows the WebKit intent of explaining the problem, fix, and tests. It is not a bug-tracker template, though. It has no Bugzilla link, no bug title, no 'Reviewed by' line, and no ChangeLog-style file list (path/changed.ext with function names). The bug-filing requirement is unmet, and the commit-message format is missing. Explanation of the fix is substantial and clear, so the author content is largely complete in substance, but the required template structure is not followed.
Resolution
Reformat the description to the repository template. Add the Bugzilla bug title and the https://bugs.webkit.org/show_bug.cgi?id=##### link. Add the 'Reviewed by' line. Keep the explanation of the fix. Add the changed-file list with the function names changed (for example runtime/JSObject.cpp: (JSC::definePropertyOnReceiverSlow)) and the test file. Mention the bug on Bugzilla as the template requires.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
Clang (23.1.4)
Source/JavaScriptCore/runtime/JSObject.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: clang-tidy Source/JavaScriptCore/runtime/JSObject.cpp -- -std=c++17 -I./Source -I./Tools -I./macos-cross -I./PerformanceTests -I./WebKitLibraries -I./Websites -I./Source/JavaScriptCore/runtime -I./Source/WTF/wtf -I./Source/WebCore/dom -I./Source/WebKit/UIProcess/API/Cocoa -I./Source/bmalloc/libpas/src/libpas -I./Source/WebCore/platform/graphics -I./Source/WebCore/page -I./Source/WebCore/html -I./Source/WebCore/platform -I./Source/WebKitLegacy/mac/DOM -I./Source/ThirdParty/skia/src/core -I./Source/WebKit/Shared -I./Source/WTF/icu/unicode -I./Source/WebCore/rendering -I./Source/JavaScriptCore/b3 -I./Source/JavaScriptCore/dfg -I./Source/WebCore/css -I./Source/WebCore/Modules/WebGPU -I./Source/JavaScriptCore/bytecode -I./Source/JavaScriptCore/heap -I./Source/WebCore/svg -I./Source/WebCore/bindings/js -I./Source/WebKit/UIProcess -I./Source/WebCore/html/canvas -I./Source/WebCore/loader -I./Source/ThirdParty/ANGLE/src/libANGLE -I./Source/JavaScriptCore/aot/runtime -I./Source/JavaScriptCore/b3/air -I./Source/WebCore/Modules/mediastream -I./Source/WebCore/Modules/webaudio -I./Source/WebCore/editing -I./Source/ThirdParty/skia/include/core -I./Source/WebCore/Modules/webxr -I./Source/WebCore/css/parser -I./Source/WebCore/style -I./Source/WebKit/UIProcess/API/C -I./Source/JavaScriptCore/jit -I./Source/WebKit/Shared/Cocoa -I./Source/WebKitLegacy/mac/WebView -I./Source/JavaScriptCore/aot/codegen -I./Source/WebKit/UIProcess/API -I./Source/WebKit/UIProcess/API/glib -I./Source/JavaScriptCore/wasm -I./Source/WebGPU/WGSL/AST
parser at end of file
ASTMatcher: Matching 'bugprone-pointer-arithmetic-on-polymorphic-object' against:
BinaryOperator : <./Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h:252:16, col:30>
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
I reviewed this PR and didn't find any bugs. Because it changes what a native CustomValue setter is handed on the OrdinarySet step-3 path in core JSC object-model code (and knowingly changes behavior for setters that check their this value), a human look from a JSC reviewer would still be worthwhile.
What was reviewed:
slot.slotBase() as the holder: the slot comes from the receiver's own getOwnPropertySlot, and every setCustom/setCacheableCustom path asserts a non-null slot base, so it is the receiver for ordinary objects and the forwarded-to object only for Proxy-without-trap / embedder forwarders; it now matches what putInlineSlow passes (obj, obj->realm()).
The new holder immutability guard: when the holder's property is immutable it falls through to the receiver's [[DefineOwnProperty]], which for a trapless Proxy reaches the target and refuses; the test's last block exercises this for sloppy, strict and Reflect.set.
The $vm helpers the test relies on (createCustomTestGetterSetter, createGlobalObject, makePropertiesImmutable) exist in JSDollarVM.cpp, and customSetValue2/customSetValueGlobalObject store value2 on the given object and record globalObject->globalThis() in result.result, as the test assumes.
Extended reasoning...
The change is a single commit touching Source/JavaScriptCore/runtime/JSObject.cpp (the CustomValue arm of definePropertyOnReceiverSlow, +5/-3) and adding one stress test, JSTests/stress/custom-value-put-through-proxy.js. It touches no auth, crypto or injection surface, but it does change which object and realm native setters receive on a core property-store path, which is memory-safety relevant for embedder setters that downcast their arguments. The code reads as consistent with the other CustomValue call sites and the test matches the $vm helper semantics. Both changed paths fall under the CODEOWNERS entries for Source/JavaScriptCore and JSTests, and the PR itself documents an intentional behavior change for setters that inspect their this value, so a human reviewer should weigh that rather than this being auto-approved.
JavaScriptCore calls a native setter with the receiver of the store and
the receiver's realm when the receiver answers for the properties of
another object: the global of a node:vm context, or a Proxy made in a
context. oven-sh/WebKit#993 makes it pass the object that holds the
property and that object's realm.
The tests are marked until Bun pins a WebKit with that change.
- test.failing: Module.prototype.require (the override stays on the
global of the context), prototype of a mock (the setter refuses the
store), onmessage and onerror of a ShadowRealm (the handlers go to
the main realm).
- test.todo: Error.prepareStackTrace. Its setter writes out of bounds,
so these stores do not run as expected failures.
… holds the property
definePropertyOnReceiverSlow asks the receiver for its own property. For a
custom value with a setter it calls the setter with the receiver and the
receiver's realm. A receiver can answer with the slot of another object: the
global object of a node:vm context in Bun does so for its contextified
object, and $vm.createImpureGetter() does so for its delegate. The setter
then gets an object that does not hold the property.
The arm now takes the setter only if slot.slotBase() is the receiver. Every
other receiver gets [[DefineOwnProperty]], as a Proxy receiver does since
324876@main. In Bun the global object of a context hands that definition to
its contextified object, and there the definition calls the setter with the
holder and in the holder's realm.
robobun
changed the title
[JSC] OrdinarySet calls a CustomValue setter with the holder and its realm, not with the receiver
[JSC] OrdinarySet calls a CustomValue setter only for a receiver that holds the property
Nov 13, 2026
robobun
added a commit
to oven-sh/bun
that referenced
this pull request
Nov 13, 2026
The stores whose receiver is the global of a node:vm context need a change
to the engine (oven-sh/WebKit#993). Their tests go with the change that
pins it, where they run without marks.
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the new revision (the slot.slotBase() == receiver narrowing and the replacement test) and found no bugs; since this changes OrdinarySet step 3 semantics in a CODEOWNERS-covered path, a human look from a JSC reviewer is still worthwhile.
What was reviewed:
The new condition in definePropertyOnReceiverSlow: slotBase() is only read after the CustomValue check, so the slot is populated; the immutable-property check now consistently refers to the holder since holder == receiver on that arm.
A JSGlobalProxy receiver is unwrapped to the global object before the own-property lookup, so global-object custom values (e.g. onmessage) still have slotBase() == receiver and keep reaching their setter.
The test's expectations against the $vm helpers: createImpureGetter forwards the delegate's slot, and testStaticValuePutterSetFlag flags the object it is handed, so the "flag on the holder stays undefined" assertions match the new behavior.
Not done in this review: the new stress test was not executed in any jsc configuration (no build or test run here).
Extended reasoning...
The range is a single commit touching three files: a one-condition change in Source/JavaScriptCore/runtime/JSObject.cpp (definePropertyOnReceiverSlow now calls a CustomValue setter only when slot.slotBase() is the receiver, so a receiver that forwards another object's slot falls through to [[DefineOwnProperty]] instead of invoking the holder's native setter with the wrong object), a new JSTests/stress test, and a doc entry in JSTests/BUN-TEST-DIFFERENCES.md. It touches no injection, auth, or data-exposure surface, but it does alter core [[Set]] semantics and removes a path that could call a native setter with a non-holder object (memory-safety relevant in Bun's embedding). The diff is small and the logic checks out by reading, but both changed paths are covered by @ WebKit/jsc-reviewers in .github/CODEOWNERS, and the test could not be run in this review, which is why this is a defer rather than an approve.
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
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.
Reworked at 68490ed. Earlier reviews and preview builds are of the first version.
Problem
CustomValuesetter with an object that does not hold the property. No user reported this.definePropertyOnReceiverSlow(runtime/JSObject.cpp:876) asks the receiver for its own property and calls that slot's setter with the receiver. Bun'snode:vmglobal answers with the slot of its contextified object.Reflect.set({}, "require", f, g)losesfifgis the global ofvm.createContext(Module.prototype). WithError, which Node.js refuses,prepareStackTraceaborts:ASSERTION FAILED: !source || is<Target>(*source)inZig::errorConstructorPrepareStackTraceSetter.Fix
slot.slotBase()is the receiver. Every other receiver gets[[DefineOwnProperty]], as a Proxy does since 23777f3.node:vmglobal hands that definition to its contextified object, where the setter gets the holder and its realm (Upgrade to upstream WebKit 8156ba68efab #1015).JSTests/stress/reflect-set-receiver-custom-value-of-another-object.js, which aborts the parent'sjsc.Background
CustomValueis a data property that native code keeps. Its setter takes a realm and the holder: the object that has the property.slot.slotBase()to the setter (the first version: it skips adefinePropertytrap), or hide the setter in the slot that Bun'snode:vmglobal forwards (1 of 3 such receivers).Downsides
$vm.createImpureGetter(delegate)receiver takes an own property, and the delegate's setter no longer runs.CustomValuereaches the setter in 203 instructions, not 201. The function grows from 709 to 726 bytes.Notes
What changed since the first version. The first version gave the setter
slot.slotBase()and its realm. #1015 then brought upstream 23777f3, which sends a Proxy receiver to[[DefineOwnProperty]], and the fork's rule that a definition of a value calls the setter of a custom value (A11 inJSTests/BUN-TEST-DIFFERENCES.md). So the Proxy receivers are right onmain. What is left is a receiver that is no Proxy and answers with the slot of another object. This version sends it the same way. The branch is onmain(de04322).Receivers that answer with the slot of another object. There are three.
NodeVMGlobalObject::getOwnPropertySlotin Bun, for every internal method type butGet.DebuggerScope::getOwnPropertySlot, which an inspector can reach.$vm.createImpureGetter(delegate)in thejscshell. A script in Bun reaches the call only through the first. AJSGlobalProxyis not one here, becausereceiverForDefinePropertyOnReceivertakes its target first.What the setters did with the receiver. Bun has 7
CustomValueproperties with a setter.Error.prepareStackTrace: the setter casts the realm toZig::GlobalObjectwithout a check. The realm was theNodeVMGlobalObject. This is the assertion above. A release build has no check. In a release build of oven-sh/bun 7aebd750bc the field is at offset 6,672 ofZig::GlobalObject, and aNodeVMGlobalObjecthas 4,088 bytes, so the store is out of bounds. On release 1.4.3-canary.1+367d939d9, 1 to 20,000 such stores printed the default stack and exited 0.Module.prototype.require: the setter keeps the override on the realm. The override went to the global object of the context, andrequire()of the main realm did not call it. Node.js v26.3.0 calls it. This is the case with input that Node.js accepts.globalThis.onmessageandonerror: Fix type confusion assigning onmessage/onerror through a Proxy of globalThis bun#37053 added a checked cast that falls back to the global object of the main realm. For a store in a ShadowRealm that is the wrong realm.prototypeof abun:testmock andexportsof a compiled module: the setters checkthisValueand refused the store.The two shapes that were not taken.
slot.slotBase()and its realm to the setter. The store then never reaches the receiver's[[DefineOwnProperty]]. With a Proxy that has adefinePropertytrap as the contextified object, Node.js v26.3.0 runs the trap once. So does this version. That shape runs no trap.NodeVMGlobalObject::getOwnPropertySlotforwards the lookup, take the setter out of aCustomValueslot. The store then also ends in the definition. It was not built. It changes one of the three receivers, soDebuggerScopeand the test object still reach the call, and it gives out a slot without a setter that the property has. It adds a test and a branch to every lookup that the contextified object answers. The operand here runs only on the slow path of a store, and only for aCustomValue.Tests run. A debug and ASAN
jscbuilt from b553971 aborts in the new test, and so does a releasejsc:With the change the test passes in the default mode, with
--useJIT=0,--useLLInt=0,--useFTLJIT=0, with--collectContinuously=1 --useConcurrentJIT=0, and with low tier-up thresholds. On a releasejscthe slowest of these takes 180 ms. 82 related tests pass in the default mode: the files ofJSTests/stressthat use$vm.createCustomTestGetterSetter,$vm.createStaticCustomValue,$vm.createImpureGetter,$vm.makePropertiesImmutable,$vm.createGlobalProxyorReflect.set(.Where the numbers come from. I built and measured on b553971, which was
mainat that time, with oven-sh/bun 7aebd750bc.runtime/JSObject.cppandtools/JSDollarVM.cppare the same files on de04322. "Parent" below is b553971.Bun with this change. oven-sh/bun#48840 is the Bun half: it pins the preview build of this PR and has the tests. On a debug build of it against 68490ed,
test/js/node/vm/has 427 passes and no failure, and the 98test-vm-*.jsfiles of Node's suite pass.capture-stack-trace.test.js,node-module-module.test.js,web-globals.test.js,webkit-upgrade-8156ba68ef.test.ts,mock-fn.test.jsandworker.test.tspass.Cost, measured.
jsc, with the change against the parent.nm -S:definePropertyOnReceiverSlowis 709 bytes before and 726 after.objdump -d: the difference is onecmpand onejne. The.textofjscis 37,657,804 bytes before and after.gdb, instructions from the 30th entry into the function to the entry into the setter, forReflect.set({}, "customValue2", i, target)with the custom value ontarget: 201 before, 203 after..textis 119,191,104 bytes before and after.gdbhit counts.definePropertyOnReceiverSlowis entered 0 times onmainand 0 times with the change in each of these four runs: hello world, 1,000 requests toBun.serve, abun testfile, and 30,000 direct stores toError.prepareStackTrace,Module.prototype.requireandonmessage.requirethrough anode:vmglobal (100 new values, 100 repeats). Calls ofNodeVMGlobalObject::defineOwnProperty,validateAndApplyPropertyDescriptor, the getter and the setter: 200, 253, 202 and 100 with the change, 0, 53, 2 and 200 onmain. A store that repeats the value defines nothing, so it calls no setter.main. After 1,000 first stores toprototypeof a fresh mock, one context each: 1,004 and 1,002.Node.js parity. 100 probe stores with a
node:vmglobal in the path (entry form, receiver chain, state of the holder), one process each, compared with Node.js v26.3.0 by output and exit code: 69 are equal with the change, 32 onmain. Of the 31 that still differ, 21 print the same onmain. 6 differ for a reason that a plain data property shows too:NodeVMGlobalObject::putalso stores on the sandbox of a target that is a context global,vm.runInNewContext()makes a second context for an object that has one, and a refusingdefinePropertytrap makes the store answerfalse. 4 were equal onmainonly because the write was lost there: 3 stores through 3 or more nested contexts, which Node.js does not pass on, and 1 strict store with a refusing trap. AdefinePropertytrap of a Proxy as the contextified object runs once in Node.js, once with the change, and not at all onmain.Not changed.
NodeVMGlobalObject::defineOwnPropertyasks the calling realm, not the context, whether the name is a global that is read-only and not configurable (src/jsc/bindings/NodeVM.cpp:1336). A store through a context global now takes that path, so such a global in the calling realm makes the store answertrueand install nothing. Node.js asks the context. That line is a fix for Bun.$vmhas one.DebuggerScopeand$vmobjects reach it there.Related work.
if. The two conflict. The new test tells them apart: with the holder passed to the setter, the delegate's setter runs and the test fails.Error.prepareStackTrace, and node:module: watch Module._resolveFilename and Module.prototype.require as data properties bun#47763 makesModule.prototype.requirea data property. Both are open. The setters ofonmessage,onerror, theprototypeof a mock and theexportsof a compiled module stay.Self-review. 21 concerns raised, 19 addressed. Not done: a report to upstream WebKit, and a jsdom run for the cost numbers.