@@ -607,6 +607,50 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {
607
607
608
608
CHECK_EQ (set_was_called, false );
609
609
}
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
+ }
610
654
611
655
612
656
namespace {
@@ -4578,7 +4622,7 @@ TEST(NamedAllCanReadInterceptor) {
4578
4622
ExpectInt32 (" checked.whatever" , 17 );
4579
4623
CHECK (!CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" )
4580
4624
->IsUndefined ());
4581
- CHECK_EQ (5 , access_check_data.count );
4625
+ CHECK_EQ (6 , access_check_data.count );
4582
4626
4583
4627
access_check_data.result = false ;
4584
4628
ExpectInt32 (" checked.whatever" , intercept_data_0.value );
@@ -4587,7 +4631,7 @@ TEST(NamedAllCanReadInterceptor) {
4587
4631
CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" );
4588
4632
CHECK (try_catch.HasCaught ());
4589
4633
}
4590
- CHECK_EQ (7 , access_check_data.count );
4634
+ CHECK_EQ (9 , access_check_data.count );
4591
4635
4592
4636
intercept_data_1.should_intercept = true ;
4593
4637
ExpectInt32 (" checked.whatever" , intercept_data_1.value );
@@ -4596,7 +4640,7 @@ TEST(NamedAllCanReadInterceptor) {
4596
4640
CompileRun (" Object.getOwnPropertyDescriptor(checked, 'whatever')" );
4597
4641
CHECK (try_catch.HasCaught ());
4598
4642
}
4599
- CHECK_EQ (9 , access_check_data.count );
4643
+ CHECK_EQ (12 , access_check_data.count );
4600
4644
g_access_check_data = nullptr ;
4601
4645
}
4602
4646
@@ -4665,7 +4709,7 @@ TEST(IndexedAllCanReadInterceptor) {
4665
4709
ExpectInt32 (" checked[15]" , 17 );
4666
4710
CHECK (!CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" )
4667
4711
->IsUndefined ());
4668
- CHECK_EQ (5 , access_check_data.count );
4712
+ CHECK_EQ (6 , access_check_data.count );
4669
4713
4670
4714
access_check_data.result = false ;
4671
4715
ExpectInt32 (" checked[15]" , intercept_data_0.value );
@@ -4674,7 +4718,7 @@ TEST(IndexedAllCanReadInterceptor) {
4674
4718
CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" );
4675
4719
CHECK (try_catch.HasCaught ());
4676
4720
}
4677
- CHECK_EQ (7 , access_check_data.count );
4721
+ CHECK_EQ (9 , access_check_data.count );
4678
4722
4679
4723
intercept_data_1.should_intercept = true ;
4680
4724
ExpectInt32 (" checked[15]" , intercept_data_1.value );
@@ -4683,7 +4727,7 @@ TEST(IndexedAllCanReadInterceptor) {
4683
4727
CompileRun (" Object.getOwnPropertyDescriptor(checked, '15')" );
4684
4728
CHECK (try_catch.HasCaught ());
4685
4729
}
4686
- CHECK_EQ (9 , access_check_data.count );
4730
+ CHECK_EQ (12 , access_check_data.count );
4687
4731
4688
4732
g_access_check_data = nullptr ;
4689
4733
}
0 commit comments