Skip to content

Commit 9eb96bb

Browse files
TimothyGuCommit Bot
authored andcommitted
[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 <[email protected]> Reviewed-by: Jakob Kummerow <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]> Cr-Commit-Position: refs/heads/master@{#54492}
1 parent 8fa1668 commit 9eb96bb

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/objects.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7807,13 +7807,17 @@ namespace {
78077807

78087808
Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
78097809
PropertyDescriptor* desc) {
7810-
bool has_access = true;
78117810
if (it->state() == LookupIterator::ACCESS_CHECK) {
7812-
has_access = it->HasAccess() || JSObject::AllCanRead(it);
7813-
it->Next();
7811+
if (it->HasAccess()) {
7812+
it->Next();
7813+
} else if (!JSObject::AllCanRead(it) ||
7814+
it->state() != LookupIterator::INTERCEPTOR) {
7815+
it->Restart();
7816+
return Just(false);
7817+
}
78147818
}
78157819

7816-
if (has_access && it->state() == LookupIterator::INTERCEPTOR) {
7820+
if (it->state() == LookupIterator::INTERCEPTOR) {
78177821
Isolate* isolate = it->isolate();
78187822
Handle<InterceptorInfo> interceptor = it->GetInterceptor();
78197823
if (!interceptor->descriptor()->IsUndefined(isolate)) {
@@ -7845,9 +7849,9 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
78457849

78467850
return Just(true);
78477851
}
7852+
it->Next();
78487853
}
78497854
}
7850-
it->Restart();
78517855
return Just(false);
78527856
}
78537857
} // namespace

test/cctest/test-api-interceptors.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,7 +4771,7 @@ TEST(NamedAllCanReadInterceptor) {
47714771
ExpectInt32("checked.whatever", 17);
47724772
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
47734773
->IsUndefined());
4774-
CHECK_EQ(6, access_check_data.count);
4774+
CHECK_EQ(5, access_check_data.count);
47754775

47764776
access_check_data.result = false;
47774777
ExpectInt32("checked.whatever", intercept_data_0.value);
@@ -4780,7 +4780,7 @@ TEST(NamedAllCanReadInterceptor) {
47804780
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
47814781
CHECK(try_catch.HasCaught());
47824782
}
4783-
CHECK_EQ(9, access_check_data.count);
4783+
CHECK_EQ(8, access_check_data.count);
47844784

47854785
intercept_data_1.should_intercept = true;
47864786
ExpectInt32("checked.whatever", intercept_data_1.value);
@@ -4789,7 +4789,7 @@ TEST(NamedAllCanReadInterceptor) {
47894789
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
47904790
CHECK(try_catch.HasCaught());
47914791
}
4792-
CHECK_EQ(12, access_check_data.count);
4792+
CHECK_EQ(11, access_check_data.count);
47934793
g_access_check_data = nullptr;
47944794
}
47954795

@@ -4858,7 +4858,7 @@ TEST(IndexedAllCanReadInterceptor) {
48584858
ExpectInt32("checked[15]", 17);
48594859
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
48604860
->IsUndefined());
4861-
CHECK_EQ(6, access_check_data.count);
4861+
CHECK_EQ(5, access_check_data.count);
48624862

48634863
access_check_data.result = false;
48644864
ExpectInt32("checked[15]", intercept_data_0.value);
@@ -4867,7 +4867,7 @@ TEST(IndexedAllCanReadInterceptor) {
48674867
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
48684868
CHECK(try_catch.HasCaught());
48694869
}
4870-
CHECK_EQ(9, access_check_data.count);
4870+
CHECK_EQ(8, access_check_data.count);
48714871

48724872
intercept_data_1.should_intercept = true;
48734873
ExpectInt32("checked[15]", intercept_data_1.value);
@@ -4876,7 +4876,7 @@ TEST(IndexedAllCanReadInterceptor) {
48764876
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
48774877
CHECK(try_catch.HasCaught());
48784878
}
4879-
CHECK_EQ(12, access_check_data.count);
4879+
CHECK_EQ(11, access_check_data.count);
48804880

48814881
g_access_check_data = nullptr;
48824882
}

0 commit comments

Comments
 (0)