Skip to content

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

Open
edusperoni wants to merge 2 commits into
mainfrom
fix/interceptor-define-property
Open

edusperoni wants to merge 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) with this PR's CI artifacts: re-verification on the artifacts of a59401b pending. The previous revision passed 2087/0 in default and canary modes, plus ASan.

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.
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