@@ -23,11 +23,13 @@ using v8::FunctionCallbackInfo;
23
23
using v8::FunctionTemplate;
24
24
using v8::HandleScope;
25
25
using v8::Integer;
26
+ using v8::Just;
26
27
using v8::Local;
27
28
using v8::Maybe;
28
29
using v8::MaybeLocal;
29
30
using v8::Name;
30
31
using v8::NamedPropertyHandlerConfiguration;
32
+ using v8::Nothing;
31
33
using v8::Object;
32
34
using v8::ObjectTemplate;
33
35
using v8::Persistent;
@@ -525,17 +527,20 @@ class ContextifyScript : public BaseObject {
525
527
Local<String> code = args[0 ]->ToString (env->isolate ());
526
528
527
529
Local<Value> options = args[1 ];
528
- Local <String> filename = GetFilenameArg (env, options);
529
- Local <Integer> lineOffset = GetLineOffsetArg (env, options);
530
- Local <Integer> columnOffset = GetColumnOffsetArg (env, options);
531
- bool display_errors = GetDisplayErrorsArg (env, options);
530
+ MaybeLocal <String> filename = GetFilenameArg (env, options);
531
+ MaybeLocal <Integer> lineOffset = GetLineOffsetArg (env, options);
532
+ MaybeLocal <Integer> columnOffset = GetColumnOffsetArg (env, options);
533
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, options);
532
534
MaybeLocal<Uint8Array> cached_data_buf = GetCachedData (env, options);
533
- bool produce_cached_data = GetProduceCachedData (env, options);
535
+ Maybe< bool > maybe_produce_cached_data = GetProduceCachedData (env, options);
534
536
if (try_catch.HasCaught ()) {
535
537
try_catch.ReThrow ();
536
538
return ;
537
539
}
538
540
541
+ bool display_errors = maybe_display_errors.ToChecked ();
542
+ bool produce_cached_data = maybe_produce_cached_data.ToChecked ();
543
+
539
544
ScriptCompiler::CachedData* cached_data = nullptr ;
540
545
Local<Uint8Array> ui8;
541
546
if (cached_data_buf.ToLocal (&ui8)) {
@@ -545,7 +550,8 @@ class ContextifyScript : public BaseObject {
545
550
ui8->ByteLength ());
546
551
}
547
552
548
- ScriptOrigin origin (filename, lineOffset, columnOffset);
553
+ ScriptOrigin origin (filename.ToLocalChecked (), lineOffset.ToLocalChecked (),
554
+ columnOffset.ToLocalChecked ());
549
555
ScriptCompiler::Source source (code, origin, cached_data);
550
556
ScriptCompiler::CompileOptions compile_options =
551
557
ScriptCompiler::kNoCompileOptions ;
@@ -603,14 +609,18 @@ class ContextifyScript : public BaseObject {
603
609
604
610
// Assemble arguments
605
611
TryCatch try_catch (args.GetIsolate ());
606
- uint64_t timeout = GetTimeoutArg (env, args[0 ]);
607
- bool display_errors = GetDisplayErrorsArg (env, args[0 ]);
608
- bool break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
612
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[0 ]);
613
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[0 ]);
614
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
609
615
if (try_catch.HasCaught ()) {
610
616
try_catch.ReThrow ();
611
617
return ;
612
618
}
613
619
620
+ int64_t timeout = maybe_timeout.ToChecked ();
621
+ bool display_errors = maybe_display_errors.ToChecked ();
622
+ bool break_on_sigint = maybe_break_on_sigint.ToChecked ();
623
+
614
624
// Do the eval within this context
615
625
EvalMachine (env, timeout, display_errors, break_on_sigint, args,
616
626
&try_catch);
@@ -633,13 +643,17 @@ class ContextifyScript : public BaseObject {
633
643
Local<Object> sandbox = args[0 ].As <Object>();
634
644
{
635
645
TryCatch try_catch (env->isolate ());
636
- timeout = GetTimeoutArg (env, args[1 ]);
637
- display_errors = GetDisplayErrorsArg (env, args[1 ]);
638
- break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
646
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[1 ]);
647
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[1 ]);
648
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
639
649
if (try_catch.HasCaught ()) {
640
650
try_catch.ReThrow ();
641
651
return ;
642
652
}
653
+
654
+ timeout = maybe_timeout.ToChecked ();
655
+ display_errors = maybe_display_errors.ToChecked ();
656
+ break_on_sigint = maybe_break_on_sigint.ToChecked ();
643
657
}
644
658
645
659
// Get the context from the sandbox
@@ -709,60 +723,82 @@ class ContextifyScript : public BaseObject {
709
723
True (env->isolate ()));
710
724
}
711
725
712
- static bool GetBreakOnSigintArg (Environment* env, Local<Value> options) {
726
+ static Maybe<bool > GetBreakOnSigintArg (Environment* env,
727
+ Local<Value> options) {
713
728
if (options->IsUndefined () || options->IsString ()) {
714
- return false ;
729
+ return Just ( false ) ;
715
730
}
716
731
if (!options->IsObject ()) {
717
732
env->ThrowTypeError (" options must be an object" );
718
- return false ;
733
+ return Nothing< bool >() ;
719
734
}
720
735
721
736
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " breakOnSigint" );
722
- Local<Value> value = options.As <Object>()->Get (key);
723
- return value->IsTrue ();
737
+ MaybeLocal<Value> maybe_value =
738
+ options.As <Object>()->Get (env->context (), key);
739
+ if (maybe_value.IsEmpty ())
740
+ return Nothing<bool >();
741
+
742
+ Local<Value> value = maybe_value.ToLocalChecked ();
743
+ return Just (value->IsTrue ());
724
744
}
725
745
726
- static int64_t GetTimeoutArg (Environment* env, Local<Value> options) {
746
+ static Maybe< int64_t > GetTimeoutArg (Environment* env, Local<Value> options) {
727
747
if (options->IsUndefined () || options->IsString ()) {
728
- return - 1 ;
748
+ return Just< int64_t >(- 1 ) ;
729
749
}
730
750
if (!options->IsObject ()) {
731
751
env->ThrowTypeError (" options must be an object" );
732
- return - 1 ;
752
+ return Nothing< int64_t >() ;
733
753
}
734
754
735
- Local<Value> value = options.As <Object>()->Get (env->timeout_string ());
755
+ MaybeLocal<Value> maybe_value =
756
+ options.As <Object>()->Get (env->context (), env->timeout_string ());
757
+ if (maybe_value.IsEmpty ())
758
+ return Nothing<int64_t >();
759
+
760
+ Local<Value> value = maybe_value.ToLocalChecked ();
736
761
if (value->IsUndefined ()) {
737
- return - 1 ;
762
+ return Just< int64_t >(- 1 ) ;
738
763
}
739
- int64_t timeout = value->IntegerValue ();
740
764
741
- if (timeout <= 0 ) {
765
+ Maybe<int64_t > timeout = value->IntegerValue (env->context ());
766
+
767
+ if (timeout.IsJust () && timeout.ToChecked () <= 0 ) {
742
768
env->ThrowRangeError (" timeout must be a positive number" );
743
- return - 1 ;
769
+ return Nothing< int64_t >() ;
744
770
}
771
+
745
772
return timeout;
746
773
}
747
774
748
775
749
- static bool GetDisplayErrorsArg (Environment* env, Local<Value> options) {
776
+ static Maybe<bool > GetDisplayErrorsArg (Environment* env,
777
+ Local<Value> options) {
750
778
if (options->IsUndefined () || options->IsString ()) {
751
- return true ;
779
+ return Just ( true ) ;
752
780
}
753
781
if (!options->IsObject ()) {
754
782
env->ThrowTypeError (" options must be an object" );
755
- return false ;
783
+ return Nothing< bool >() ;
756
784
}
757
785
758
786
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " displayErrors" );
759
- Local<Value> value = options.As <Object>()->Get (key);
787
+ MaybeLocal<Value> maybe_value =
788
+ options.As <Object>()->Get (env->context (), key);
789
+ if (maybe_value.IsEmpty ())
790
+ return Nothing<bool >();
760
791
761
- return value->IsUndefined () ? true : value->BooleanValue ();
792
+ Local<Value> value = maybe_value.ToLocalChecked ();
793
+ if (value->IsUndefined ())
794
+ return Just (true );
795
+
796
+ return value->BooleanValue (env->context ());
762
797
}
763
798
764
799
765
- static Local<String> GetFilenameArg (Environment* env, Local<Value> options) {
800
+ static MaybeLocal<String> GetFilenameArg (Environment* env,
801
+ Local<Value> options) {
766
802
Local<String> defaultFilename =
767
803
FIXED_ONE_BYTE_STRING (env->isolate (), " evalmachine.<anonymous>" );
768
804
@@ -778,11 +814,15 @@ class ContextifyScript : public BaseObject {
778
814
}
779
815
780
816
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " filename" );
781
- Local<Value> value = options.As <Object>()->Get (key);
817
+ MaybeLocal<Value> maybe_value =
818
+ options.As <Object>()->Get (env->context (), key);
819
+ if (maybe_value.IsEmpty ())
820
+ return MaybeLocal<String>();
782
821
822
+ Local<Value> value = maybe_value.ToLocalChecked ();
783
823
if (value->IsUndefined ())
784
824
return defaultFilename;
785
- return value->ToString (env->isolate ());
825
+ return value->ToString (env->context ());
786
826
}
787
827
788
828
@@ -791,7 +831,13 @@ class ContextifyScript : public BaseObject {
791
831
if (!options->IsObject ()) {
792
832
return MaybeLocal<Uint8Array>();
793
833
}
794
- Local<Value> value = options.As <Object>()->Get (env->cached_data_string ());
834
+
835
+ MaybeLocal<Value> maybe_value =
836
+ options.As <Object>()->Get (env->context (), env->cached_data_string ());
837
+ if (maybe_value.IsEmpty ())
838
+ return MaybeLocal<Uint8Array>();
839
+
840
+ Local<Value> value = maybe_value.ToLocalChecked ();
795
841
if (value->IsUndefined ()) {
796
842
return MaybeLocal<Uint8Array>();
797
843
}
@@ -805,44 +851,64 @@ class ContextifyScript : public BaseObject {
805
851
}
806
852
807
853
808
- static bool GetProduceCachedData (Environment* env, Local<Value> options) {
854
+ static Maybe<bool > GetProduceCachedData (Environment* env,
855
+ Local<Value> options) {
809
856
if (!options->IsObject ()) {
810
- return false ;
857
+ return Just ( false ) ;
811
858
}
812
- Local<Value> value =
813
- options.As <Object>()->Get (env->produce_cached_data_string ());
814
859
815
- return value->IsTrue ();
860
+ MaybeLocal<Value> maybe_value =
861
+ options.As <Object>()->Get (env->context (),
862
+ env->produce_cached_data_string ());
863
+ if (maybe_value.IsEmpty ())
864
+ return Nothing<bool >();
865
+
866
+ Local<Value> value = maybe_value.ToLocalChecked ();
867
+ return Just (value->IsTrue ());
816
868
}
817
869
818
870
819
- static Local <Integer> GetLineOffsetArg (Environment* env,
820
- Local<Value> options) {
871
+ static MaybeLocal <Integer> GetLineOffsetArg (Environment* env,
872
+ Local<Value> options) {
821
873
Local<Integer> defaultLineOffset = Integer::New (env->isolate (), 0 );
822
874
823
875
if (!options->IsObject ()) {
824
876
return defaultLineOffset;
825
877
}
826
878
827
879
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " lineOffset" );
828
- Local<Value> value = options.As <Object>()->Get (key);
880
+ MaybeLocal<Value> maybe_value =
881
+ options.As <Object>()->Get (env->context (), key);
882
+ if (maybe_value.IsEmpty ())
883
+ return MaybeLocal<Integer>();
829
884
830
- return value->IsUndefined () ? defaultLineOffset : value->ToInteger ();
885
+ Local<Value> value = maybe_value.ToLocalChecked ();
886
+ if (value->IsUndefined ())
887
+ return defaultLineOffset;
888
+
889
+ return value->ToInteger (env->context ());
831
890
}
832
891
833
892
834
- static Local <Integer> GetColumnOffsetArg (Environment* env,
835
- Local<Value> options) {
893
+ static MaybeLocal <Integer> GetColumnOffsetArg (Environment* env,
894
+ Local<Value> options) {
836
895
Local<Integer> defaultColumnOffset = Integer::New (env->isolate (), 0 );
837
896
838
897
if (!options->IsObject ()) {
839
898
return defaultColumnOffset;
840
899
}
841
900
842
901
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " columnOffset" );
843
- 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>();
906
+
907
+ Local<Value> value = maybe_value.ToLocalChecked ();
908
+ if (value->IsUndefined ())
909
+ return defaultColumnOffset;
844
910
845
- return value->IsUndefined () ? defaultColumnOffset : value-> ToInteger ( );
911
+ return value->ToInteger (env-> context () );
846
912
}
847
913
848
914
0 commit comments