@@ -49,6 +49,7 @@ using v8::FunctionTemplate;
49
49
using v8::HandleScope;
50
50
using v8::IndexedPropertyHandlerConfiguration;
51
51
using v8::Int32;
52
+ using v8::Intercepted;
52
53
using v8::Isolate;
53
54
using v8::Just;
54
55
using v8::Local;
@@ -459,13 +460,12 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) {
459
460
}
460
461
461
462
// static
462
- void ContextifyContext::PropertyGetterCallback (
463
- Local<Name> property,
464
- const PropertyCallbackInfo<Value>& args) {
463
+ Intercepted ContextifyContext::PropertyGetterCallback (
464
+ Local<Name> property, const PropertyCallbackInfo<Value>& args) {
465
465
ContextifyContext* ctx = ContextifyContext::Get (args);
466
466
467
467
// Still initializing
468
- if (IsStillInitializing (ctx)) return ;
468
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
469
469
470
470
Local<Context> context = ctx->context ();
471
471
Local<Object> sandbox = ctx->sandbox ();
@@ -482,18 +482,20 @@ void ContextifyContext::PropertyGetterCallback(
482
482
rv = ctx->global_proxy ();
483
483
484
484
args.GetReturnValue ().Set (rv);
485
+ return Intercepted::kYes ;
485
486
}
487
+ return Intercepted::kNo ;
486
488
}
487
489
488
490
// static
489
- void ContextifyContext::PropertySetterCallback (
491
+ Intercepted ContextifyContext::PropertySetterCallback (
490
492
Local<Name> property,
491
493
Local<Value> value,
492
- const PropertyCallbackInfo<Value >& args) {
494
+ const PropertyCallbackInfo<void >& args) {
493
495
ContextifyContext* ctx = ContextifyContext::Get (args);
494
496
495
497
// Still initializing
496
- if (IsStillInitializing (ctx)) return ;
498
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
497
499
498
500
Local<Context> context = ctx->context ();
499
501
PropertyAttribute attributes = PropertyAttribute::None;
@@ -511,8 +513,7 @@ void ContextifyContext::PropertySetterCallback(
511
513
(static_cast <int >(attributes) &
512
514
static_cast <int >(PropertyAttribute::ReadOnly));
513
515
514
- if (read_only)
515
- return ;
516
+ if (read_only) return Intercepted::kNo ;
516
517
517
518
// true for x = 5
518
519
// false for this.x = 5
@@ -532,10 +533,11 @@ void ContextifyContext::PropertySetterCallback(
532
533
bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox;
533
534
if (!is_declared && args.ShouldThrowOnError () && is_contextual_store &&
534
535
!is_function)
535
- return ;
536
+ return Intercepted:: kNo ;
536
537
537
- if (!is_declared && property->IsSymbol ()) return ;
538
- if (ctx->sandbox ()->Set (context, property, value).IsNothing ()) return ;
538
+ if (!is_declared && property->IsSymbol ()) return Intercepted::kNo ;
539
+ if (ctx->sandbox ()->Set (context, property, value).IsNothing ())
540
+ return Intercepted::kNo ;
539
541
540
542
Local<Value> desc;
541
543
if (is_declared_on_sandbox &&
@@ -549,19 +551,21 @@ void ContextifyContext::PropertySetterCallback(
549
551
// We have to specify the return value for any contextual or get/set
550
552
// property
551
553
if (desc_obj->HasOwnProperty (context, env->get_string ()).FromMaybe (false ) ||
552
- desc_obj->HasOwnProperty (context, env->set_string ()).FromMaybe (false ))
554
+ desc_obj->HasOwnProperty (context, env->set_string ()).FromMaybe (false )) {
553
555
args.GetReturnValue ().Set (value);
556
+ return Intercepted::kYes ;
557
+ }
554
558
}
559
+ return Intercepted::kNo ;
555
560
}
556
561
557
562
// static
558
- void ContextifyContext::PropertyDescriptorCallback (
559
- Local<Name> property,
560
- const PropertyCallbackInfo<Value>& args) {
563
+ Intercepted ContextifyContext::PropertyDescriptorCallback (
564
+ Local<Name> property, const PropertyCallbackInfo<Value>& args) {
561
565
ContextifyContext* ctx = ContextifyContext::Get (args);
562
566
563
567
// Still initializing
564
- if (IsStillInitializing (ctx)) return ;
568
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
565
569
566
570
Local<Context> context = ctx->context ();
567
571
@@ -571,19 +575,21 @@ void ContextifyContext::PropertyDescriptorCallback(
571
575
Local<Value> desc;
572
576
if (sandbox->GetOwnPropertyDescriptor (context, property).ToLocal (&desc)) {
573
577
args.GetReturnValue ().Set (desc);
578
+ return Intercepted::kYes ;
574
579
}
575
580
}
581
+ return Intercepted::kNo ;
576
582
}
577
583
578
584
// static
579
- void ContextifyContext::PropertyDefinerCallback (
585
+ Intercepted ContextifyContext::PropertyDefinerCallback (
580
586
Local<Name> property,
581
587
const PropertyDescriptor& desc,
582
- const PropertyCallbackInfo<Value >& args) {
588
+ const PropertyCallbackInfo<void >& args) {
583
589
ContextifyContext* ctx = ContextifyContext::Get (args);
584
590
585
591
// Still initializing
586
- if (IsStillInitializing (ctx)) return ;
592
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
587
593
588
594
Local<Context> context = ctx->context ();
589
595
Isolate* isolate = context->GetIsolate ();
@@ -602,7 +608,7 @@ void ContextifyContext::PropertyDefinerCallback(
602
608
// If the property is set on the global as neither writable nor
603
609
// configurable, don't change it on the global or sandbox.
604
610
if (is_declared && read_only && dont_delete) {
605
- return ;
611
+ return Intercepted:: kNo ;
606
612
}
607
613
608
614
Local<Object> sandbox = ctx->sandbox ();
@@ -625,6 +631,9 @@ void ContextifyContext::PropertyDefinerCallback(
625
631
desc.has_set () ? desc.set () : Undefined (isolate).As <Value>());
626
632
627
633
define_prop_on_sandbox (&desc_for_sandbox);
634
+ // TODO(https://github.com/nodejs/node/issues/52634): this should return
635
+ // kYes to behave according to the expected semantics.
636
+ return Intercepted::kNo ;
628
637
} else {
629
638
Local<Value> value =
630
639
desc.has_value () ? desc.value () : Undefined (isolate).As <Value>();
@@ -636,26 +645,29 @@ void ContextifyContext::PropertyDefinerCallback(
636
645
PropertyDescriptor desc_for_sandbox (value);
637
646
define_prop_on_sandbox (&desc_for_sandbox);
638
647
}
648
+ // TODO(https://github.com/nodejs/node/issues/52634): this should return
649
+ // kYes to behave according to the expected semantics.
650
+ return Intercepted::kNo ;
639
651
}
652
+ return Intercepted::kNo ;
640
653
}
641
654
642
655
// static
643
- void ContextifyContext::PropertyDeleterCallback (
644
- Local<Name> property,
645
- const PropertyCallbackInfo<Boolean >& args) {
656
+ Intercepted ContextifyContext::PropertyDeleterCallback (
657
+ Local<Name> property, const PropertyCallbackInfo<Boolean >& args) {
646
658
ContextifyContext* ctx = ContextifyContext::Get (args);
647
659
648
660
// Still initializing
649
- if (IsStillInitializing (ctx)) return ;
661
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
650
662
651
663
Maybe<bool > success = ctx->sandbox ()->Delete (ctx->context (), property);
652
664
653
- if (success.FromMaybe (false ))
654
- return ;
665
+ if (success.FromMaybe (false )) return Intercepted::kNo ;
655
666
656
667
// Delete failed on the sandbox, intercept and do not delete on
657
668
// the global object.
658
669
args.GetReturnValue ().Set (false );
670
+ return Intercepted::kYes ;
659
671
}
660
672
661
673
// static
@@ -675,76 +687,71 @@ void ContextifyContext::PropertyEnumeratorCallback(
675
687
}
676
688
677
689
// static
678
- void ContextifyContext::IndexedPropertyGetterCallback (
679
- uint32_t index,
680
- const PropertyCallbackInfo<Value>& args) {
690
+ Intercepted ContextifyContext::IndexedPropertyGetterCallback (
691
+ uint32_t index, const PropertyCallbackInfo<Value>& args) {
681
692
ContextifyContext* ctx = ContextifyContext::Get (args);
682
693
683
694
// Still initializing
684
- if (IsStillInitializing (ctx)) return ;
695
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
685
696
686
- ContextifyContext::PropertyGetterCallback (
697
+ return ContextifyContext::PropertyGetterCallback (
687
698
Uint32ToName (ctx->context (), index ), args);
688
699
}
689
700
690
-
691
- void ContextifyContext::IndexedPropertySetterCallback (
701
+ Intercepted ContextifyContext::IndexedPropertySetterCallback (
692
702
uint32_t index,
693
703
Local<Value> value,
694
- const PropertyCallbackInfo<Value >& args) {
704
+ const PropertyCallbackInfo<void >& args) {
695
705
ContextifyContext* ctx = ContextifyContext::Get (args);
696
706
697
707
// Still initializing
698
- if (IsStillInitializing (ctx)) return ;
708
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
699
709
700
- ContextifyContext::PropertySetterCallback (
710
+ return ContextifyContext::PropertySetterCallback (
701
711
Uint32ToName (ctx->context (), index ), value, args);
702
712
}
703
713
704
714
// static
705
- void ContextifyContext::IndexedPropertyDescriptorCallback (
706
- uint32_t index,
707
- const PropertyCallbackInfo<Value>& args) {
715
+ Intercepted ContextifyContext::IndexedPropertyDescriptorCallback (
716
+ uint32_t index, const PropertyCallbackInfo<Value>& args) {
708
717
ContextifyContext* ctx = ContextifyContext::Get (args);
709
718
710
719
// Still initializing
711
- if (IsStillInitializing (ctx)) return ;
720
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
712
721
713
- ContextifyContext::PropertyDescriptorCallback (
722
+ return ContextifyContext::PropertyDescriptorCallback (
714
723
Uint32ToName (ctx->context (), index ), args);
715
724
}
716
725
717
-
718
- void ContextifyContext::IndexedPropertyDefinerCallback (
726
+ Intercepted ContextifyContext::IndexedPropertyDefinerCallback (
719
727
uint32_t index,
720
728
const PropertyDescriptor& desc,
721
- const PropertyCallbackInfo<Value >& args) {
729
+ const PropertyCallbackInfo<void >& args) {
722
730
ContextifyContext* ctx = ContextifyContext::Get (args);
723
731
724
732
// Still initializing
725
- if (IsStillInitializing (ctx)) return ;
733
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
726
734
727
- ContextifyContext::PropertyDefinerCallback (
735
+ return ContextifyContext::PropertyDefinerCallback (
728
736
Uint32ToName (ctx->context (), index ), desc, args);
729
737
}
730
738
731
739
// static
732
- void ContextifyContext::IndexedPropertyDeleterCallback (
733
- uint32_t index,
734
- const PropertyCallbackInfo<Boolean >& args) {
740
+ Intercepted ContextifyContext::IndexedPropertyDeleterCallback (
741
+ uint32_t index, const PropertyCallbackInfo<Boolean >& args) {
735
742
ContextifyContext* ctx = ContextifyContext::Get (args);
736
743
737
744
// Still initializing
738
- if (IsStillInitializing (ctx)) return ;
745
+ if (IsStillInitializing (ctx)) return Intercepted:: kNo ;
739
746
740
747
Maybe<bool > success = ctx->sandbox ()->Delete (ctx->context (), index );
741
748
742
- if (success.FromMaybe (false ))
743
- return ;
749
+ if (success.FromMaybe (false )) return Intercepted::kNo ;
744
750
745
751
// Delete failed on the sandbox, intercept and do not delete on
746
752
// the global object.
747
753
args.GetReturnValue ().Set (false );
754
+ return Intercepted::kYes ;
748
755
}
749
756
750
757
void ContextifyScript::CreatePerIsolateProperties (
0 commit comments