Skip to content

Commit a44aff4

Browse files
committed
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 c7e8aff commit a44aff4

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 5
1212
#define V8_MINOR_VERSION 6
1313
#define V8_BUILD_NUMBER 326
14-
#define V8_PATCH_LEVEL 55
14+
#define V8_PATCH_LEVEL 56
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/objects.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -7330,7 +7330,13 @@ namespace {
73307330

73317331
Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
73327332
PropertyDescriptor* desc) {
7333-
if (it->state() == LookupIterator::INTERCEPTOR) {
7333+
bool has_access = true;
7334+
if (it->state() == LookupIterator::ACCESS_CHECK) {
7335+
has_access = it->HasAccess() || JSObject::AllCanRead(it);
7336+
it->Next();
7337+
}
7338+
7339+
if (has_access && it->state() == LookupIterator::INTERCEPTOR) {
73347340
Isolate* isolate = it->isolate();
73357341
Handle<InterceptorInfo> interceptor = it->GetInterceptor();
73367342
if (!interceptor->descriptor()->IsUndefined(isolate)) {
@@ -7374,6 +7380,7 @@ Maybe<bool> GetPropertyDescriptorWithInterceptor(LookupIterator* it,
73747380
}
73757381
}
73767382
}
7383+
it->Restart();
73777384
return Just(false);
73787385
}
73797386
} // namespace

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

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

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

613657
bool get_was_called_in_order = false;
614658
bool define_was_called_in_order = false;
@@ -4516,7 +4560,7 @@ TEST(NamedAllCanReadInterceptor) {
45164560
ExpectInt32("checked.whatever", 17);
45174561
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')")
45184562
->IsUndefined());
4519-
CHECK_EQ(5, access_check_data.count);
4563+
CHECK_EQ(6, access_check_data.count);
45204564

45214565
access_check_data.result = false;
45224566
ExpectInt32("checked.whatever", intercept_data_0.value);
@@ -4525,7 +4569,7 @@ TEST(NamedAllCanReadInterceptor) {
45254569
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
45264570
CHECK(try_catch.HasCaught());
45274571
}
4528-
CHECK_EQ(7, access_check_data.count);
4572+
CHECK_EQ(9, access_check_data.count);
45294573

45304574
intercept_data_1.should_intercept = true;
45314575
ExpectInt32("checked.whatever", intercept_data_1.value);
@@ -4534,7 +4578,7 @@ TEST(NamedAllCanReadInterceptor) {
45344578
CompileRun("Object.getOwnPropertyDescriptor(checked, 'whatever')");
45354579
CHECK(try_catch.HasCaught());
45364580
}
4537-
CHECK_EQ(9, access_check_data.count);
4581+
CHECK_EQ(12, access_check_data.count);
45384582
g_access_check_data = nullptr;
45394583
}
45404584

@@ -4603,7 +4647,7 @@ TEST(IndexedAllCanReadInterceptor) {
46034647
ExpectInt32("checked[15]", 17);
46044648
CHECK(!CompileRun("Object.getOwnPropertyDescriptor(checked, '15')")
46054649
->IsUndefined());
4606-
CHECK_EQ(5, access_check_data.count);
4650+
CHECK_EQ(6, access_check_data.count);
46074651

46084652
access_check_data.result = false;
46094653
ExpectInt32("checked[15]", intercept_data_0.value);
@@ -4612,7 +4656,7 @@ TEST(IndexedAllCanReadInterceptor) {
46124656
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
46134657
CHECK(try_catch.HasCaught());
46144658
}
4615-
CHECK_EQ(7, access_check_data.count);
4659+
CHECK_EQ(9, access_check_data.count);
46164660

46174661
intercept_data_1.should_intercept = true;
46184662
ExpectInt32("checked[15]", intercept_data_1.value);
@@ -4621,7 +4665,7 @@ TEST(IndexedAllCanReadInterceptor) {
46214665
CompileRun("Object.getOwnPropertyDescriptor(checked, '15')");
46224666
CHECK(try_catch.HasCaught());
46234667
}
4624-
CHECK_EQ(9, access_check_data.count);
4668+
CHECK_EQ(12, access_check_data.count);
46254669

46264670
g_access_check_data = nullptr;
46274671
}

0 commit comments

Comments
 (0)