@@ -492,12 +492,14 @@ class ContextifyScript : public BaseObject {
492
492
493
493
TryCatch try_catch (env->isolate ());
494
494
Local<String> code = args[0 ]->ToString (env->isolate ());
495
- Local<String> filename = GetFilenameArg (env, args, 1 );
496
- Local<Integer> lineOffset = GetLineOffsetArg (args, 1 );
497
- Local<Integer> columnOffset = GetColumnOffsetArg (args, 1 );
498
- bool display_errors = GetDisplayErrorsArg (env, args, 1 );
499
- MaybeLocal<Uint8Array> cached_data_buf = GetCachedData (env, args, 1 );
500
- bool produce_cached_data = GetProduceCachedData (env, args, 1 );
495
+
496
+ Local<Value> options = args[1 ];
497
+ Local<String> filename = GetFilenameArg (env, options);
498
+ Local<Integer> lineOffset = GetLineOffsetArg (env, options);
499
+ Local<Integer> columnOffset = GetColumnOffsetArg (env, options);
500
+ bool display_errors = GetDisplayErrorsArg (env, options);
501
+ MaybeLocal<Uint8Array> cached_data_buf = GetCachedData (env, options);
502
+ bool produce_cached_data = GetProduceCachedData (env, options);
501
503
if (try_catch.HasCaught ()) {
502
504
try_catch.ReThrow ();
503
505
return ;
@@ -570,9 +572,9 @@ class ContextifyScript : public BaseObject {
570
572
571
573
// Assemble arguments
572
574
TryCatch try_catch (args.GetIsolate ());
573
- uint64_t timeout = GetTimeoutArg (env, args, 0 );
574
- bool display_errors = GetDisplayErrorsArg (env, args, 0 );
575
- bool break_on_sigint = GetBreakOnSigintArg (env, args, 0 );
575
+ uint64_t timeout = GetTimeoutArg (env, args[ 0 ] );
576
+ bool display_errors = GetDisplayErrorsArg (env, args[ 0 ] );
577
+ bool break_on_sigint = GetBreakOnSigintArg (env, args[ 0 ] );
576
578
if (try_catch.HasCaught ()) {
577
579
try_catch.ReThrow ();
578
580
return ;
@@ -600,9 +602,9 @@ class ContextifyScript : public BaseObject {
600
602
Local<Object> sandbox = args[0 ].As <Object>();
601
603
{
602
604
TryCatch try_catch (env->isolate ());
603
- timeout = GetTimeoutArg (env, args, 1 );
604
- display_errors = GetDisplayErrorsArg (env, args, 1 );
605
- break_on_sigint = GetBreakOnSigintArg (env, args, 1 );
605
+ timeout = GetTimeoutArg (env, args[ 1 ] );
606
+ display_errors = GetDisplayErrorsArg (env, args[ 1 ] );
607
+ break_on_sigint = GetBreakOnSigintArg (env, args[ 1 ] );
606
608
if (try_catch.HasCaught ()) {
607
609
try_catch.ReThrow ();
608
610
return ;
@@ -676,36 +678,31 @@ class ContextifyScript : public BaseObject {
676
678
True (env->isolate ()));
677
679
}
678
680
679
- static bool GetBreakOnSigintArg (Environment* env,
680
- const FunctionCallbackInfo<Value>& args,
681
- const int i) {
682
- if (args[i]->IsUndefined () || args[i]->IsString ()) {
681
+ static bool GetBreakOnSigintArg (Environment* env, Local<Value> options) {
682
+ if (options->IsUndefined () || options->IsString ()) {
683
683
return false ;
684
684
}
685
- if (!args[i] ->IsObject ()) {
685
+ if (!options ->IsObject ()) {
686
686
env->ThrowTypeError (" options must be an object" );
687
687
return false ;
688
688
}
689
689
690
- Local<String> key = FIXED_ONE_BYTE_STRING (args.GetIsolate (),
691
- " breakOnSigint" );
692
- Local<Value> value = args[i].As <Object>()->Get (key);
690
+ Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " breakOnSigint" );
691
+ Local<Value> value = options.As <Object>()->Get (key);
693
692
return value->IsTrue ();
694
693
}
695
694
696
- static int64_t GetTimeoutArg (Environment* env,
697
- const FunctionCallbackInfo<Value>& args,
698
- const int i) {
699
- if (args[i]->IsUndefined () || args[i]->IsString ()) {
695
+ static int64_t GetTimeoutArg (Environment* env, Local<Value> options) {
696
+ if (options->IsUndefined () || options->IsString ()) {
700
697
return -1 ;
701
698
}
702
- if (!args[i] ->IsObject ()) {
699
+ if (!options ->IsObject ()) {
703
700
env->ThrowTypeError (" options must be an object" );
704
701
return -1 ;
705
702
}
706
703
707
- Local<String> key = FIXED_ONE_BYTE_STRING (args. GetIsolate (), " timeout" );
708
- Local<Value> value = args[i] .As <Object>()->Get (key);
704
+ Local<String> key = FIXED_ONE_BYTE_STRING (env-> isolate (), " timeout" );
705
+ Local<Value> value = options .As <Object>()->Get (key);
709
706
if (value->IsUndefined ()) {
710
707
return -1 ;
711
708
}
@@ -719,59 +716,52 @@ class ContextifyScript : public BaseObject {
719
716
}
720
717
721
718
722
- static bool GetDisplayErrorsArg (Environment* env,
723
- const FunctionCallbackInfo<Value>& args,
724
- const int i) {
725
- if (args[i]->IsUndefined () || args[i]->IsString ()) {
719
+ static bool GetDisplayErrorsArg (Environment* env, Local<Value> options) {
720
+ if (options->IsUndefined () || options->IsString ()) {
726
721
return true ;
727
722
}
728
- if (!args[i] ->IsObject ()) {
723
+ if (!options ->IsObject ()) {
729
724
env->ThrowTypeError (" options must be an object" );
730
725
return false ;
731
726
}
732
727
733
- Local<String> key = FIXED_ONE_BYTE_STRING (args.GetIsolate (),
734
- " displayErrors" );
735
- Local<Value> value = args[i].As <Object>()->Get (key);
728
+ Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " displayErrors" );
729
+ Local<Value> value = options.As <Object>()->Get (key);
736
730
737
731
return value->IsUndefined () ? true : value->BooleanValue ();
738
732
}
739
733
740
734
741
- static Local<String> GetFilenameArg (Environment* env,
742
- const FunctionCallbackInfo<Value>& args,
743
- const int i) {
735
+ static Local<String> GetFilenameArg (Environment* env, Local<Value> options) {
744
736
Local<String> defaultFilename =
745
- FIXED_ONE_BYTE_STRING (args. GetIsolate (), " evalmachine.<anonymous>" );
737
+ FIXED_ONE_BYTE_STRING (env-> isolate (), " evalmachine.<anonymous>" );
746
738
747
- if (args[i] ->IsUndefined ()) {
739
+ if (options ->IsUndefined ()) {
748
740
return defaultFilename;
749
741
}
750
- if (args[i] ->IsString ()) {
751
- return args[i] .As <String>();
742
+ if (options ->IsString ()) {
743
+ return options .As <String>();
752
744
}
753
- if (!args[i] ->IsObject ()) {
745
+ if (!options ->IsObject ()) {
754
746
env->ThrowTypeError (" options must be an object" );
755
747
return Local<String>();
756
748
}
757
749
758
- Local<String> key = FIXED_ONE_BYTE_STRING (args. GetIsolate (), " filename" );
759
- Local<Value> value = args[i] .As <Object>()->Get (key);
750
+ Local<String> key = FIXED_ONE_BYTE_STRING (env-> isolate (), " filename" );
751
+ Local<Value> value = options .As <Object>()->Get (key);
760
752
761
753
if (value->IsUndefined ())
762
754
return defaultFilename;
763
- return value->ToString (args. GetIsolate ());
755
+ return value->ToString (env-> isolate ());
764
756
}
765
757
766
758
767
- static MaybeLocal<Uint8Array> GetCachedData (
768
- Environment* env,
769
- const FunctionCallbackInfo<Value>& args,
770
- const int i) {
771
- if (!args[i]->IsObject ()) {
759
+ static MaybeLocal<Uint8Array> GetCachedData (Environment* env,
760
+ Local<Value> options) {
761
+ if (!options->IsObject ()) {
772
762
return MaybeLocal<Uint8Array>();
773
763
}
774
- Local<Value> value = args[i] .As <Object>()->Get (env->cached_data_string ());
764
+ Local<Value> value = options .As <Object>()->Get (env->cached_data_string ());
775
765
if (value->IsUndefined ()) {
776
766
return MaybeLocal<Uint8Array>();
777
767
}
@@ -785,48 +775,42 @@ class ContextifyScript : public BaseObject {
785
775
}
786
776
787
777
788
- static bool GetProduceCachedData (
789
- Environment* env,
790
- const FunctionCallbackInfo<Value>& args,
791
- const int i) {
792
- if (!args[i]->IsObject ()) {
778
+ static bool GetProduceCachedData (Environment* env, Local<Value> options) {
779
+ if (!options->IsObject ()) {
793
780
return false ;
794
781
}
795
782
Local<Value> value =
796
- args[i] .As <Object>()->Get (env->produce_cached_data_string ());
783
+ options .As <Object>()->Get (env->produce_cached_data_string ());
797
784
798
785
return value->IsTrue ();
799
786
}
800
787
801
788
802
- static Local<Integer> GetLineOffsetArg (
803
- const FunctionCallbackInfo<Value>& args,
804
- const int i) {
805
- Local<Integer> defaultLineOffset = Integer::New (args.GetIsolate (), 0 );
789
+ static Local<Integer> GetLineOffsetArg (Environment* env,
790
+ Local<Value> options) {
791
+ Local<Integer> defaultLineOffset = Integer::New (env->isolate (), 0 );
806
792
807
- if (!args[i] ->IsObject ()) {
793
+ if (!options ->IsObject ()) {
808
794
return defaultLineOffset;
809
795
}
810
796
811
- Local<String> key = FIXED_ONE_BYTE_STRING (args. GetIsolate (), " lineOffset" );
812
- Local<Value> value = args[i] .As <Object>()->Get (key);
797
+ Local<String> key = FIXED_ONE_BYTE_STRING (env-> isolate (), " lineOffset" );
798
+ Local<Value> value = options .As <Object>()->Get (key);
813
799
814
800
return value->IsUndefined () ? defaultLineOffset : value->ToInteger ();
815
801
}
816
802
817
803
818
- static Local<Integer> GetColumnOffsetArg (
819
- const FunctionCallbackInfo<Value>& args,
820
- const int i) {
821
- Local<Integer> defaultColumnOffset = Integer::New (args.GetIsolate (), 0 );
804
+ static Local<Integer> GetColumnOffsetArg (Environment* env,
805
+ Local<Value> options) {
806
+ Local<Integer> defaultColumnOffset = Integer::New (env->isolate (), 0 );
822
807
823
- if (!args[i] ->IsObject ()) {
808
+ if (!options ->IsObject ()) {
824
809
return defaultColumnOffset;
825
810
}
826
811
827
- Local<String> key = FIXED_ONE_BYTE_STRING (args.GetIsolate (),
828
- " columnOffset" );
829
- Local<Value> value = args[i].As <Object>()->Get (key);
812
+ Local<String> key = FIXED_ONE_BYTE_STRING (env->isolate (), " columnOffset" );
813
+ Local<Value> value = options.As <Object>()->Get (key);
830
814
831
815
return value->IsUndefined () ? defaultColumnOffset : value->ToInteger ();
832
816
}
0 commit comments