@@ -609,6 +609,50 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {
609
609
610
610
CHECK_EQ (set_was_called, false );
611
611
}
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
+ }
612
656
613
657
bool get_was_called_in_order = false ;
614
658
bool define_was_called_in_order = false ;
@@ -4516,7 +4560,7 @@ TEST(NamedAllCanReadInterceptor) {
4516
4560
ExpectInt32 (" checked.whatever" , 17 );
4517
4561
CHECK (!CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" )
4518
4562
->IsUndefined ());
4519
- CHECK_EQ (5 , access_check_data.count );
4563
+ CHECK_EQ (6 , access_check_data.count );
4520
4564
4521
4565
access_check_data.result = false ;
4522
4566
ExpectInt32 (" checked.whatever" , intercept_data_0.value );
@@ -4525,7 +4569,7 @@ TEST(NamedAllCanReadInterceptor) {
4525
4569
CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" );
4526
4570
CHECK (try_catch.HasCaught ());
4527
4571
}
4528
- CHECK_EQ (7 , access_check_data.count );
4572
+ CHECK_EQ (9 , access_check_data.count );
4529
4573
4530
4574
intercept_data_1.should_intercept = true ;
4531
4575
ExpectInt32 (" checked.whatever" , intercept_data_1.value );
@@ -4534,7 +4578,7 @@ TEST(NamedAllCanReadInterceptor) {
4534
4578
CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" );
4535
4579
CHECK (try_catch.HasCaught ());
4536
4580
}
4537
- CHECK_EQ (9 , access_check_data.count );
4581
+ CHECK_EQ (12 , access_check_data.count );
4538
4582
g_access_check_data = nullptr ;
4539
4583
}
4540
4584
@@ -4603,7 +4647,7 @@ TEST(IndexedAllCanReadInterceptor) {
4603
4647
ExpectInt32 (" checked[15]" , 17 );
4604
4648
CHECK (!CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" )
4605
4649
->IsUndefined ());
4606
- CHECK_EQ (5 , access_check_data.count );
4650
+ CHECK_EQ (6 , access_check_data.count );
4607
4651
4608
4652
access_check_data.result = false ;
4609
4653
ExpectInt32 (" checked[15]" , intercept_data_0.value );
@@ -4612,7 +4656,7 @@ TEST(IndexedAllCanReadInterceptor) {
4612
4656
CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" );
4613
4657
CHECK (try_catch.HasCaught ());
4614
4658
}
4615
- CHECK_EQ (7 , access_check_data.count );
4659
+ CHECK_EQ (9 , access_check_data.count );
4616
4660
4617
4661
intercept_data_1.should_intercept = true ;
4618
4662
ExpectInt32 (" checked[15]" , intercept_data_1.value );
@@ -4621,7 +4665,7 @@ TEST(IndexedAllCanReadInterceptor) {
4621
4665
CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" );
4622
4666
CHECK (try_catch.HasCaught ());
4623
4667
}
4624
- CHECK_EQ (9 , access_check_data.count );
4668
+ CHECK_EQ (12 , access_check_data.count );
4625
4669
4626
4670
g_access_check_data = nullptr ;
4627
4671
}
0 commit comments