Commit 9eb96bb4 authored by Timothy Gu's avatar Timothy Gu Committed by Commit Bot

[api] Avoid needlessly calling descriptor interceptors

Reland part of https://chromium-review.googlesource.com/c/v8/v8/+/816515.

Change-Id: I72ad85ffd162fc0563fc25cdf35189e894f9dc82
Reviewed-on: https://chromium-review.googlesource.com/1138808
Commit-Queue: Timothy Gu <timothygu@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54492}
parent 8fa16685
...@@ -7807,13 +7807,17 @@ namespace { ...@@ -7807,13 +7807,17 @@ namespace {
Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it, Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
PropertyDescriptor* desc) { PropertyDescriptor* desc) {
bool has_access = true;
if (it->state() == LookupIterator::ACCESS_CHECK) { if (it->state() == LookupIterator::ACCESS_CHECK) {
has_access = it->HasAccess() || JSObject::AllCanRead(it); if (it->HasAccess()) {
it->Next(); it->Next();
} else if (!JSObject::AllCanRead(it) ||
it->state() != LookupIterator::INTERCEPTOR) {
it->Restart();
return Just(false);
}
} }
if (has_access && it->state() == LookupIterator::INTERCEPTOR) { if (it->state() == LookupIterator::INTERCEPTOR) {
Isolate* isolate = it->isolate(); Isolate* isolate = it->isolate();
Handle<InterceptorInfo> interceptor = it->GetInterceptor(); Handle<InterceptorInfo> interceptor = it->GetInterceptor();
if (!interceptor->descriptor()->IsUndefined(isolate)) { if (!interceptor->descriptor()->IsUndefined(isolate)) {
...@@ -7845,9 +7849,9 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it, ...@@ -7845,9 +7849,9 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
return Just(true); return Just(true);
} }
it->Next();
} }
} }
it->Restart();
return Just(false); return Just(false);
} }
} // namespace } // namespace
......
...@@ -4771,7 +4771,7 @@ TEST(NamedAllCanReadInterceptor) { ...@@ -4771,7 +4771,7 @@ TEST(NamedAllCanReadInterceptor) {
ExpectInt32("checked.whatever", 17); ExpectInt32("checked.whatever", 17);
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
->IsUndefined()); ->IsUndefined());
CHECK_EQ(6, access_check_data.count); CHECK_EQ(5, access_check_data.count);
access_check_data.result = false; access_check_data.result = false;
ExpectInt32("checked.whatever", intercept_data_0.value); ExpectInt32("checked.whatever", intercept_data_0.value);
...@@ -4780,7 +4780,7 @@ TEST(NamedAllCanReadInterceptor) { ...@@ -4780,7 +4780,7 @@ TEST(NamedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
} }
CHECK_EQ(9, access_check_data.count); CHECK_EQ(8, access_check_data.count);
intercept_data_1.should_intercept = true; intercept_data_1.should_intercept = true;
ExpectInt32("checked.whatever", intercept_data_1.value); ExpectInt32("checked.whatever", intercept_data_1.value);
...@@ -4789,7 +4789,7 @@ TEST(NamedAllCanReadInterceptor) { ...@@ -4789,7 +4789,7 @@ TEST(NamedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
} }
CHECK_EQ(12, access_check_data.count); CHECK_EQ(11, access_check_data.count);
g_access_check_data = nullptr; g_access_check_data = nullptr;
} }
...@@ -4858,7 +4858,7 @@ TEST(IndexedAllCanReadInterceptor) { ...@@ -4858,7 +4858,7 @@ TEST(IndexedAllCanReadInterceptor) {
ExpectInt32("checked[15]", 17); ExpectInt32("checked[15]", 17);
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
->IsUndefined()); ->IsUndefined());
CHECK_EQ(6, access_check_data.count); CHECK_EQ(5, access_check_data.count);
access_check_data.result = false; access_check_data.result = false;
ExpectInt32("checked[15]", intercept_data_0.value); ExpectInt32("checked[15]", intercept_data_0.value);
...@@ -4867,7 +4867,7 @@ TEST(IndexedAllCanReadInterceptor) { ...@@ -4867,7 +4867,7 @@ TEST(IndexedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
} }
CHECK_EQ(9, access_check_data.count); CHECK_EQ(8, access_check_data.count);
intercept_data_1.should_intercept = true; intercept_data_1.should_intercept = true;
ExpectInt32("checked[15]", intercept_data_1.value); ExpectInt32("checked[15]", intercept_data_1.value);
...@@ -4876,7 +4876,7 @@ TEST(IndexedAllCanReadInterceptor) { ...@@ -4876,7 +4876,7 @@ TEST(IndexedAllCanReadInterceptor) {
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
} }
CHECK_EQ(12, access_check_data.count); CHECK_EQ(11, access_check_data.count);
g_access_check_data = nullptr; g_access_check_data = nullptr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment