@@ -663,7 +663,6 @@ void ContextifyScript::Init(Environment* env, Local<Object> target) {
663
663
script_tmpl->SetClassName (class_name);
664
664
env->SetProtoMethod (script_tmpl, " createCachedData" , CreateCachedData);
665
665
env->SetProtoMethod (script_tmpl, " runInContext" , RunInContext);
666
- env->SetProtoMethod (script_tmpl, " runInThisContext" , RunInThisContext);
667
666
668
667
Local<Context> context = env->context ();
669
668
@@ -677,7 +676,6 @@ void ContextifyScript::RegisterExternalReferences(
677
676
registry->Register (New);
678
677
registry->Register (CreateCachedData);
679
678
registry->Register (RunInContext);
680
- registry->Register (RunInThisContext);
681
679
}
682
680
683
681
void ContextifyScript::New (const FunctionCallbackInfo<Value>& args) {
@@ -844,59 +842,33 @@ void ContextifyScript::CreateCachedData(
844
842
}
845
843
}
846
844
847
- void ContextifyScript::RunInThisContext (
848
- const FunctionCallbackInfo<Value>& args) {
849
- Environment* env = Environment::GetCurrent (args);
850
-
851
- ContextifyScript* wrapped_script;
852
- ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.Holder ());
853
-
854
- TRACE_EVENT0 (TRACING_CATEGORY_NODE2 (vm, script), " RunInThisContext" );
855
-
856
- // TODO(addaleax): Use an options object or otherwise merge this with
857
- // RunInContext().
858
- CHECK_EQ (args.Length (), 4 );
859
-
860
- CHECK (args[0 ]->IsNumber ());
861
- int64_t timeout = args[0 ]->IntegerValue (env->context ()).FromJust ();
862
-
863
- CHECK (args[1 ]->IsBoolean ());
864
- bool display_errors = args[1 ]->IsTrue ();
865
-
866
- CHECK (args[2 ]->IsBoolean ());
867
- bool break_on_sigint = args[2 ]->IsTrue ();
868
-
869
- CHECK (args[3 ]->IsBoolean ());
870
- bool break_on_first_line = args[3 ]->IsTrue ();
871
-
872
- // Do the eval within this context
873
- EvalMachine (env,
874
- timeout,
875
- display_errors,
876
- break_on_sigint,
877
- break_on_first_line,
878
- nullptr , // microtask_queue
879
- args);
880
- }
881
-
882
845
void ContextifyScript::RunInContext (const FunctionCallbackInfo<Value>& args) {
883
846
Environment* env = Environment::GetCurrent (args);
884
847
885
848
ContextifyScript* wrapped_script;
886
849
ASSIGN_OR_RETURN_UNWRAP (&wrapped_script, args.Holder ());
887
850
888
851
CHECK_EQ (args.Length (), 5 );
852
+ CHECK (args[0 ]->IsObject () || args[0 ]->IsNull ());
889
853
890
- CHECK (args[0 ]->IsObject ());
891
- Local<Object> sandbox = args[0 ].As <Object>();
892
- // Get the context from the sandbox
893
- ContextifyContext* contextify_context =
894
- ContextifyContext::ContextFromContextifiedSandbox (env, sandbox);
895
- CHECK_NOT_NULL (contextify_context);
854
+ Local<Context> context;
855
+ std::shared_ptr<v8::MicrotaskQueue> microtask_queue;
896
856
897
- Local<Context> context = contextify_context->context ();
898
- if (context.IsEmpty ())
899
- return ;
857
+ if (args[0 ]->IsObject ()) {
858
+ Local<Object> sandbox = args[0 ].As <Object>();
859
+ // Get the context from the sandbox
860
+ ContextifyContext* contextify_context =
861
+ ContextifyContext::ContextFromContextifiedSandbox (env, sandbox);
862
+ CHECK_NOT_NULL (contextify_context);
863
+ CHECK_EQ (contextify_context->env (), env);
864
+
865
+ context = contextify_context->context ();
866
+ if (context.IsEmpty ()) return ;
867
+
868
+ microtask_queue = contextify_context->microtask_queue ();
869
+ } else {
870
+ context = env->context ();
871
+ }
900
872
901
873
TRACE_EVENT0 (TRACING_CATEGORY_NODE2 (vm, script), " RunInContext" );
902
874
@@ -914,12 +886,12 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
914
886
915
887
// Do the eval within the context
916
888
Context::Scope context_scope (context);
917
- EvalMachine (contextify_context-> env () ,
889
+ EvalMachine (env,
918
890
timeout,
919
891
display_errors,
920
892
break_on_sigint,
921
893
break_on_first_line,
922
- contextify_context-> microtask_queue () ,
894
+ microtask_queue,
923
895
args);
924
896
}
925
897
0 commit comments