@@ -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;
@@ -495,17 +497,20 @@ class ContextifyScript : public BaseObject {
495
497
Local<String> code = args[0 ]->ToString (env->isolate ());
496
498
497
499
Local<Value> options = args[1 ];
498
- Local <String> filename = GetFilenameArg (env, options);
499
- Local <Integer> lineOffset = GetLineOffsetArg (env, options);
500
- Local <Integer> columnOffset = GetColumnOffsetArg (env, options);
501
- bool display_errors = GetDisplayErrorsArg (env, options);
500
+ MaybeLocal <String> filename = GetFilenameArg (env, options);
501
+ MaybeLocal <Integer> lineOffset = GetLineOffsetArg (env, options);
502
+ MaybeLocal <Integer> columnOffset = GetColumnOffsetArg (env, options);
503
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, options);
502
504
MaybeLocal<Uint8Array> cached_data_buf = GetCachedData (env, options);
503
- bool produce_cached_data = GetProduceCachedData (env, options);
505
+ Maybe< bool > maybe_produce_cached_data = GetProduceCachedData (env, options);
504
506
if (try_catch.HasCaught ()) {
505
507
try_catch.ReThrow ();
506
508
return ;
507
509
}
508
510
511
+ bool display_errors = maybe_display_errors.FromJust ();
512
+ bool produce_cached_data = maybe_produce_cached_data.FromJust ();
513
+
509
514
ScriptCompiler::CachedData* cached_data = nullptr ;
510
515
if (!cached_data_buf.IsEmpty ()) {
511
516
Local<Uint8Array> ui8 = cached_data_buf.ToLocalChecked ();
@@ -515,7 +520,8 @@ class ContextifyScript : public BaseObject {
515
520
ui8->ByteLength ());
516
521
}
517
522
518
- ScriptOrigin origin (filename, lineOffset, columnOffset);
523
+ ScriptOrigin origin (filename.ToLocalChecked (), lineOffset.ToLocalChecked (),
524
+ columnOffset.ToLocalChecked ());
519
525
ScriptCompiler::Source source (code, origin, cached_data);
520
526
ScriptCompiler::CompileOptions compile_options =
521
527
ScriptCompiler::kNoCompileOptions ;
@@ -573,14 +579,18 @@ class ContextifyScript : public BaseObject {
573
579
574
580
// Assemble arguments
575
581
TryCatch try_catch (args.GetIsolate ());
576
- uint64_t timeout = GetTimeoutArg (env, args[0 ]);
577
- bool display_errors = GetDisplayErrorsArg (env, args[0 ]);
578
- bool break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
582
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[0 ]);
583
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[0 ]);
584
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[0 ]);
579
585
if (try_catch.HasCaught ()) {
580
586
try_catch.ReThrow ();
581
587
return ;
582
588
}
583
589
590
+ int64_t timeout = maybe_timeout.FromJust ();
591
+ bool display_errors = maybe_display_errors.FromJust ();
592
+ bool break_on_sigint = maybe_break_on_sigint.FromJust ();
593
+
584
594
// Do the eval within this context
585
595
EvalMachine (env, timeout, display_errors, break_on_sigint, args,
586
596
&try_catch);
@@ -603,13 +613,17 @@ class ContextifyScript : public BaseObject {
603
613
Local<Object> sandbox = args[0 ].As <Object>();
604
614
{
605
615
TryCatch try_catch (env->isolate ());
606
- timeout = GetTimeoutArg (env, args[1 ]);
607
- display_errors = GetDisplayErrorsArg (env, args[1 ]);
608
- break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
616
+ Maybe< int64_t > maybe_timeout = GetTimeoutArg (env, args[1 ]);
617
+ Maybe< bool > maybe_display_errors = GetDisplayErrorsArg (env, args[1 ]);
618
+ Maybe< bool > maybe_break_on_sigint = GetBreakOnSigintArg (env, args[1 ]);
609
619
if (try_catch.HasCaught ()) {
610
620
try_catch.ReThrow ();
611
621
return ;
612
622
}
623
+
624
+ timeout = maybe_timeout.FromJust ();
625
+ display_errors = maybe_display_errors.FromJust ();
626
+ break_on_sigint = maybe_break_on_sigint.FromJust ();
613
627
}
614
628
615
629
// Get the context from the sandbox
@@ -679,61 +693,82 @@ class ContextifyScript : public BaseObject {
679
693
True (env->isolate ()));
680
694
}
681
695
682
- static bool GetBreakOnSigintArg (Environment* env, Local<Value> options) {
696
+ static Maybe<bool > GetBreakOnSigintArg (Environment* env,
697
+ Local<Value> options) {
683
698
if (options->IsUndefined () || options->IsString ()) {
684
- return false ;
699
+ return Just ( false ) ;
685
700
}
686
701
if (!options->IsObject ()) {
687
702
env->ThrowTypeError (" options must be an object" );
688
- return false ;
703
+ return Nothing< bool >() ;
689
704
}
690
705
691
706
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " breakOnSigint" );
692
- Local<Value> value = options.As <Object>()->Get (key);
693
- return value->IsTrue ();
707
+ MaybeLocal<Value> maybe_value =
708
+ options.As <Object>()->Get (env->context (), key);
709
+ if (maybe_value.IsEmpty ())
710
+ return Nothing<bool >();
711
+
712
+ Local<Value> value = maybe_value.ToLocalChecked ();
713
+ return Just (value->IsTrue ());
694
714
}
695
715
696
- static int64_t GetTimeoutArg (Environment* env, Local<Value> options) {
716
+ static Maybe< int64_t > GetTimeoutArg (Environment* env, Local<Value> options) {
697
717
if (options->IsUndefined () || options->IsString ()) {
698
- return - 1 ;
718
+ return Just< int64_t >(- 1 ) ;
699
719
}
700
720
if (!options->IsObject ()) {
701
721
env->ThrowTypeError (" options must be an object" );
702
- return - 1 ;
722
+ return Nothing< int64_t >() ;
703
723
}
704
724
705
- Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " timeout" );
706
- Local<Value> value = options.As <Object>()->Get (key);
725
+ MaybeLocal<Value> maybe_value =
726
+ options.As <Object>()->Get (env->context (), env->timeout_string ());
727
+ if (maybe_value.IsEmpty ())
728
+ return Nothing<int64_t >();
729
+
730
+ Local<Value> value = maybe_value.ToLocalChecked ();
707
731
if (value->IsUndefined ()) {
708
- return - 1 ;
732
+ return Just< int64_t >(- 1 ) ;
709
733
}
710
- int64_t timeout = value->IntegerValue ();
711
734
712
- if (timeout <= 0 ) {
735
+ Maybe<int64_t > timeout = value->IntegerValue (env->context ());
736
+
737
+ if (timeout.IsJust () && timeout.FromJust () <= 0 ) {
713
738
env->ThrowRangeError (" timeout must be a positive number" );
714
- return - 1 ;
739
+ return Nothing< int64_t >() ;
715
740
}
741
+
716
742
return timeout;
717
743
}
718
744
719
745
720
- static bool GetDisplayErrorsArg (Environment* env, Local<Value> options) {
746
+ static Maybe<bool > GetDisplayErrorsArg (Environment* env,
747
+ Local<Value> options) {
721
748
if (options->IsUndefined () || options->IsString ()) {
722
- return true ;
749
+ return Just ( true ) ;
723
750
}
724
751
if (!options->IsObject ()) {
725
752
env->ThrowTypeError (" options must be an object" );
726
- return false ;
753
+ return Nothing< bool >() ;
727
754
}
728
755
729
756
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " displayErrors" );
730
- Local<Value> value = options.As <Object>()->Get (key);
757
+ MaybeLocal<Value> maybe_value =
758
+ options.As <Object>()->Get (env->context (), key);
759
+ if (maybe_value.IsEmpty ())
760
+ return Nothing<bool >();
731
761
732
- return value->IsUndefined () ? true : value->BooleanValue ();
762
+ Local<Value> value = maybe_value.ToLocalChecked ();
763
+ if (value->IsUndefined ())
764
+ return Just (true );
765
+
766
+ return value->BooleanValue (env->context ());
733
767
}
734
768
735
769
736
- static Local<String> GetFilenameArg (Environment* env, Local<Value> options) {
770
+ static MaybeLocal<String> GetFilenameArg (Environment* env,
771
+ Local<Value> options) {
737
772
Local<String> defaultFilename =
738
773
FIXED_ONE_BYTE_STRING (env->isolate (), " evalmachine.<anonymous>" );
739
774
@@ -749,11 +784,15 @@ class ContextifyScript : public BaseObject {
749
784
}
750
785
751
786
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " filename" );
752
- 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 MaybeLocal<String>();
753
791
792
+ Local<Value> value = maybe_value.ToLocalChecked ();
754
793
if (value->IsUndefined ())
755
794
return defaultFilename;
756
- return value->ToString (env->isolate ());
795
+ return value->ToString (env->context ());
757
796
}
758
797
759
798
@@ -762,7 +801,13 @@ class ContextifyScript : public BaseObject {
762
801
if (!options->IsObject ()) {
763
802
return MaybeLocal<Uint8Array>();
764
803
}
765
- Local<Value> value = options.As <Object>()->Get (env->cached_data_string ());
804
+
805
+ MaybeLocal<Value> maybe_value =
806
+ options.As <Object>()->Get (env->context (), env->cached_data_string ());
807
+ if (maybe_value.IsEmpty ())
808
+ return MaybeLocal<Uint8Array>();
809
+
810
+ Local<Value> value = maybe_value.ToLocalChecked ();
766
811
if (value->IsUndefined ()) {
767
812
return MaybeLocal<Uint8Array>();
768
813
}
@@ -776,44 +821,64 @@ class ContextifyScript : public BaseObject {
776
821
}
777
822
778
823
779
- static bool GetProduceCachedData (Environment* env, Local<Value> options) {
824
+ static Maybe<bool > GetProduceCachedData (Environment* env,
825
+ Local<Value> options) {
780
826
if (!options->IsObject ()) {
781
- return false ;
827
+ return Just ( false ) ;
782
828
}
783
- Local<Value> value =
784
- options.As <Object>()->Get (env->produce_cached_data_string ());
785
829
786
- return value->IsTrue ();
830
+ MaybeLocal<Value> maybe_value =
831
+ options.As <Object>()->Get (env->context (),
832
+ env->produce_cached_data_string ());
833
+ if (maybe_value.IsEmpty ())
834
+ return Nothing<bool >();
835
+
836
+ Local<Value> value = maybe_value.ToLocalChecked ();
837
+ return Just (value->IsTrue ());
787
838
}
788
839
789
840
790
- static Local <Integer> GetLineOffsetArg (Environment* env,
791
- Local<Value> options) {
841
+ static MaybeLocal <Integer> GetLineOffsetArg (Environment* env,
842
+ Local<Value> options) {
792
843
Local<Integer> defaultLineOffset = Integer::New (env->isolate (), 0 );
793
844
794
845
if (!options->IsObject ()) {
795
846
return defaultLineOffset;
796
847
}
797
848
798
849
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " lineOffset" );
799
- Local<Value> value = options.As <Object>()->Get (key);
850
+ MaybeLocal<Value> maybe_value =
851
+ options.As <Object>()->Get (env->context (), key);
852
+ if (maybe_value.IsEmpty ())
853
+ return MaybeLocal<Integer>();
800
854
801
- return value->IsUndefined () ? defaultLineOffset : value->ToInteger ();
855
+ Local<Value> value = maybe_value.ToLocalChecked ();
856
+ if (value->IsUndefined ())
857
+ return defaultLineOffset;
858
+
859
+ return value->ToInteger (env->context ());
802
860
}
803
861
804
862
805
- static Local <Integer> GetColumnOffsetArg (Environment* env,
806
- Local<Value> options) {
863
+ static MaybeLocal <Integer> GetColumnOffsetArg (Environment* env,
864
+ Local<Value> options) {
807
865
Local<Integer> defaultColumnOffset = Integer::New (env->isolate (), 0 );
808
866
809
867
if (!options->IsObject ()) {
810
868
return defaultColumnOffset;
811
869
}
812
870
813
871
Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " columnOffset" );
814
- Local<Value> value = options.As <Object>()->Get (key);
872
+ MaybeLocal<Value> maybe_value =
873
+ options.As <Object>()->Get (env->context (), key);
874
+ if (maybe_value.IsEmpty ())
875
+ return MaybeLocal<Integer>();
876
+
877
+ Local<Value> value = maybe_value.ToLocalChecked ();
878
+ if (value->IsUndefined ())
879
+ return defaultColumnOffset;
815
880
816
- return value->IsUndefined () ? defaultColumnOffset : value-> ToInteger ( );
881
+ return value->ToInteger (env-> context () );
817
882
}
818
883
819
884
0 commit comments