diff --git a/README.md b/README.md index 361d8ef..069f076 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/patches/v8_create_data_property_interceptor.patch b/patches/v8_create_data_property_interceptor.patch new file mode 100644 index 0000000..aa0f7ca --- /dev/null +++ b/patches/v8_create_data_property_interceptor.patch @@ -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 JSObject::CreateDataProperty(Isolate* isolate, + DirectHandle object, + PropertyKey key, + DirectHandle value, +- Maybe should_throw) { ++ Maybe 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 CreateDataProperty( + Isolate* isolate, DirectHandle object, PropertyKey key, + DirectHandle value, +- Maybe should_throw = Just(kDontThrow)); ++ Maybe should_throw = Just(kDontThrow), ++ EnforceDefineSemantics semantics = EnforceDefineSemantics::kDefine); + + V8_EXPORT_PRIVATE static void AddProperty(Isolate* isolate, + DirectHandle 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 Object::SetSuperProperty(LookupIterator* it, + should_throw)) { + return Nothing(); + } ++ if (IsJSObject(*receiver)) { ++ // A [[Set]] that adds a property does not call the interceptor's ++ // definer. ++ return JSObject::CreateDataProperty( ++ isolate, Cast(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, const v8::PropertyDescriptor& desc, ++ const v8::PropertyCallbackInfo& info) { ++ create_data_property_definer_calls++; ++ CHECK(desc.has_value()); ++ return v8::Intercepted::kNo; ++} ++ ++void CheckPropertyDefinerCallbackInCreateDataProperty(Local context) { ++ v8::Local 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 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, const v8::PropertyCallbackInfo& info) { diff --git a/patches/v8_interceptor_define_descriptor.patch b/patches/v8_interceptor_define_descriptor.patch new file mode 100644 index 0000000..860dae5 --- /dev/null +++ b/patches/v8_interceptor_define_descriptor.patch @@ -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 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(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, const v8::PropertyDescriptor& desc, ++ const v8::PropertyCallbackInfo& 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 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 definer_calls; + v8::Intercepted LogDefinerCallsAndContinueCallback( diff --git a/scripts/matrix/fetch.sh b/scripts/matrix/fetch.sh index 520c27b..8ca1663 100755 --- a/scripts/matrix/fetch.sh +++ b/scripts/matrix/fetch.sh @@ -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.