Skip to content

Commit a59401b

Browse files
committed
fix(patches): keep assignments off the interceptor definer
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.
1 parent 902eaff commit a59401b

3 files changed

Lines changed: 201 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ platform), dispatch the workflow with `platforms: android` or `platforms: ios`.
129129
|---|---|
130130
| `v8_resurrecting_finalizers.patch` | Restores `WeakCallbackType::kFinalizer`, removed upstream immediately after 10.3.22. Both runtimes' object managers depend on resurrecting finalizers. It also lifts, for the finalizer drain only, the `DisallowJavascriptExecution` scope that `Heap::CollectGarbage` now holds across the whole collection: 14.9 turns entering JS from a GC callback into a `GRACEFUL_FATAL`, and the iOS runtime reaches JS whenever a released ObjC object's `-dealloc` hits a JS-backed override. |
131131
| `v8_nonmasking_own_lookup.patch` | Fixes own-property lookups on an object with a `kNonMasking` named interceptor when its prototype has a named interceptor of its own ([crbug 585053531](https://issues.chromium.org/issues/585053531)). `LookupIterator::NextInternal` meant to treat the prototype's interceptor as invisible but `continue`d out of the walk while still in a found state, so the lookup ended on the prototype: its properties read as own, `delete` removed them from the prototype, and sets and `defineProperty` went to the prototype's interceptor instead of the receiver's. The patch steps past the invisible interceptor within the same holder. Indexed interceptors are no longer skipped, as upstream since 892dda71342. Applied on every platform. |
132-
| `v8_create_data_property_interceptor.patch` | `JSObject::CreateDataProperty`, behind class fields (`DefineNamedOwnIC_Slow`) and `v8::Object::CreateDataProperty`, added the property without consulting the object's named interceptor: its fast path follows a cached map transition, and its slow path's `CheckIfCanDefineAsConfigurable` advances the lookup past the interceptor before defining. A field defined on an object with a named interceptor therefore landed on the object itself once the class's initializer had feedback. For objects with a named interceptor the patch skips the fast path and defines through the interceptor with define semantics. Applied on every platform. |
133-
| `v8_interceptor_define_descriptor.patch` | The define-semantics branch of `JSObject::DefineOwnPropertyIgnoreAttributes` built the descriptor it hands a named interceptor's definer with each attribute test inverted, so a plain data property (`NONE`) arrived as `{writable: false, enumerable: false, configurable: false}`. Applied on every platform. |
132+
| `v8_create_data_property_interceptor.patch` | `JSObject::CreateDataProperty`, behind class fields (`DefineNamedOwnIC_Slow`) and `v8::Object::CreateDataProperty`, added the property without consulting the object's named interceptor: its fast path follows a cached map transition, and its slow path's `CheckIfCanDefineAsConfigurable` advances the lookup past the interceptor before defining. A field defined on an object with a named interceptor therefore landed on the object itself once the class's initializer had feedback. For objects whose own lookup reaches a named interceptor, the patch skips the fast path and defines through the interceptor with define semantics: the definer goes first and the configurability checks run only if it declines, as on the class-field path without feedback. An assignment that adds a property (`SetSuperProperty`) still does not call the definer, which V8's own interceptor tests require; it passes `EnforceDefineSemantics::kSet`. Adds cctest `PropertyDefinerCallbackInCreateDataProperty`. Applied on every platform. |
133+
| `v8_interceptor_define_descriptor.patch` | The define-semantics branch of `JSObject::DefineOwnPropertyIgnoreAttributes` built the descriptor it hands a named interceptor's definer with each attribute test inverted, so a plain data property (`NONE`) arrived as `{writable: false, enumerable: false, configurable: false}`. Adds cctest `PropertyDefinerCallbackClassField`. Applied on every platform. |
134134
| `android_build.patch` | Lowers chromium's minimum SDK to 21 (that floor is for Java/dex tooling; this builds only the native target), makes `android_ndk_root` a gn arg, and widens the hard Linux-host assert so macOS can build the 64-bit ABIs. |
135135
| `v8_catalyst_jit_write_protect.patch` | Mac Catalyst compiles as iOS (`TARGET_OS_IPHONE`), so V8 picks its iOS JIT-memory model, which assumes `MAP_JIT` pages are writable and executable at once. A Catalyst process runs on macOS, where Apple silicon makes `MAP_JIT` pages per-thread W^X, so the first JIT code write faults (`SIGBUS`). The patch gives Catalyst the macOS model: `pthread_jit_write_protect_np` around code writes (resolved with `dlsym`, since the SDK marks it unavailable on Catalyst) and the macOS code-range pre-commit. Applied to iOS fetches only; it is a no-op outside Catalyst. |
136136

Lines changed: 144 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,155 @@
11
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
2-
index d05eb55..f17be0a 100644
2+
index d05eb55..e575536 100644
33
--- a/src/objects/js-objects.cc
44
+++ b/src/objects/js-objects.cc
5-
@@ -4264,7 +4264,11 @@ Maybe<bool> JSObject::CreateDataProperty(Isolate* isolate,
5+
@@ -4263,9 +4263,25 @@ Maybe<bool> JSObject::CreateDataProperty(Isolate* isolate,
6+
DirectHandle<JSObject> object,
67
PropertyKey key,
78
DirectHandle<Object> value,
8-
Maybe<ShouldThrow> should_throw) {
9-
- if (!key.is_element()) {
10-
+ // A named interceptor must see the definition: the fast path follows a map
11-
+ // transition without looking at it.
12-
+ bool named_interceptor =
13-
+ !key.is_element() && object->map()->has_named_interceptor();
14-
+ if (!key.is_element() && !named_interceptor) {
15-
if (TryFastAddDataProperty(isolate, object, key.name(), value, NONE)) {
9+
- Maybe<ShouldThrow> should_throw) {
10+
+ Maybe<ShouldThrow> should_throw,
11+
+ EnforceDefineSemantics semantics) {
12+
if (!key.is_element()) {
13+
- if (TryFastAddDataProperty(isolate, object, key.name(), value, NONE)) {
14+
+ if (semantics == EnforceDefineSemantics::kDefine &&
15+
+ object->map()->has_named_interceptor()) {
16+
+ // Neither the transition fast path nor the checks below call the
17+
+ // interceptor. As in [[DefineOwnProperty]], its definer goes first, and
18+
+ // the checks run only if it declines.
19+
+ LookupIterator it(isolate, object, key, LookupIterator::OWN);
20+
+ while (it.state() == LookupIterator::ACCESS_CHECK && it.HasAccess()) {
21+
+ it.Next();
22+
+ }
23+
+ if (it.state() == LookupIterator::INTERCEPTOR) {
24+
+ return DefineOwnPropertyIgnoreAttributes(
25+
+ &it, value, NONE, should_throw, DONT_FORCE_FIELD,
26+
+ EnforceDefineSemantics::kDefine);
27+
+ }
28+
+ } else if (TryFastAddDataProperty(isolate, object, key.name(), value,
29+
+ NONE)) {
1630
return Just(true);
1731
}
18-
@@ -4277,6 +4281,16 @@ Maybe<bool> JSObject::CreateDataProperty(Isolate* isolate,
19-
return can_define;
2032
}
33+
diff --git a/src/objects/js-objects.h b/src/objects/js-objects.h
34+
index 0efd658..5d70c7b 100644
35+
--- a/src/objects/js-objects.h
36+
+++ b/src/objects/js-objects.h
37+
@@ -540,11 +540,13 @@ V8_OBJECT class JSObject : public JSReceiver {
38+
PropertyAttributes attributes = NONE);
2139

22-
+ if (named_interceptor) {
23-
+ // The check above advanced the iterator past the interceptor. Define
24-
+ // through it, as [[DefineOwnProperty]] would, rather than adding the
25-
+ // property behind its back.
26-
+ it.Restart();
27-
+ return DefineOwnPropertyIgnoreAttributes(&it, value, NONE, should_throw,
28-
+ DONT_FORCE_FIELD,
29-
+ EnforceDefineSemantics::kDefine);
40+
// Adds or reconfigures a property to attributes NONE. It will fail when it
41+
- // cannot.
42+
+ // cannot. With kDefine, a named interceptor's definer is asked first. [[Set]]
43+
+ // passes kSet: a [[Set]] that adds a property does not call the definer.
44+
V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
45+
Isolate* isolate, DirectHandle<JSObject> object, PropertyKey key,
46+
DirectHandle<Object> value,
47+
- Maybe<ShouldThrow> should_throw = Just(kDontThrow));
48+
+ Maybe<ShouldThrow> should_throw = Just(kDontThrow),
49+
+ EnforceDefineSemantics semantics = EnforceDefineSemantics::kDefine);
50+
51+
V8_EXPORT_PRIVATE static void AddProperty(Isolate* isolate,
52+
DirectHandle<JSObject> object,
53+
diff --git a/src/objects/objects.cc b/src/objects/objects.cc
54+
index e55ab41..9b5eda9 100644
55+
--- a/src/objects/objects.cc
56+
+++ b/src/objects/objects.cc
57+
@@ -2659,6 +2659,13 @@ Maybe<bool> Object::SetSuperProperty(LookupIterator* it,
58+
should_throw)) {
59+
return Nothing<bool>();
60+
}
61+
+ if (IsJSObject(*receiver)) {
62+
+ // A [[Set]] that adds a property does not call the interceptor's
63+
+ // definer.
64+
+ return JSObject::CreateDataProperty(
65+
+ isolate, Cast<JSObject>(receiver), it->GetKey(), value,
66+
+ should_throw, EnforceDefineSemantics::kSet);
67+
+ }
68+
return JSReceiver::CreateDataProperty(isolate, receiver, it->GetKey(),
69+
value, should_throw);
70+
}
71+
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
72+
index a62476a..a2abe50 100644
73+
--- a/test/cctest/test-api-interceptors.cc
74+
+++ b/test/cctest/test-api-interceptors.cc
75+
@@ -2946,6 +2946,80 @@ THREADED_TEST(PropertyDefinerCallbackInDefineNamedOwnIC) {
76+
}
77+
}
78+
79+
+namespace {
80+
+int create_data_property_definer_calls = 0;
81+
+v8::Intercepted CountDefinerCallsAndContinueCallback(
82+
+ Local<Name> name, const v8::PropertyDescriptor& desc,
83+
+ const v8::PropertyCallbackInfo<Boolean>& info) {
84+
+ create_data_property_definer_calls++;
85+
+ CHECK(desc.has_value());
86+
+ return v8::Intercepted::kNo;
87+
+}
88+
+
89+
+void CheckPropertyDefinerCallbackInCreateDataProperty(Local<Context> context) {
90+
+ v8::Local<v8::FunctionTemplate> templ =
91+
+ v8::FunctionTemplate::New(CcTest::isolate());
92+
+ templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
93+
+ nullptr, nullptr, nullptr, nullptr, nullptr,
94+
+ CountDefinerCallsAndContinueCallback));
95+
+ context->Global()
96+
+ ->Set(context, v8_str("Cls"),
97+
+ templ->GetFunction(context).ToLocalChecked())
98+
+ .FromJust();
99+
+
100+
+ // Every instance, including those created once the field initializer has
101+
+ // feedback.
102+
+ create_data_property_definer_calls = 0;
103+
+ CHECK(CompileRun("class WithFields extends Cls {"
104+
+ " field = 1;"
105+
+ " ['computed'] = 2;"
106+
+ "}"
107+
+ "let ok = true;"
108+
+ "for (let i = 0; i < 20; i++) {"
109+
+ " const o = new WithFields();"
110+
+ " ok = ok && o.field === 1 && o.computed === 2;"
111+
+ "}"
112+
+ "ok")
113+
+ ->IsTrue());
114+
+ CHECK_EQ(40, create_data_property_definer_calls);
115+
+
116+
+ create_data_property_definer_calls = 0;
117+
+ Local<Object> obj =
118+
+ templ->InstanceTemplate()->NewInstance(context).ToLocalChecked();
119+
+ CHECK(obj->CreateDataProperty(context, v8_str("api"), v8_num(3)).FromJust());
120+
+ CHECK_EQ(1, create_data_property_definer_calls);
121+
+ CHECK_EQ(3, obj->Get(context, v8_str("api"))
122+
+ .ToLocalChecked()
123+
+ ->Int32Value(context)
124+
+ .FromJust());
125+
+
126+
+ // Assignments do not call the definer.
127+
+ context->Global()->Set(context, v8_str("obj"), obj).FromJust();
128+
+ create_data_property_definer_calls = 0;
129+
+ CHECK_EQ(4, CompileRun("for (let i = 0; i < 20; i++) obj['p' + i] = 4;"
130+
+ "obj.p19")
131+
+ ->Int32Value(context)
132+
+ .FromJust());
133+
+ CHECK_EQ(0, create_data_property_definer_calls);
134+
+}
135+
+} // namespace
136+
+
137+
+THREADED_TEST(PropertyDefinerCallbackInCreateDataProperty) {
138+
+ {
139+
+ LocalContext env;
140+
+ v8::HandleScope scope(env.isolate());
141+
+ CheckPropertyDefinerCallbackInCreateDataProperty(env.local());
142+
+ }
143+
+
144+
+ {
145+
+ i::v8_flags.lazy_feedback_allocation = false;
146+
+ i::FlagList::EnforceFlagImplications();
147+
+ LocalContext env;
148+
+ v8::HandleScope scope(env.isolate());
149+
+ CheckPropertyDefinerCallbackInCreateDataProperty(env.local());
30150
+ }
151+
+}
31152
+
32-
RETURN_ON_EXCEPTION_VALUE(isolate,
33-
DefineOwnPropertyIgnoreAttributes(&it, value, NONE),
34-
Nothing<bool>());
153+
namespace {
154+
v8::Intercepted EmptyPropertyDescriptorCallback(
155+
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {

‎patches/v8_interceptor_define_descriptor.patch‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
2-
index f17be0a..fbfc3ea 100644
2+
index d05eb55..6f2f912 100644
33
--- a/src/objects/js-objects.cc
44
+++ b/src/objects/js-objects.cc
55
@@ -3801,9 +3801,9 @@ Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
@@ -15,3 +15,57 @@ index f17be0a..fbfc3ea 100644
1515
descriptor.set_value(Cast<JSAny>(value));
1616
if (!DefinePropertyWithInterceptorInternal(it, it->GetInterceptor(),
1717
should_throw, &descriptor)
18+
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
19+
index a62476a..b75e8da 100644
20+
--- a/test/cctest/test-api-interceptors.cc
21+
+++ b/test/cctest/test-api-interceptors.cc
22+
@@ -2748,6 +2748,49 @@ THREADED_TEST(PropertyDefinerCallbackWithSetter) {
23+
.FromJust());
24+
}
25+
26+
+// Check that a class field reaches the callback as a plain data property.
27+
+namespace {
28+
+int data_property_define_calls = 0;
29+
+v8::Intercepted CheckDataPropertyDefineCallback(
30+
+ Local<Name> name, const v8::PropertyDescriptor& desc,
31+
+ const v8::PropertyCallbackInfo<Boolean>& info) {
32+
+ data_property_define_calls++;
33+
+ CHECK(desc.has_value());
34+
+ CHECK_EQ(42, desc.value()
35+
+ ->Int32Value(info.GetIsolate()->GetCurrentContext())
36+
+ .FromJust());
37+
+ CHECK(desc.has_writable());
38+
+ CHECK(desc.writable());
39+
+ CHECK(desc.has_enumerable());
40+
+ CHECK(desc.enumerable());
41+
+ CHECK(desc.has_configurable());
42+
+ CHECK(desc.configurable());
43+
+ CHECK(!desc.has_get());
44+
+ CHECK(!desc.has_set());
45+
+ return v8::Intercepted::kYes;
46+
+}
47+
+} // namespace
48+
+
49+
+THREADED_TEST(PropertyDefinerCallbackClassField) {
50+
+ v8::HandleScope scope(CcTest::isolate());
51+
+ LocalContext env;
52+
+ v8::Local<v8::FunctionTemplate> templ =
53+
+ v8::FunctionTemplate::New(CcTest::isolate());
54+
+ templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
55+
+ nullptr, nullptr, nullptr, nullptr, nullptr,
56+
+ CheckDataPropertyDefineCallback));
57+
+ env->Global()
58+
+ ->Set(env.local(), v8_str("Cls"),
59+
+ templ->GetFunction(env.local()).ToLocalChecked())
60+
+ .FromJust();
61+
+ data_property_define_calls = 0;
62+
+ const char* code =
63+
+ "class WithField extends Cls { x = 42; }"
64+
+ "new WithField().x;";
65+
+ CHECK(v8_compile(code)->Run(env.local()).ToLocalChecked()->IsUndefined());
66+
+ CHECK_EQ(1, data_property_define_calls);
67+
+}
68+
+
69+
namespace {
70+
std::vector<std::string> definer_calls;
71+
v8::Intercepted LogDefinerCallsAndContinueCallback(

0 commit comments

Comments
 (0)