From 3471d6312df83151b7132841fcc76752ee4adf12 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Mon, 6 Mar 2017 12:46:20 +0100 Subject: [PATCH] deps: cherry-pick 0ba513f05 from V8 upstream Original commit message: [api] Fix DescriptorInterceptor with access check. The DescriptorInterceptor should intercept all Object.getOwnPropertyDescriptor calls. This CL fixes the interceptor's behavior if the iterator state is ACCESS_CHECK. BUG= Review-Url: https://codereview.chromium.org/2707263002 Cr-Commit-Position: refs/heads/master@{#43417} PR-URL: https://github.com/nodejs/node/pull/11712 Reviewed-By: Ben Noordhuis Reviewed-By: Myles Borins Reviewed-By: Ali Ijaz Sheikh Reviewed-By: James M Snell --- deps/v8/src/objects.cc | 9 +++- deps/v8/test/cctest/test-api-interceptors.cc | 56 +++++++++++++++++--- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/deps/v8/src/objects.cc b/deps/v8/src/objects.cc index 086d515625310c..fd2d34d743fb77 100644 --- a/deps/v8/src/objects.cc +++ b/deps/v8/src/objects.cc @@ -7008,7 +7008,13 @@ namespace { Maybe GetPropertyDescriptorWithInterceptor(LookupIterator* it, PropertyDescriptor* desc) { - if (it->state() == LookupIterator::INTERCEPTOR) { + bool has_access = true; + if (it->state() == LookupIterator::ACCESS_CHECK) { + has_access = it->HasAccess() || JSObject::AllCanRead(it); + it->Next(); + } + + if (has_access && it->state() == LookupIterator::INTERCEPTOR) { Isolate* isolate = it->isolate(); Handle interceptor = it->GetInterceptor(); if (!interceptor->descriptor()->IsUndefined(isolate)) { @@ -7052,6 +7058,7 @@ Maybe GetPropertyDescriptorWithInterceptor(LookupIterator* it, } } } + 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 6aebba67bc46a1..66f0a0b0eb4754 100644 --- a/deps/v8/test/cctest/test-api-interceptors.cc +++ b/deps/v8/test/cctest/test-api-interceptors.cc @@ -607,6 +607,50 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) { CHECK_EQ(set_was_called, false); } +namespace { +int descriptor_was_called; + +void PropertyDescriptorCallback( + Local name, const v8::PropertyCallbackInfo& info) { + // Intercept the callback by setting a different descriptor. + descriptor_was_called++; + const char* code = + "var desc = {value: 5};" + "desc;"; + Local descriptor = v8_compile(code) + ->Run(info.GetIsolate()->GetCurrentContext()) + .ToLocalChecked(); + info.GetReturnValue().Set(descriptor); +} +} // namespace + +// Check that the descriptor callback is called on the global object. +THREADED_TEST(DescriptorCallbackOnGlobalObject) { + v8::HandleScope scope(CcTest::isolate()); + LocalContext env; + v8::Local templ = + v8::FunctionTemplate::New(CcTest::isolate()); + + v8::Local object_template = templ->InstanceTemplate(); + object_template->SetHandler(v8::NamedPropertyHandlerConfiguration( + nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr)); + v8::Local ctx = + v8::Context::New(CcTest::isolate(), nullptr, object_template); + + descriptor_was_called = 0; + + // Declare function. + v8::Local code = v8_str( + "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); " + "desc.value;"); + CHECK_EQ(5, v8::Script::Compile(ctx, code) + .ToLocalChecked() + ->Run(ctx) + .ToLocalChecked() + ->Int32Value(ctx) + .FromJust()); + CHECK_EQ(1, descriptor_was_called); +} namespace { @@ -4578,7 +4622,7 @@ TEST(NamedAllCanReadInterceptor) { ExpectInt32("checked.whatever", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')") ->IsUndefined()); - CHECK_EQ(5, access_check_data.count); + CHECK_EQ(6, access_check_data.count); access_check_data.result = false; ExpectInt32("checked.whatever", intercept_data_0.value); @@ -4587,7 +4631,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(7, access_check_data.count); + CHECK_EQ(9, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked.whatever", intercept_data_1.value); @@ -4596,7 +4640,7 @@ TEST(NamedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(12, access_check_data.count); g_access_check_data = nullptr; } @@ -4665,7 +4709,7 @@ TEST(IndexedAllCanReadInterceptor) { ExpectInt32("checked[15]", 17); CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')") ->IsUndefined()); - CHECK_EQ(5, access_check_data.count); + CHECK_EQ(6, access_check_data.count); access_check_data.result = false; ExpectInt32("checked[15]", intercept_data_0.value); @@ -4674,7 +4718,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(7, access_check_data.count); + CHECK_EQ(9, access_check_data.count); intercept_data_1.should_intercept = true; ExpectInt32("checked[15]", intercept_data_1.value); @@ -4683,7 +4727,7 @@ TEST(IndexedAllCanReadInterceptor) { CompileRun("Object.getOwnPropertyDescriptor(checked, '15')"); CHECK(try_catch.HasCaught()); } - CHECK_EQ(9, access_check_data.count); + CHECK_EQ(12, access_check_data.count); g_access_check_data = nullptr; }