Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ platform), dispatch the workflow with `platforms: android` or `platforms: ios`.
|---|---|
| `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. |
| `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. |
| `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. |
| `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. |
| `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. |
| `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. |

Expand Down
155 changes: 155 additions & 0 deletions patches/v8_create_data_property_interceptor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
index d05eb55..e575536 100644
--- a/src/objects/js-objects.cc
+++ b/src/objects/js-objects.cc
@@ -4263,9 +4263,25 @@ Maybe<bool> JSObject::CreateDataProperty(Isolate* isolate,
DirectHandle<JSObject> object,
PropertyKey key,
DirectHandle<Object> value,
- Maybe<ShouldThrow> should_throw) {
+ Maybe<ShouldThrow> should_throw,
+ EnforceDefineSemantics semantics) {
if (!key.is_element()) {
- if (TryFastAddDataProperty(isolate, object, key.name(), value, NONE)) {
+ if (semantics == EnforceDefineSemantics::kDefine &&
+ object->map()->has_named_interceptor()) {
+ // Neither the transition fast path nor the checks below call the
+ // interceptor. As in [[DefineOwnProperty]], its definer goes first, and
+ // the checks run only if it declines.
+ LookupIterator it(isolate, object, key, LookupIterator::OWN);
+ while (it.state() == LookupIterator::ACCESS_CHECK && it.HasAccess()) {
+ it.Next();
+ }
+ if (it.state() == LookupIterator::INTERCEPTOR) {
+ return DefineOwnPropertyIgnoreAttributes(
+ &it, value, NONE, should_throw, DONT_FORCE_FIELD,
+ EnforceDefineSemantics::kDefine);
+ }
+ } else if (TryFastAddDataProperty(isolate, object, key.name(), value,
+ NONE)) {
return Just(true);
}
}
diff --git a/src/objects/js-objects.h b/src/objects/js-objects.h
index 0efd658..5d70c7b 100644
--- a/src/objects/js-objects.h
+++ b/src/objects/js-objects.h
@@ -540,11 +540,13 @@ V8_OBJECT class JSObject : public JSReceiver {
PropertyAttributes attributes = NONE);

// Adds or reconfigures a property to attributes NONE. It will fail when it
- // cannot.
+ // cannot. With kDefine, a named interceptor's definer is asked first. [[Set]]
+ // passes kSet: a [[Set]] that adds a property does not call the definer.
V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
Isolate* isolate, DirectHandle<JSObject> object, PropertyKey key,
DirectHandle<Object> value,
- Maybe<ShouldThrow> should_throw = Just(kDontThrow));
+ Maybe<ShouldThrow> should_throw = Just(kDontThrow),
+ EnforceDefineSemantics semantics = EnforceDefineSemantics::kDefine);

V8_EXPORT_PRIVATE static void AddProperty(Isolate* isolate,
DirectHandle<JSObject> object,
diff --git a/src/objects/objects.cc b/src/objects/objects.cc
index e55ab41..9b5eda9 100644
--- a/src/objects/objects.cc
+++ b/src/objects/objects.cc
@@ -2659,6 +2659,13 @@ Maybe<bool> Object::SetSuperProperty(LookupIterator* it,
should_throw)) {
return Nothing<bool>();
}
+ if (IsJSObject(*receiver)) {
+ // A [[Set]] that adds a property does not call the interceptor's
+ // definer.
+ return JSObject::CreateDataProperty(
+ isolate, Cast<JSObject>(receiver), it->GetKey(), value,
+ should_throw, EnforceDefineSemantics::kSet);
+ }
return JSReceiver::CreateDataProperty(isolate, receiver, it->GetKey(),
value, should_throw);
}
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
index a62476a..a2abe50 100644
--- a/test/cctest/test-api-interceptors.cc
+++ b/test/cctest/test-api-interceptors.cc
@@ -2946,6 +2946,80 @@ THREADED_TEST(PropertyDefinerCallbackInDefineNamedOwnIC) {
}
}

+namespace {
+int create_data_property_definer_calls = 0;
+v8::Intercepted CountDefinerCallsAndContinueCallback(
+ Local<Name> name, const v8::PropertyDescriptor& desc,
+ const v8::PropertyCallbackInfo<Boolean>& info) {
+ create_data_property_definer_calls++;
+ CHECK(desc.has_value());
+ return v8::Intercepted::kNo;
+}
+
+void CheckPropertyDefinerCallbackInCreateDataProperty(Local<Context> context) {
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+ templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, nullptr, nullptr, nullptr, nullptr,
+ CountDefinerCallsAndContinueCallback));
+ context->Global()
+ ->Set(context, v8_str("Cls"),
+ templ->GetFunction(context).ToLocalChecked())
+ .FromJust();
+
+ // Every instance, including those created once the field initializer has
+ // feedback.
+ create_data_property_definer_calls = 0;
+ CHECK(CompileRun("class WithFields extends Cls {"
+ " field = 1;"
+ " ['computed'] = 2;"
+ "}"
+ "let ok = true;"
+ "for (let i = 0; i < 20; i++) {"
+ " const o = new WithFields();"
+ " ok = ok && o.field === 1 && o.computed === 2;"
+ "}"
+ "ok")
+ ->IsTrue());
+ CHECK_EQ(40, create_data_property_definer_calls);
+
+ create_data_property_definer_calls = 0;
+ Local<Object> obj =
+ templ->InstanceTemplate()->NewInstance(context).ToLocalChecked();
+ CHECK(obj->CreateDataProperty(context, v8_str("api"), v8_num(3)).FromJust());
+ CHECK_EQ(1, create_data_property_definer_calls);
+ CHECK_EQ(3, obj->Get(context, v8_str("api"))
+ .ToLocalChecked()
+ ->Int32Value(context)
+ .FromJust());
+
+ // Assignments do not call the definer.
+ context->Global()->Set(context, v8_str("obj"), obj).FromJust();
+ create_data_property_definer_calls = 0;
+ CHECK_EQ(4, CompileRun("for (let i = 0; i < 20; i++) obj['p' + i] = 4;"
+ "obj.p19")
+ ->Int32Value(context)
+ .FromJust());
+ CHECK_EQ(0, create_data_property_definer_calls);
+}
+} // namespace
+
+THREADED_TEST(PropertyDefinerCallbackInCreateDataProperty) {
+ {
+ LocalContext env;
+ v8::HandleScope scope(env.isolate());
+ CheckPropertyDefinerCallbackInCreateDataProperty(env.local());
+ }
+
+ {
+ i::v8_flags.lazy_feedback_allocation = false;
+ i::FlagList::EnforceFlagImplications();
+ LocalContext env;
+ v8::HandleScope scope(env.isolate());
+ CheckPropertyDefinerCallbackInCreateDataProperty(env.local());
+ }
+}
+
namespace {
v8::Intercepted EmptyPropertyDescriptorCallback(
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
71 changes: 71 additions & 0 deletions patches/v8_interceptor_define_descriptor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
index d05eb55..6f2f912 100644
--- a/src/objects/js-objects.cc
+++ b/src/objects/js-objects.cc
@@ -3801,9 +3801,9 @@ Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
InterceptorResult result;
if (semantics == EnforceDefineSemantics::kDefine) {
PropertyDescriptor descriptor;
- descriptor.set_configurable((attributes & DONT_DELETE) != 0);
- descriptor.set_enumerable((attributes & DONT_ENUM) != 0);
- descriptor.set_writable((attributes & READ_ONLY) != 0);
+ descriptor.set_configurable((attributes & DONT_DELETE) == 0);
+ descriptor.set_enumerable((attributes & DONT_ENUM) == 0);
+ descriptor.set_writable((attributes & READ_ONLY) == 0);
descriptor.set_value(Cast<JSAny>(value));
if (!DefinePropertyWithInterceptorInternal(it, it->GetInterceptor(),
should_throw, &descriptor)
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
index a62476a..b75e8da 100644
--- a/test/cctest/test-api-interceptors.cc
+++ b/test/cctest/test-api-interceptors.cc
@@ -2748,6 +2748,49 @@ THREADED_TEST(PropertyDefinerCallbackWithSetter) {
.FromJust());
}

+// Check that a class field reaches the callback as a plain data property.
+namespace {
+int data_property_define_calls = 0;
+v8::Intercepted CheckDataPropertyDefineCallback(
+ Local<Name> name, const v8::PropertyDescriptor& desc,
+ const v8::PropertyCallbackInfo<Boolean>& info) {
+ data_property_define_calls++;
+ CHECK(desc.has_value());
+ CHECK_EQ(42, desc.value()
+ ->Int32Value(info.GetIsolate()->GetCurrentContext())
+ .FromJust());
+ CHECK(desc.has_writable());
+ CHECK(desc.writable());
+ CHECK(desc.has_enumerable());
+ CHECK(desc.enumerable());
+ CHECK(desc.has_configurable());
+ CHECK(desc.configurable());
+ CHECK(!desc.has_get());
+ CHECK(!desc.has_set());
+ return v8::Intercepted::kYes;
+}
+} // namespace
+
+THREADED_TEST(PropertyDefinerCallbackClassField) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+ templ->InstanceTemplate()->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, nullptr, nullptr, nullptr, nullptr,
+ CheckDataPropertyDefineCallback));
+ env->Global()
+ ->Set(env.local(), v8_str("Cls"),
+ templ->GetFunction(env.local()).ToLocalChecked())
+ .FromJust();
+ data_property_define_calls = 0;
+ const char* code =
+ "class WithField extends Cls { x = 42; }"
+ "new WithField().x;";
+ CHECK(v8_compile(code)->Run(env.local()).ToLocalChecked()->IsUndefined());
+ CHECK_EQ(1, data_property_define_calls);
+}
+
namespace {
std::vector<std::string> definer_calls;
v8::Intercepted LogDefinerCallsAndContinueCallback(
6 changes: 6 additions & 0 deletions scripts/matrix/fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ git -C v8 apply "$ROOT_DIR/patches/v8_js_dispatch_table_reservation.patch"
# prototype that has a named interceptor of its own (crbug 585053531).
git -C v8 apply "$ROOT_DIR/patches/v8_nonmasking_own_lookup.patch"

# CreateDataProperty (class fields, v8::Object::CreateDataProperty) added the
# property behind a named interceptor's back, and the definer it did reach got
# the field's attributes inverted.
git -C v8 apply "$ROOT_DIR/patches/v8_create_data_property_interceptor.patch"
git -C v8 apply "$ROOT_DIR/patches/v8_interceptor_define_descriptor.patch"

if [ "$PLATFORM" = "ios" ]; then
# Mac Catalyst compiles as iOS but runs on macOS; this gives its JIT build
# the macOS MAP_JIT + pthread_jit_write_protect_np handling.
Expand Down
Loading