Repository navigation
fix(patches): define properties through named interceptors - #13
Open
edusperoni wants to merge 2 commits into
Open
edusperoni wants to merge 2 commits into
edusperoni wants to merge 2 commits into
Conversation
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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.patchJSObject::CreateDataPropertyis behind class fields (DefineNamedOwnIC_Slow) andv8::Object::CreateDataProperty. It added the property without consulting the object's named interceptor:TryFastAddDataProperty, follows a cached map transition;CheckIfCanDefineAsConfigurableadvances the lookup past the interceptor beforeDefineOwnPropertyIgnoreAttributesruns.--no-lazy-feedback-allocation), its fields land on the instance itself.JSObject::CreateDataPropertygains anEnforceDefineSemanticsparameter, defaulting tokDefine. WithkDefine, 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::SetSuperPropertyalso reachesCreateDataPropertywhen a[[Set]]adds a property. It passeskSetand keeps the original code. That preserves V8's contract that an assignment never calls the definer, whichPropertyDefinerCallback*,QueryInterceptorandInterceptorDefineICWithSideEffectfulCallbackspin.v8_interceptor_define_descriptor.patchkDefinebranch ofJSObject::DefineOwnPropertyIgnoreAttributesbuilds the descriptor it hands the definer with each attribute test inverted ((attributes & READ_ONLY) != 0forwritable, and likewise for the other two).NONE) arrives as{writable: false, enumerable: false, configurable: false}.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 touchesjs-objects.cc.Context
The iOS runtime's
canarywrapper 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
main(241f63a62a3), alone and in either order; every platform builds.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.PropertyDefinerCallbackInCreateDataProperty: 40 definer calls over 20 instances of a class with two fields, 1 forv8::Object::CreateDataProperty, 0 for 20 assignments.PropertyDefinerCallbackClassField: the definer receives{value: 42, writable: true, enumerable: true, configurable: true}for a cold class field.--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::CreateDataPropertyreaches it once (0 on stock); a cold field's descriptor is{writable: true, enumerable: true, configurable: true}.