Skip to content

Commit 11df46e

Browse files
authored
fix(patches): define properties through named interceptors (#13)
JSObject::CreateDataProperty, behind class fields (DefineNamedOwnIC_Slow) and v8::Object::CreateDataProperty, added properties without calling a named interceptor's definer once a class's field initializer had feedback. With define semantics it now defines through the interceptor: the definer goes first and the configurability checks run only if it declines. Object::SetSuperProperty passes EnforceDefineSemantics::kSet, so an assignment that adds a property still never calls the definer (crbug 586849332). The kDefine branch of DefineOwnPropertyIgnoreAttributes handed the definer a descriptor with writable/enumerable/configurable inverted (crbug 586850607; fixed upstream in 15.3.49 by crrev.com/c/8202604). Both patches add cctests and apply on every platform.
1 parent f77082c commit 11df46e

4 files changed

Lines changed: 234 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +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 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. |
132134
| `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. |
133135
| `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. |
134136

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
2+
index d05eb55..e575536 100644
3+
--- a/src/objects/js-objects.cc
4+
+++ b/src/objects/js-objects.cc
5+
@@ -4263,9 +4263,25 @@ Maybe<bool> JSObject::CreateDataProperty(Isolate* isolate,
6+
DirectHandle<JSObject> object,
7+
PropertyKey key,
8+
DirectHandle<Object> value,
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)) {
30+
return Just(true);
31+
}
32+
}
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);
39+
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());
150+
+ }
151+
+}
152+
+
153+
namespace {
154+
v8::Intercepted EmptyPropertyDescriptorCallback(
155+
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
2+
index d05eb55..6f2f912 100644
3+
--- a/src/objects/js-objects.cc
4+
+++ b/src/objects/js-objects.cc
5+
@@ -3801,9 +3801,9 @@ Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
6+
InterceptorResult result;
7+
if (semantics == EnforceDefineSemantics::kDefine) {
8+
PropertyDescriptor descriptor;
9+
- descriptor.set_configurable((attributes & DONT_DELETE) != 0);
10+
- descriptor.set_enumerable((attributes & DONT_ENUM) != 0);
11+
- descriptor.set_writable((attributes & READ_ONLY) != 0);
12+
+ descriptor.set_configurable((attributes & DONT_DELETE) == 0);
13+
+ descriptor.set_enumerable((attributes & DONT_ENUM) == 0);
14+
+ descriptor.set_writable((attributes & READ_ONLY) == 0);
15+
descriptor.set_value(Cast<JSAny>(value));
16+
if (!DefinePropertyWithInterceptorInternal(it, it->GetInterceptor(),
17+
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(

‎scripts/matrix/fetch.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ git -C v8 apply "$ROOT_DIR/patches/v8_js_dispatch_table_reservation.patch"
9191
# prototype that has a named interceptor of its own (crbug 585053531).
9292
git -C v8 apply "$ROOT_DIR/patches/v8_nonmasking_own_lookup.patch"
9393

94+
# CreateDataProperty (class fields, v8::Object::CreateDataProperty) added the
95+
# property behind a named interceptor's back, and the definer it did reach got
96+
# the field's attributes inverted.
97+
git -C v8 apply "$ROOT_DIR/patches/v8_create_data_property_interceptor.patch"
98+
git -C v8 apply "$ROOT_DIR/patches/v8_interceptor_define_descriptor.patch"
99+
94100
if [ "$PLATFORM" = "ios" ]; then
95101
# Mac Catalyst compiles as iOS but runs on macOS; this gives its JIT build
96102
# the macOS MAP_JIT + pthread_jit_write_protect_np handling.

0 commit comments

Comments
 (0)