chore: cherry-pick 36b66b5cc991 from v8 (#33613)

This commit is contained in:
Jeremy Rose
2022-04-05 09:42:31 -07:00
committed by GitHub
parent bd1e0176f5
commit f4fc41b877
2 changed files with 143 additions and 0 deletions

View File

@@ -8,3 +8,4 @@ fix_build_deprecated_attirbute_for_older_msvc_versions.patch
fix_disable_implies_dcheck_for_node_stream_array_buffers.patch
fix_use_allocationtype_kold_in_v8_scriptormodule_legacy_lifetime.patch
fix_destructor_for_embedderstatescope.patch
cherry-pick-36b66b5cc991.patch

View File

@@ -0,0 +1,142 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Igor Sheludko <ishell@chromium.org>
Date: Fri, 1 Apr 2022 17:41:24 +0200
Subject: Merged: [runtime] Fix handling of interceptors, pt.3
... in JSObject::DefineOwnPropertyIgnoreAttributes().
Don't execute interceptor again if it declined to handle the operation.
Bug: chromium:1311641
(cherry picked from commit c4e66b89b4ecd0e90b31e9e4ed08d38085a84c49)
Change-Id: Ie9aef5a98959403f6a26e6bef7f4a77d312bd62a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3563560
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/branch-heads/10.0@{#16}
Cr-Branched-From: 6ea73a738c467dc26abbbe84e27a36aac1c6e119-refs/heads/10.0.139@{#1}
Cr-Branched-From: ccc689011280419901e6ee42cae39980c0e96030-refs/heads/main@{#79131}
diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc
index 1df13df72c29f804168ab1f57117650922378a07..d823bba604936c1c99b4e3aea694afc8fa267d83 100644
--- a/src/objects/js-objects.cc
+++ b/src/objects/js-objects.cc
@@ -3451,9 +3451,18 @@ Maybe<bool> JSObject::DefineOwnPropertyIgnoreAttributes(
if (can_define.IsNothing() || !can_define.FromJust()) {
return can_define;
}
- it->Restart();
}
- break;
+
+ // The interceptor declined to handle the operation, so proceed defining
+ // own property without the interceptor.
+ Isolate* isolate = it->isolate();
+ Handle<Object> receiver = it->GetReceiver();
+ LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR;
+ LookupIterator own_lookup =
+ it->IsElement() ? LookupIterator(isolate, receiver, it->index(), c)
+ : LookupIterator(isolate, receiver, it->name(), c);
+ return JSObject::DefineOwnPropertyIgnoreAttributes(
+ &own_lookup, value, attributes, should_throw, handling, semantics);
}
case LookupIterator::ACCESSOR: {
diff --git a/test/cctest/test-api-interceptors.cc b/test/cctest/test-api-interceptors.cc
index 909795ece407ac2089f15e562d308733371fbb65..7eb96a54f77519a8b968d40fab4d01070e0ed179 100644
--- a/test/cctest/test-api-interceptors.cc
+++ b/test/cctest/test-api-interceptors.cc
@@ -60,6 +60,16 @@ void EmptyInterceptorDeleter(
void EmptyInterceptorEnumerator(
const v8::PropertyCallbackInfo<v8::Array>& info) {}
+void EmptyInterceptorDefinerWithSideEffect(
+ Local<Name> name, const v8::PropertyDescriptor& desc,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ ApiTestFuzzer::Fuzz();
+ v8::Local<v8::Value> result = CompileRun("interceptor_definer_side_effect()");
+ if (!result->IsNull()) {
+ info.GetReturnValue().Set(result);
+ }
+}
+
void SimpleAccessorGetter(Local<String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
Local<Object> self = info.This().As<Object>();
@@ -869,13 +879,17 @@ THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
namespace {
void CheckInterceptorIC(v8::GenericNamedPropertyGetterCallback getter,
+ v8::GenericNamedPropertySetterCallback setter,
v8::GenericNamedPropertyQueryCallback query,
- const char* source, int expected) {
+ v8::GenericNamedPropertyDefinerCallback definer,
+ v8::PropertyHandlerFlags flags, const char* source,
+ int expected) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
- getter, nullptr, query, nullptr, nullptr, v8_str("data")));
+ getter, setter, query, nullptr /* deleter */, nullptr /* enumerator */,
+ definer, nullptr /* descriptor */, v8_str("data"), flags));
LocalContext context;
context->Global()
->Set(context.local(), v8_str("o"),
@@ -885,9 +899,17 @@ void CheckInterceptorIC(v8::GenericNamedPropertyGetterCallback getter,
CHECK_EQ(expected, value->Int32Value(context.local()).FromJust());
}
+void CheckInterceptorIC(v8::GenericNamedPropertyGetterCallback getter,
+ v8::GenericNamedPropertyQueryCallback query,
+ const char* source, int expected) {
+ CheckInterceptorIC(getter, nullptr, query, nullptr,
+ v8::PropertyHandlerFlags::kNone, source, expected);
+}
+
void CheckInterceptorLoadIC(v8::GenericNamedPropertyGetterCallback getter,
const char* source, int expected) {
- CheckInterceptorIC(getter, nullptr, source, expected);
+ CheckInterceptorIC(getter, nullptr, nullptr, nullptr,
+ v8::PropertyHandlerFlags::kNone, source, expected);
}
void InterceptorLoadICGetter(Local<Name> name,
@@ -1581,6 +1603,38 @@ THREADED_TEST(InterceptorStoreICWithSideEffectfulCallbacks) {
19);
}
+THREADED_TEST(InterceptorDefineICWithSideEffectfulCallbacks) {
+ CheckInterceptorIC(EmptyInterceptorGetter, EmptyInterceptorSetter,
+ EmptyInterceptorQuery,
+ EmptyInterceptorDefinerWithSideEffect,
+ v8::PropertyHandlerFlags::kNonMasking,
+ "let inside_side_effect = false;"
+ "let interceptor_definer_side_effect = function() {"
+ " if (!inside_side_effect) {"
+ " inside_side_effect = true;"
+ " o.y = 153;"
+ " inside_side_effect = false;"
+ " }"
+ " return null;"
+ "};"
+ "class Base {"
+ " constructor(arg) {"
+ " return arg;"
+ " }"
+ "}"
+ "class ClassWithField extends Base {"
+ " y = (() => {"
+ " return 42;"
+ " })();"
+ " constructor(arg) {"
+ " super(arg);"
+ " }"
+ "}"
+ "new ClassWithField(o);"
+ "o.y",
+ 42);
+}
+
static void InterceptorStoreICSetter(
Local<Name> key, Local<Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {