@@ -44,11 +44,13 @@ using v8::FunctionCallbackInfo;
44
44
using v8::FunctionTemplate;
45
45
using v8::HandleScope;
46
46
using v8::Integer;
47
+ using v8::Just;
47
48
using v8::Local;
48
49
using v8::Maybe;
49
50
using v8::MaybeLocal;
50
51
using v8::Name;
51
52
using v8::NamedPropertyHandlerConfiguration;
53
+ using v8::Nothing;
52
54
using v8::Object;
53
55
using v8::ObjectTemplate;
54
56
using v8::Persistent;
@@ -547,17 +549,20 @@ class ContextifyScript : public BaseObject {
547
549
Local<String> code = args[0 ]->ToString (env->isolate ());
548
550
549
551
Local<Value> options = args[1 ];
550
- Local <String> filename = GetFilenameArg (env, options);
551
- Local <Integer> lineOffset = GetLineOffsetArg (env, options);
552
- Local <Integer> columnOffset = GetColumnOffsetArg (env, options);
553
- bool display_errors = GetDisplayErrorsArg (env, options);
552
+ MaybeLocal <String> filename = GetFilenameArg (env, options);
553
+ MaybeLocal <Integer> lineOffset = GetLineOffsetArg (env, options);
554
+ MaybeLocal <Integer> columnOffset = GetColumnOffsetArg (env, options);
555
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, options);
554
556
MaybeLocal<Uint8Array> cached_data_buf = GetCachedData (env, options);
555
- bool produce_cached_data = GetProduceCachedData (env, options);
557
+ Maybe< bool > maybe_produce_cached_data = GetProduceCachedData (env, options);
556
558
if (try_catch.HasCaught ()) {
557
559
try_catch.ReThrow ();
558
560
return ;
559
561
}
560
562
563
+ bool display_errors = maybe_display_errors.ToChecked ();
564
+ bool produce_cached_data = maybe_produce_cached_data.ToChecked ();
565
+
561
566
ScriptCompiler::CachedData* cached_data = nullptr ;
562
567
Local<Uint8Array> ui8;
563
568
if (cached_data_buf.ToLocal (&ui8)) {
@@ -567,7 +572,8 @@ class ContextifyScript : public BaseObject {
567
572
ui8->ByteLength ());
568
573
}
569
574
570
- ScriptOrigin origin (filename, lineOffset, columnOffset);
575
+ ScriptOrigin origin (filename.ToLocalChecked (), lineOffset.ToLocalChecked (),
576
+ columnOffset.ToLocalChecked ());
571
577
ScriptCompiler::Source source (code, origin, cached_data);
572
578
ScriptCompiler::CompileOptions compile_options =
573
579
ScriptCompiler::kNoCompileOptions ;
@@ -625,14 +631,18 @@ class ContextifyScript : public BaseObject {
625
631
626
632
// Assemble arguments
627
633
TryCatch try_catch (args.GetIsolate ());
628
- uint64_t timeout = GetTimeoutArg (env, args[0 ]);
629
- bool display_errors = GetDisplayErrorsArg (env, args[0 ]);
630
- bool break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
634
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[0 ]);
635
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[0 ]);
636
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
631
637
if (try_catch.HasCaught ()) {
632
638
try_catch.ReThrow ();
633
639
return ;
634
640
}
635
641
642
+ int64_t timeout = maybe_timeout.ToChecked ();
643
+ bool display_errors = maybe_display_errors.ToChecked ();
644
+ bool break_on_sigint = maybe_break_on_sigint.ToChecked ();
645
+
636
646
// Do the eval within this context
637
647
EvalMachine (env, timeout, display_errors, break_on_sigint, args,
638
648
&try_catch);
@@ -655,13 +665,17 @@ class ContextifyScript : public BaseObject {
655
665
Local<Object> sandbox = args[0 ].As <Object>();
656
666
{
657
667
TryCatch try_catch (env->isolate ());
658
- timeout = GetTimeoutArg (env, args[1 ]);
659
- display_errors = GetDisplayErrorsArg (env, args[1 ]);
660
- break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
668
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[1 ]);
669
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[1 ]);
670
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
661
671
if (try_catch.HasCaught ()) {
662
672
try_catch.ReThrow ();
663
673
return ;
664
674
}
675
+
676
+ timeout = maybe_timeout.ToChecked ();
677
+ display_errors = maybe_display_errors.ToChecked ();
678
+ break_on_sigint = maybe_break_on_sigint.ToChecked ();
665
679
}
666
680
667
681
// Get the context from the sandbox
@@ -731,60 +745,82 @@ class ContextifyScript : public BaseObject {
731
745
True (env->isolate ()));
732
746
}
733
747
734
- static bool GetBreakOnSigintArg (Environment* env, Local<Value> options) {
748
+ static Maybe<bool > GetBreakOnSigintArg (Environment* env,
749
+ Local<Value> options) {
735
750
if (options->IsUndefined () || options->IsString ()) {
736
- return false ;
751
+ return Just ( false ) ;
737
752
}
738
753
if (!options->IsObject ()) {
739
754
env->ThrowTypeError (" options must be an object" );
740
- return false ;
755
+ return Nothing< bool >() ;
741
756
}
742
757
743
758
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " breakOnSigint" );
744
- Local<Value> value = options.As <Object>()->Get (key);
745
- return value->IsTrue ();
759
+ MaybeLocal<Value> maybe_value =
760
+ options.As <Object>()->Get (env->context (), key);
761
+ if (maybe_value.IsEmpty ())
762
+ return Nothing<bool >();
763
+
764
+ Local<Value> value = maybe_value.ToLocalChecked ();
765
+ return Just (value->IsTrue ());
746
766
}
747
767
748
- static int64_t GetTimeoutArg (Environment* env, Local<Value> options) {
768
+ static Maybe< int64_t > GetTimeoutArg (Environment* env, Local<Value> options) {
749
769
if (options->IsUndefined () || options->IsString ()) {
750
- return - 1 ;
770
+ return Just< int64_t >(- 1 ) ;
751
771
}
752
772
if (!options->IsObject ()) {
753
773
env->ThrowTypeError (" options must be an object" );
754
- return - 1 ;
774
+ return Nothing< int64_t >() ;
755
775
}
756
776
757
- Local<Value> value = options.As <Object>()->Get (env->timeout_string ());
777
+ MaybeLocal<Value> maybe_value =
778
+ options.As <Object>()->Get (env->context (), env->timeout_string ());
779
+ if (maybe_value.IsEmpty ())
780
+ return Nothing<int64_t >();
781
+
782
+ Local<Value> value = maybe_value.ToLocalChecked ();
758
783
if (value->IsUndefined ()) {
759
- return - 1 ;
784
+ return Just< int64_t >(- 1 ) ;
760
785
}
761
- int64_t timeout = value->IntegerValue ();
762
786
763
- if (timeout <= 0 ) {
787
+ Maybe<int64_t > timeout = value->IntegerValue (env->context ());
788
+
789
+ if (timeout.IsJust () && timeout.ToChecked () <= 0 ) {
764
790
env->ThrowRangeError (" timeout must be a positive number" );
765
- return - 1 ;
791
+ return Nothing< int64_t >() ;
766
792
}
793
+
767
794
return timeout;
768
795
}
769
796
770
797
771
- static bool GetDisplayErrorsArg (Environment* env, Local<Value> options) {
798
+ static Maybe<bool > GetDisplayErrorsArg (Environment* env,
799
+ Local<Value> options) {
772
800
if (options->IsUndefined () || options->IsString ()) {
773
- return true ;
801
+ return Just ( true ) ;
774
802
}
775
803
if (!options->IsObject ()) {
776
804
env->ThrowTypeError (" options must be an object" );
777
- return false ;
805
+ return Nothing< bool >() ;
778
806
}
779
807
780
808
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " displayErrors" );
781
- Local<Value> value = options.As <Object>()->Get (key);
809
+ MaybeLocal<Value> maybe_value =
810
+ options.As <Object>()->Get (env->context (), key);
811
+ if (maybe_value.IsEmpty ())
812
+ return Nothing<bool >();
782
813
783
- return value->IsUndefined () ? true : value->BooleanValue ();
814
+ Local<Value> value = maybe_value.ToLocalChecked ();
815
+ if (value->IsUndefined ())
816
+ return Just (true );
817
+
818
+ return value->BooleanValue (env->context ());
784
819
}
785
820
786
821
787
- static Local<String> GetFilenameArg (Environment* env, Local<Value> options) {
822
+ static MaybeLocal<String> GetFilenameArg (Environment* env,
823
+ Local<Value> options) {
788
824
Local<String> defaultFilename =
789
825
FIXED_ONE_BYTE_STRING (env->isolate (), " evalmachine.<anonymous>" );
790
826
@@ -800,11 +836,15 @@ class ContextifyScript : public BaseObject {
800
836
}
801
837
802
838
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " filename" );
803
- Local<Value> value = options.As <Object>()->Get (key);
839
+ MaybeLocal<Value> maybe_value =
840
+ options.As <Object>()->Get (env->context (), key);
841
+ if (maybe_value.IsEmpty ())
842
+ return MaybeLocal<String>();
804
843
844
+ Local<Value> value = maybe_value.ToLocalChecked ();
805
845
if (value->IsUndefined ())
806
846
return defaultFilename;
807
- return value->ToString (env->isolate ());
847
+ return value->ToString (env->context ());
808
848
}
809
849
810
850
@@ -813,7 +853,13 @@ class ContextifyScript : public BaseObject {
813
853
if (!options->IsObject ()) {
814
854
return MaybeLocal<Uint8Array>();
815
855
}
816
- Local<Value> value = options.As <Object>()->Get (env->cached_data_string ());
856
+
857
+ MaybeLocal<Value> maybe_value =
858
+ options.As <Object>()->Get (env->context (), env->cached_data_string ());
859
+ if (maybe_value.IsEmpty ())
860
+ return MaybeLocal<Uint8Array>();
861
+
862
+ Local<Value> value = maybe_value.ToLocalChecked ();
817
863
if (value->IsUndefined ()) {
818
864
return MaybeLocal<Uint8Array>();
819
865
}
@@ -827,44 +873,64 @@ class ContextifyScript : public BaseObject {
827
873
}
828
874
829
875
830
- static bool GetProduceCachedData (Environment* env, Local<Value> options) {
876
+ static Maybe<bool > GetProduceCachedData (Environment* env,
877
+ Local<Value> options) {
831
878
if (!options->IsObject ()) {
832
- return false ;
879
+ return Just ( false ) ;
833
880
}
834
- Local<Value> value =
835
- options.As <Object>()->Get (env->produce_cached_data_string ());
836
881
837
- return value->IsTrue ();
882
+ MaybeLocal<Value> maybe_value =
883
+ options.As <Object>()->Get (env->context (),
884
+ env->produce_cached_data_string ());
885
+ if (maybe_value.IsEmpty ())
886
+ return Nothing<bool >();
887
+
888
+ Local<Value> value = maybe_value.ToLocalChecked ();
889
+ return Just (value->IsTrue ());
838
890
}
839
891
840
892
841
- static Local <Integer> GetLineOffsetArg (Environment* env,
842
- Local<Value> options) {
893
+ static MaybeLocal <Integer> GetLineOffsetArg (Environment* env,
894
+ Local<Value> options) {
843
895
Local<Integer> defaultLineOffset = Integer::New (env->isolate (), 0 );
844
896
845
897
if (!options->IsObject ()) {
846
898
return defaultLineOffset;
847
899
}
848
900
849
901
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " lineOffset" );
850
- Local<Value> value = options.As <Object>()->Get (key);
902
+ MaybeLocal<Value> maybe_value =
903
+ options.As <Object>()->Get (env->context (), key);
904
+ if (maybe_value.IsEmpty ())
905
+ return MaybeLocal<Integer>();
851
906
852
- return value->IsUndefined () ? defaultLineOffset : value->ToInteger ();
907
+ Local<Value> value = maybe_value.ToLocalChecked ();
908
+ if (value->IsUndefined ())
909
+ return defaultLineOffset;
910
+
911
+ return value->ToInteger (env->context ());
853
912
}
854
913
855
914
856
- static Local <Integer> GetColumnOffsetArg (Environment* env,
857
- Local<Value> options) {
915
+ static MaybeLocal <Integer> GetColumnOffsetArg (Environment* env,
916
+ Local<Value> options) {
858
917
Local<Integer> defaultColumnOffset = Integer::New (env->isolate (), 0 );
859
918
860
919
if (!options->IsObject ()) {
861
920
return defaultColumnOffset;
862
921
}
863
922
864
923
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " columnOffset" );
865
- Local<Value> value = options.As <Object>()->Get (key);
924
+ MaybeLocal<Value> maybe_value =
925
+ options.As <Object>()->Get (env->context (), key);
926
+ if (maybe_value.IsEmpty ())
927
+ return MaybeLocal<Integer>();
928
+
929
+ Local<Value> value = maybe_value.ToLocalChecked ();
930
+ if (value->IsUndefined ())
931
+ return defaultColumnOffset;
866
932
867
- return value->IsUndefined () ? defaultColumnOffset : value-> ToInteger ( );
933
+ return value->ToInteger (env-> context () );
868
934
}
869
935
870
936
0 commit comments