@@ -51,6 +51,7 @@ using v8::FunctionTemplate;
51
51
using v8::HandleScope;
52
52
using v8::IndexedPropertyHandlerConfiguration;
53
53
using v8::Int32;
54
+ using v8::Intercepted;
54
55
using v8::Isolate;
55
56
using v8::Just;
56
57
using v8::Local;
@@ -458,14 +459,15 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) {
458
459
}
459
460
460
461
// static
461
- void ContextifyContext::PropertyGetterCallback (
462
- Local<Name> property,
463
- const PropertyCallbackInfo<Value>& args) {
462
+ Intercepted ContextifyContext::PropertyGetterCallback (
463
+ Local<Name> property, const PropertyCallbackInfo<Value>& args) {
464
464
Environment* env = Environment::GetCurrent (args);
465
465
ContextifyContext* ctx = ContextifyContext::Get (args);
466
466
467
467
// Still initializing
468
- if (IsStillInitializing (ctx)) return ;
468
+ if (IsStillInitializing (ctx)) {
469
+ return Intercepted::kNo ;
470
+ }
469
471
470
472
Local<Context> context = ctx->context ();
471
473
Local<Object> sandbox = ctx->sandbox ();
@@ -487,18 +489,22 @@ void ContextifyContext::PropertyGetterCallback(
487
489
rv = ctx->global_proxy ();
488
490
489
491
args.GetReturnValue ().Set (rv);
492
+ return Intercepted::kYes ;
490
493
}
494
+ return Intercepted::kNo ;
491
495
}
492
496
493
497
// static
494
- void ContextifyContext::PropertySetterCallback (
498
+ Intercepted ContextifyContext::PropertySetterCallback (
495
499
Local<Name> property,
496
500
Local<Value> value,
497
- const PropertyCallbackInfo<Value >& args) {
501
+ const PropertyCallbackInfo<void >& args) {
498
502
ContextifyContext* ctx = ContextifyContext::Get (args);
499
503
500
504
// Still initializing
501
- if (IsStillInitializing (ctx)) return ;
505
+ if (IsStillInitializing (ctx)) {
506
+ return Intercepted::kNo ;
507
+ }
502
508
503
509
Local<Context> context = ctx->context ();
504
510
PropertyAttribute attributes = PropertyAttribute::None;
@@ -516,8 +522,9 @@ void ContextifyContext::PropertySetterCallback(
516
522
(static_cast <int >(attributes) &
517
523
static_cast <int >(PropertyAttribute::ReadOnly));
518
524
519
- if (read_only)
520
- return ;
525
+ if (read_only) {
526
+ return Intercepted::kNo ;
527
+ }
521
528
522
529
// true for x = 5
523
530
// false for this.x = 5
@@ -536,11 +543,16 @@ void ContextifyContext::PropertySetterCallback(
536
543
537
544
bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox;
538
545
if (!is_declared && args.ShouldThrowOnError () && is_contextual_store &&
539
- !is_function)
540
- return ;
546
+ !is_function) {
547
+ return Intercepted::kNo ;
548
+ }
541
549
542
- if (!is_declared && property->IsSymbol ()) return ;
543
- if (ctx->sandbox ()->Set (context, property, value).IsNothing ()) return ;
550
+ if (!is_declared && property->IsSymbol ()) {
551
+ return Intercepted::kNo ;
552
+ }
553
+ if (ctx->sandbox ()->Set (context, property, value).IsNothing ()) {
554
+ return Intercepted::kNo ;
555
+ }
544
556
545
557
Local<Value> desc;
546
558
if (is_declared_on_sandbox &&
@@ -554,19 +566,23 @@ void ContextifyContext::PropertySetterCallback(
554
566
// We have to specify the return value for any contextual or get/set
555
567
// property
556
568
if (desc_obj->HasOwnProperty (context, env->get_string ()).FromMaybe (false ) ||
557
- desc_obj->HasOwnProperty (context, env->set_string ()).FromMaybe (false ))
569
+ desc_obj->HasOwnProperty (context, env->set_string ()).FromMaybe (false )) {
558
570
args.GetReturnValue ().Set (value);
571
+ return Intercepted::kYes ;
572
+ }
559
573
}
574
+ return Intercepted::kNo ;
560
575
}
561
576
562
577
// static
563
- void ContextifyContext::PropertyDescriptorCallback (
564
- Local<Name> property,
565
- const PropertyCallbackInfo<Value>& args) {
578
+ Intercepted ContextifyContext::PropertyDescriptorCallback (
579
+ Local<Name> property, const PropertyCallbackInfo<Value>& args) {
566
580
ContextifyContext* ctx = ContextifyContext::Get (args);
567
581
568
582
// Still initializing
569
- if (IsStillInitializing (ctx)) return ;
583
+ if (IsStillInitializing (ctx)) {
584
+ return Intercepted::kNo ;
585
+ }
570
586
571
587
Local<Context> context = ctx->context ();
572
588
@@ -576,19 +592,23 @@ void ContextifyContext::PropertyDescriptorCallback(
576
592
Local<Value> desc;
577
593
if (sandbox->GetOwnPropertyDescriptor (context, property).ToLocal (&desc)) {
578
594
args.GetReturnValue ().Set (desc);
595
+ return Intercepted::kYes ;
579
596
}
580
597
}
598
+ return Intercepted::kNo ;
581
599
}
582
600
583
601
// static
584
- void ContextifyContext::PropertyDefinerCallback (
602
+ Intercepted ContextifyContext::PropertyDefinerCallback (
585
603
Local<Name> property,
586
604
const PropertyDescriptor& desc,
587
- const PropertyCallbackInfo<Value >& args) {
605
+ const PropertyCallbackInfo<void >& args) {
588
606
ContextifyContext* ctx = ContextifyContext::Get (args);
589
607
590
608
// Still initializing
591
- if (IsStillInitializing (ctx)) return ;
609
+ if (IsStillInitializing (ctx)) {
610
+ return Intercepted::kNo ;
611
+ }
592
612
593
613
Local<Context> context = ctx->context ();
594
614
Isolate* isolate = context->GetIsolate ();
@@ -607,7 +627,7 @@ void ContextifyContext::PropertyDefinerCallback(
607
627
// If the property is set on the global as neither writable nor
608
628
// configurable, don't change it on the global or sandbox.
609
629
if (is_declared && read_only && dont_delete) {
610
- return ;
630
+ return Intercepted:: kNo ;
611
631
}
612
632
613
633
Local<Object> sandbox = ctx->sandbox ();
@@ -630,6 +650,9 @@ void ContextifyContext::PropertyDefinerCallback(
630
650
desc.has_set () ? desc.set () : Undefined (isolate).As <Value>());
631
651
632
652
define_prop_on_sandbox (&desc_for_sandbox);
653
+ // TODO(https://github.com/nodejs/node/issues/52634): this should return
654
+ // kYes to behave according to the expected semantics.
655
+ return Intercepted::kNo ;
633
656
} else {
634
657
Local<Value> value =
635
658
desc.has_value () ? desc.value () : Undefined (isolate).As <Value>();
@@ -641,26 +664,33 @@ void ContextifyContext::PropertyDefinerCallback(
641
664
PropertyDescriptor desc_for_sandbox (value);
642
665
define_prop_on_sandbox (&desc_for_sandbox);
643
666
}
667
+ // TODO(https://github.com/nodejs/node/issues/52634): this should return
668
+ // kYes to behave according to the expected semantics.
669
+ return Intercepted::kNo ;
644
670
}
671
+ return Intercepted::kNo ;
645
672
}
646
673
647
674
// static
648
- void ContextifyContext::PropertyDeleterCallback (
649
- Local<Name> property,
650
- const PropertyCallbackInfo<Boolean >& args) {
675
+ Intercepted ContextifyContext::PropertyDeleterCallback (
676
+ Local<Name> property, const PropertyCallbackInfo<Boolean >& args) {
651
677
ContextifyContext* ctx = ContextifyContext::Get (args);
652
678
653
679
// Still initializing
654
- if (IsStillInitializing (ctx)) return ;
680
+ if (IsStillInitializing (ctx)) {
681
+ return Intercepted::kNo ;
682
+ }
655
683
656
684
Maybe<bool > success = ctx->sandbox ()->Delete (ctx->context (), property);
657
685
658
- if (success.FromMaybe (false ))
659
- return ;
686
+ if (success.FromMaybe (false )) {
687
+ return Intercepted::kNo ;
688
+ }
660
689
661
690
// Delete failed on the sandbox, intercept and do not delete on
662
691
// the global object.
663
692
args.GetReturnValue ().Set (false );
693
+ return Intercepted::kYes ;
664
694
}
665
695
666
696
// static
@@ -680,76 +710,83 @@ void ContextifyContext::PropertyEnumeratorCallback(
680
710
}
681
711
682
712
// static
683
- void ContextifyContext::IndexedPropertyGetterCallback (
684
- uint32_t index,
685
- const PropertyCallbackInfo<Value>& args) {
713
+ Intercepted ContextifyContext::IndexedPropertyGetterCallback (
714
+ uint32_t index, const PropertyCallbackInfo<Value>& args) {
686
715
ContextifyContext* ctx = ContextifyContext::Get (args);
687
716
688
717
// Still initializing
689
- if (IsStillInitializing (ctx)) return ;
718
+ if (IsStillInitializing (ctx)) {
719
+ return Intercepted::kNo ;
720
+ }
690
721
691
- ContextifyContext::PropertyGetterCallback (
722
+ return ContextifyContext::PropertyGetterCallback (
692
723
Uint32ToName (ctx->context (), index ), args);
693
724
}
694
725
695
-
696
- void ContextifyContext::IndexedPropertySetterCallback (
726
+ Intercepted ContextifyContext::IndexedPropertySetterCallback (
697
727
uint32_t index,
698
728
Local<Value> value,
699
- const PropertyCallbackInfo<Value >& args) {
729
+ const PropertyCallbackInfo<void >& args) {
700
730
ContextifyContext* ctx = ContextifyContext::Get (args);
701
731
702
732
// Still initializing
703
- if (IsStillInitializing (ctx)) return ;
733
+ if (IsStillInitializing (ctx)) {
734
+ return Intercepted::kNo ;
735
+ }
704
736
705
- ContextifyContext::PropertySetterCallback (
737
+ return ContextifyContext::PropertySetterCallback (
706
738
Uint32ToName (ctx->context (), index ), value, args);
707
739
}
708
740
709
741
// static
710
- void ContextifyContext::IndexedPropertyDescriptorCallback (
711
- uint32_t index,
712
- const PropertyCallbackInfo<Value>& args) {
742
+ Intercepted ContextifyContext::IndexedPropertyDescriptorCallback (
743
+ uint32_t index, const PropertyCallbackInfo<Value>& args) {
713
744
ContextifyContext* ctx = ContextifyContext::Get (args);
714
745
715
746
// Still initializing
716
- if (IsStillInitializing (ctx)) return ;
747
+ if (IsStillInitializing (ctx)) {
748
+ return Intercepted::kNo ;
749
+ }
717
750
718
- ContextifyContext::PropertyDescriptorCallback (
751
+ return ContextifyContext::PropertyDescriptorCallback (
719
752
Uint32ToName (ctx->context (), index ), args);
720
753
}
721
754
722
-
723
- void ContextifyContext::IndexedPropertyDefinerCallback (
755
+ Intercepted ContextifyContext::IndexedPropertyDefinerCallback (
724
756
uint32_t index,
725
757
const PropertyDescriptor& desc,
726
- const PropertyCallbackInfo<Value >& args) {
758
+ const PropertyCallbackInfo<void >& args) {
727
759
ContextifyContext* ctx = ContextifyContext::Get (args);
728
760
729
761
// Still initializing
730
- if (IsStillInitializing (ctx)) return ;
762
+ if (IsStillInitializing (ctx)) {
763
+ return Intercepted::kNo ;
764
+ }
731
765
732
- ContextifyContext::PropertyDefinerCallback (
766
+ return ContextifyContext::PropertyDefinerCallback (
733
767
Uint32ToName (ctx->context (), index ), desc, args);
734
768
}
735
769
736
770
// static
737
- void ContextifyContext::IndexedPropertyDeleterCallback (
738
- uint32_t index,
739
- const PropertyCallbackInfo<Boolean >& args) {
771
+ Intercepted ContextifyContext::IndexedPropertyDeleterCallback (
772
+ uint32_t index, const PropertyCallbackInfo<Boolean >& args) {
740
773
ContextifyContext* ctx = ContextifyContext::Get (args);
741
774
742
775
// Still initializing
743
- if (IsStillInitializing (ctx)) return ;
776
+ if (IsStillInitializing (ctx)) {
777
+ return Intercepted::kNo ;
778
+ }
744
779
745
780
Maybe<bool > success = ctx->sandbox ()->Delete (ctx->context (), index );
746
781
747
- if (success.FromMaybe (false ))
748
- return ;
782
+ if (success.FromMaybe (false )) {
783
+ return Intercepted::kNo ;
784
+ }
749
785
750
786
// Delete failed on the sandbox, intercept and do not delete on
751
787
// the global object.
752
788
args.GetReturnValue ().Set (false );
789
+ return Intercepted::kYes ;
753
790
}
754
791
755
792
void ContextifyScript::CreatePerIsolateProperties (
0 commit comments