Skip to content

[JSC] OrdinarySet calls a CustomValue setter only for a receiver that holds the property - #993

Open
robobun wants to merge 1 commit into
mainfrom
robobun/76ef35bc/custom-value-setter-holder
Open

robobun wants to merge 1 commit into
mainfrom
robobun/76ef35bc/custom-value-setter-holder

Conversation

@robobun

@robobun robobun commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

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.
  • Bun's node:vm global hands that definition to its contextified object, where the setter gets the holder and its realm (Upgrade to upstream WebKit 8156ba68efab #1015).
  • 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.
  • globalThis.onmessage and onerror: 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.
  • 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:

ASSERTION FAILED: JSValue::decode(slotValue).inherits<JSTestCustomGetterSetter>()
Source/JavaScriptCore/tools/JSDollarVM.cpp(1887) : bool (anonymous namespace)::customSetValue2(JSGlobalObject *, EncodedJSValue, EncodedJSValue, PropertyName)

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.

Related work.

Self-review. 21 concerns raised, 19 addressed. Not done: a report to upstream WebKit, and a jsdom run for the cost numbers.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Changes

Custom-value receiver behavior

Layer / File(s) Summary
Runtime holder check
Source/JavaScriptCore/runtime/JSObject.cpp
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: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning 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 Passed checks: 3 passed

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed 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

  1. parser at end of file
  2. 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1c3b74ca-e6fb-43be-a135-62dcefc73ee6
Commits

Reviewing files that changed from the base of the PR and between 9318597 and 68490ed.

Files selected for processing: 3

  • JSTests/BUN-TEST-DIFFERENCES.md
  • JSTests/stress/reflect-set-receiver-custom-value-of-another-object.js
  • Source/JavaScriptCore/runtime/JSObject.cpp

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Preview build of 68490ed: autobuild-preview-pr-993-68490ede

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

robobun added a commit to oven-sh/bun that referenced this pull request Nov 12, 2026
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
robobun force-pushed the robobun/76ef35bc/custom-value-setter-holder branch from 9318597 to 68490ed Compare November 13, 2026 12:44
@robobun 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.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant