From f559a984c77ad71edb7af3769db2f1c7aff6c16e Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sat, 18 Aug 2018 13:41:43 -0400 Subject: [PATCH] deps: cherry-pick 9eb96bb from upstream V8 Original commit message: [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 Reviewed-by: Jakob Kummerow Reviewed-by: Benedikt Meurer Cr-Commit-Position: refs/heads/master@{#54492} PR-URL: https://github.com/nodejs/node/pull/22390 Fixes: https://github.com/nodejs/node/issues/17480 Fixes: https://github.com/nodejs/node/issues/17481 Refs: https://github.com/v8/v8/commit/9eb96bb431a52568c4964dee03569eef431a4dfa Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan Reviewed-By: James M Snell --- common.gypi | 2 +- deps/v8/src/objects.cc | 14 +++++++++----- deps/v8/test/cctest/test-api-interceptors.cc | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/common.gypi b/common.gypi index 3d3246a7105823..db9401ffa1a77a 100644 --- a/common.gypi +++ b/common.gypi @@ -29,7 +29,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.15', + 'v8_embedder_string': '-node.16', # Enable disassembler for `--print-code` v8 options 'v8_enable_disassembler': 1, diff --git a/deps/v8/src/objects.cc b/deps/v8/src/objects.cc index 80442d5bd89ba1..5c43a911a9f12a 100644 --- a/deps/v8/src/objects.cc +++ b/deps/v8/src/objects.cc @@ -7662,13 +7662,17 @@ namespace { Maybe GetPropertyDescriptorWithInterceptor(LookupIterator* it, PropertyDescriptor* desc) { - bool has_access = true; if (it->state() == LookupIterator::ACCESS_CHECK) { - has_access = it->HasAccess() || JSObject::AllCanRead(it); - it->Next(); + if (it->HasAccess()) { + 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(); Handle interceptor = it->GetInterceptor(); if (!interceptor->descriptor()->IsUndefined(isolate)) { @@ -7700,9 +7704,9 @@ Maybe GetPropertyDescriptorWithInterceptor(LookupIterator* it, return Just(true); } + it->Next(); } } - it->Restart(); return Just(false); } } // namespace diff --git a/deps/v8/test/cctest/test-api-interceptors.cc b/deps/v8/test/cctest/test-api-interceptors.cc index 9a5734a9502070..f1dba643fc08f2 100644 --- a/deps/v8/test/cctest/test-api-interceptors.cc +++ b/deps/v8/test/cctest/test-api-interceptors.cc @@ -4768,7 +4768,7 @@ TEST(NamedAllCanReadInterceptor) { ExpectInt32("checked.whatever", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") ->IsUndefined()); - CHECK_EQ(6, access_check_data.count); + CHECK_EQ(5, access_check_data.count); access_check_data.result = false; ExpectInt32("checked.whatever", intercept_data_0.value); @@ -4777,7 +4777,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(8, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked.whatever", intercept_data_1.value); @@ -4786,7 +4786,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(12, access_check_data.count); + CHECK_EQ(11, access_check_data.count); g_access_check_data = nullptr; } @@ -4855,7 +4855,7 @@ TEST(IndexedAllCanReadInterceptor) { ExpectInt32("checked[15]", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") ->IsUndefined()); - CHECK_EQ(6, access_check_data.count); + CHECK_EQ(5, access_check_data.count); access_check_data.result = false; ExpectInt32("checked[15]", intercept_data_0.value); @@ -4864,7 +4864,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(8, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked[15]", intercept_data_1.value); @@ -4873,7 +4873,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(12, access_check_data.count); + CHECK_EQ(11, access_check_data.count); g_access_check_data = nullptr; }