Skip to content

Commit 3471d63

Browse files
fhinkeltargos
authored andcommitted
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: #11712 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fcc58bf commit 3471d63

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

deps/v8/src/objects.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -7008,7 +7008,13 @@ namespace {
70087008

70097009
Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
70107010
PropertyDescriptor* desc) {
7011-
if (it->state() == LookupIterator::INTERCEPTOR) {
7011+
bool has_access = true;
7012+
if (it->state() == LookupIterator::ACCESS_CHECK) {
7013+
has_access = it->HasAccess() || JSObject::AllCanRead(it);
7014+
it->Next();
7015+
}
7016+
7017+
if (has_access && it->state() == LookupIterator::INTERCEPTOR) {
70127018
Isolate* isolate = it->isolate();
70137019
Handle<InterceptorInfo> interceptor = it->GetInterceptor();
70147020
if (!interceptor->descriptor()->IsUndefined(isolate)) {
@@ -7052,6 +7058,7 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
70527058
}
70537059
}
70547060
}
7061+
it->Restart();
70557062
return Just(false);
70567063
}
70577064
} // namespace

deps/v8/test/cctest/test-api-interceptors.cc

+50-6
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,50 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {
607607

608608
CHECK_EQ(set_was_called, false);
609609
}
610+
namespace {
611+
int descriptor_was_called;
612+
613+
void PropertyDescriptorCallback(
614+
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
615+
// Intercept the callback by setting a different descriptor.
616+
descriptor_was_called++;
617+
const char* code =
618+
"var desc = {value: 5};"
619+
"desc;";
620+
Local<Value> descriptor = v8_compile(code)
621+
->Run(info.GetIsolate()->GetCurrentContext())
622+
.ToLocalChecked();
623+
info.GetReturnValue().Set(descriptor);
624+
}
625+
} // namespace
626+
627+
// Check that the descriptor callback is called on the global object.
628+
THREADED_TEST(DescriptorCallbackOnGlobalObject) {
629+
v8::HandleScope scope(CcTest::isolate());
630+
LocalContext env;
631+
v8::Local<v8::FunctionTemplate> templ =
632+
v8::FunctionTemplate::New(CcTest::isolate());
633+
634+
v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
635+
object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
636+
nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr));
637+
v8::Local<v8::Context> ctx =
638+
v8::Context::New(CcTest::isolate(), nullptr, object_template);
639+
640+
descriptor_was_called = 0;
641+
642+
// Declare function.
643+
v8::Local<v8::String> code = v8_str(
644+
"var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); "
645+
"desc.value;");
646+
CHECK_EQ(5, v8::Script::Compile(ctx, code)
647+
.ToLocalChecked()
648+
->Run(ctx)
649+
.ToLocalChecked()
650+
->Int32Value(ctx)
651+
.FromJust());
652+
CHECK_EQ(1, descriptor_was_called);
653+
}
610654

611655

612656
namespace {
@@ -4578,7 +4622,7 @@ TEST(NamedAllCanReadInterceptor) {
45784622
ExpectInt32("checked.whatever", 17);
45794623
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
45804624
->IsUndefined());
4581-
CHECK_EQ(5, access_check_data.count);
4625+
CHECK_EQ(6, access_check_data.count);
45824626

45834627
access_check_data.result = false;
45844628
ExpectInt32("checked.whatever", intercept_data_0.value);
@@ -4587,7 +4631,7 @@ TEST(NamedAllCanReadInterceptor) {
45874631
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
45884632
CHECK(try_catch.HasCaught());
45894633
}
4590-
CHECK_EQ(7, access_check_data.count);
4634+
CHECK_EQ(9, access_check_data.count);
45914635

45924636
intercept_data_1.should_intercept = true;
45934637
ExpectInt32("checked.whatever", intercept_data_1.value);
@@ -4596,7 +4640,7 @@ TEST(NamedAllCanReadInterceptor) {
45964640
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
45974641
CHECK(try_catch.HasCaught());
45984642
}
4599-
CHECK_EQ(9, access_check_data.count);
4643+
CHECK_EQ(12, access_check_data.count);
46004644
g_access_check_data = nullptr;
46014645
}
46024646

@@ -4665,7 +4709,7 @@ TEST(IndexedAllCanReadInterceptor) {
46654709
ExpectInt32("checked[15]", 17);
46664710
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
46674711
->IsUndefined());
4668-
CHECK_EQ(5, access_check_data.count);
4712+
CHECK_EQ(6, access_check_data.count);
46694713

46704714
access_check_data.result = false;
46714715
ExpectInt32("checked[15]", intercept_data_0.value);
@@ -4674,7 +4718,7 @@ TEST(IndexedAllCanReadInterceptor) {
46744718
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
46754719
CHECK(try_catch.HasCaught());
46764720
}
4677-
CHECK_EQ(7, access_check_data.count);
4721+
CHECK_EQ(9, access_check_data.count);
46784722

46794723
intercept_data_1.should_intercept = true;
46804724
ExpectInt32("checked[15]", intercept_data_1.value);
@@ -4683,7 +4727,7 @@ TEST(IndexedAllCanReadInterceptor) {
46834727
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
46844728
CHECK(try_catch.HasCaught());
46854729
}
4686-
CHECK_EQ(9, access_check_data.count);
4730+
CHECK_EQ(12, access_check_data.count);
46874731

46884732
g_access_check_data = nullptr;
46894733
}

0 commit comments

Comments
 (0)