Skip to content

fix(patches): define properties through named interceptors - #13

Merged
edusperoni merged 2 commits into
mainfrom
fix/interceptor-define-property
Nov 18, 2026
Merged

edusperoni merged 2 commits into
mainfrom
fix/interceptor-define-property

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Two V8 bugs, present in 14.9.207.39 and unchanged on upstream main, break defining a property on an object that has a named interceptor. Class fields go through that path, so an embedder that forwards an object's JS properties through interceptors loses or freezes them.

The bugs

v8_create_data_property_interceptor.patch

  • JSObject::CreateDataProperty is behind class fields (DefineNamedOwnIC_Slow) and v8::Object::CreateDataProperty. It added the property without consulting the object's named interceptor:
    • its fast path, TryFastAddDataProperty, follows a cached map transition;
    • its slow path's CheckIfCanDefineAsConfigurable advances the lookup past the interceptor before DefineOwnPropertyIgnoreAttributes runs.
  • Once a class's field initializer has feedback (around the 9th instance with lazy feedback allocation, the 2nd with --no-lazy-feedback-allocation), its fields land on the instance itself.
  • JSObject::CreateDataProperty gains an EnforceDefineSemantics parameter, defaulting to kDefine. With kDefine, when the own lookup reaches a named interceptor, the patch skips the fast path and defines through the interceptor. The definer goes first, and the configurability checks run only if it declines. That is the order the class-field path already uses before it has feedback. Objects without a named interceptor take the existing code path.
  • Object::SetSuperProperty also reaches CreateDataProperty when a [[Set]] adds a property. It passes kSet and keeps the original code. That preserves V8's contract that an assignment never calls the definer, which PropertyDefinerCallback*, QueryInterceptor and InterceptorDefineICWithSideEffectfulCallbacks pin.

v8_interceptor_define_descriptor.patch

  • The kDefine branch of JSObject::DefineOwnPropertyIgnoreAttributes builds the descriptor it hands the definer with each attribute test inverted ((attributes & READ_ONLY) != 0 for writable, and likewise for the other two).
  • A plain data property (NONE) arrives as {writable: false, enumerable: false, configurable: false}.
  • Every caller of this branch passes NONE, so the fix never builds a partial descriptor.

Both patches are applied on every platform, after v8_nonmasking_own_lookup.patch; no earlier patch touches js-objects.cc.

Context

The iOS runtime's canary wrapper lifetime mode (NativeScript/ios#561) forwards JS properties from named interceptors on ObjC instances to a state object. Measured in a standalone V8 host on 14.9.207.39 with repros for both bugs: class fields were lost after the first few instances and stored read-only, hidden and undeletable before that. Upstream crbug reports will follow.

Testing

  • Both patches apply to pristine 14.9.207.39 and to upstream main (241f63a62a3), alone and in either order; every platform builds.
  • V8's own suites on 14.9.207.39 (test-api-interceptors, test-api, test-accessors, test-api-accessors), iOS simulator build: 837 tests, 0 failures in the default variant, with --no-lazy-feedback-allocation, and 825/0 in the jitless variant.
  • New cctests, each failing on stock 14.9 and passing with the patches:
    • PropertyDefinerCallbackInCreateDataProperty: 40 definer calls over 20 instances of a class with two fields, 1 for v8::Object::CreateDataProperty, 0 for 20 assignments.
    • PropertyDefinerCallbackClassField: the definer receives {value: 42, writable: true, enumerable: true, configurable: true} for a cold class field.
  • Standalone repros (iOS simulator and Mac Catalyst; default flags, --no-lazy-feedback-allocation, --jitless): a class field on 20 instances reaches the definer 20 times (10 on stock 14.9, 1 with --no-lazy-feedback-allocation); v8::Object::CreateDataProperty reaches it once (0 on stock); a cold field's descriptor is {writable: true, enumerable: true, configurable: true}.
  • iOS runtime (feat(runtime): canary wrapper lifetime mode ios#561 at cdc59c16) with this PR's arm64 simulator libraries from run 44168976735 (a59401b) swapped in: 2107 specs, 0 failures in each of its wrapper lifetime modes (resurrecting/extended, canary/all, canary/extended, rooted/all); AddressSanitizer, canary/all: 0 failures, no reports.

Two V8 bugs (14.9.207.39, unchanged on upstream main) break defining a
property on an object with a named interceptor, which is how class fields
reach it:

- v8_create_data_property_interceptor.patch: JSObject::CreateDataProperty,
  behind class fields (DefineNamedOwnIC_Slow) and
  v8::Object::CreateDataProperty, added the property without consulting the
  interceptor. Its fast path follows a cached map transition, and its slow
  path's CheckIfCanDefineAsConfigurable advances the lookup past the
  interceptor before defining. Once a class's field initializer had feedback,
  its fields landed on the instance itself. For objects with a named
  interceptor the patch skips the fast path and defines through the
  interceptor with define semantics.
- v8_interceptor_define_descriptor.patch: the define-semantics branch of
  JSObject::DefineOwnPropertyIgnoreAttributes built the descriptor it hands
  the interceptor's definer with each attribute test inverted, so a plain
  data property arrived as non-writable, non-enumerable and
  non-configurable.

Both are applied on every platform. The iOS runtime's canary wrapper
lifetime mode forwards JS properties from interceptors on ObjC instances to
a state object; with these bugs, class fields were lost or frozen.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f98b2637-7d04-41c2-ba37-330bbad93ff3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

JSObject::CreateDataProperty is also reached from Object::SetSuperProperty
when a [[Set]] adds a property, so defining through the definer there broke
V8's contract that assignments never call it (10 cctests in
test-api-interceptors). CreateDataProperty now takes EnforceDefineSemantics:
define semantics ask the definer first and run the configurability checks
only if it declines; SetSuperProperty passes kSet and keeps the original path.

Adds cctests PropertyDefinerCallbackInCreateDataProperty and
PropertyDefinerCallbackClassField.
@edusperoni
edusperoni merged commit 11df46e into main Nov 18, 2026
28 of 30 checks passed
edusperoni added a commit to NativeScript/android that referenced this pull request Nov 22, 2026
### Description

Bottom of a stacked series that ports the iOS wrapper lifetime modes
(NativeScript/ios#558, #559's config, #561, #563; #576's leak probe is
redesigned in #2130) to Android. Not ported: #559's `rooted` mode (it
reads retain counts, which Java does not have) and #578 (a native-setter
fast path in the canary write handler; on Android a write to a Java
field still goes through V8 after the handler declines). No PR in the
series has performance numbers yet. This PR changes only the V8 pin, so
the new binary can be validated, and reverted, on its own.

`V8_RELEASE` moves from `v8-14.9.207.39-7` to `-12`. Same V8 version and
the same Android patches (`v8_resurrecting_finalizers.patch`, the JS
dispatch table reservation, the Android build patch), plus two fixes for
named interceptors and a fast path for stores a masking interceptor
declines:

- **`-10`, NativeScript/v8-buildscripts#11**
(`v8_nonmasking_own_lookup.patch`, crbug 585053531): an own-property
lookup on an object with a `kNonMasking` interceptor could end on a
prototype's interceptor (`Object.hasOwn` true for a prototype-only name,
`delete` reaching the prototype).
- **`-11`, NativeScript/v8-buildscripts#13**
(`v8_create_data_property_interceptor.patch`,
`v8_interceptor_define_descriptor.patch`):
`JSObject::CreateDataProperty` (define-semantics class fields once warm,
`v8::Object::CreateDataProperty`) bypassed named interceptors, and a
definer received a plain data property with every attribute inverted.

- **`-12`, NativeScript/v8-buildscripts#15**
(`v8_declined_interceptor_store_fast_path.patch`): when a masking named
interceptor declines a store and the receiver already has that name as
an own data field, the store IC overwrites the field directly instead of
going through `Runtime_StorePropertyPastInterceptor`. Behind
`--store-ic-declined-interceptor-fast-path`, on by default. On a phone,
an expando overwrite on a canary goes from 178 to 105 ns; adding a
property, writes that end at a prototype accessor, and everything else
are unchanged.

The canary mode later in this stack puts a masking named interceptor
(setter, deleter, definer) on wrapper templates, and needs both. Nothing
on Android uses a named interceptor on an instance template today, so
this PR alone changes no behaviour. `-8` and `-9` add only Apple TV and
Mac Catalyst variants.

### Testing

Full suite on an arm64 API 35 emulator with the `-11` arm64 libraries:
1773 specs, 0 failures. With the `-12` patch (the #15 CI arm64 library),
at the top of this stack on `main` at a59e6ba: 1895 / 1895 / 1909
specs, 0 failures, in `canary`/`all`, `canary`/`extended` and
`resurrecting`.



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Chores**
  * Updated the V8 release from 14.9.207.39-11 to 14.9.207.39-12.
* V8 installations now verify that each requested ABI matches the
selected release and record the release for each installed ABI.
Libraries and release stamps that do not match the selected release are
removed during installation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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