| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5d8ee51 commit fe1f740
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | 25 | ArrayPrototypeForEach, | |
| 26 | - ArrayPrototypeUnshift, | ||
| 27 | 26 | Symbol, | |
| 28 | 27 | PromiseReject, | |
| 29 | 28 | ReflectApply, | |
@@ -123,17 +122,19 @@ class Script extends ContextifyScript { | |||
| 123 | 122 | } | |
| 124 | 123 | ||
| 125 | 124 | runInThisContext(options) { | |
| 126 | - const { breakOnSigint, args } = getRunInContextArgs(options); | ||
| 125 | + const { breakOnSigint, args } = getRunInContextArgs(null, options); | ||
| 127 | 126 | if (breakOnSigint && process.listenerCount('SIGINT') > 0) { | |
| 128 | - return sigintHandlersWrap(super.runInThisContext, this, args); | ||
| 127 | + return sigintHandlersWrap(super.runInContext, this, args); | ||
| 129 | 128 | } | |
| 130 | - return ReflectApply(super.runInThisContext, this, args); | ||
| 129 | + return ReflectApply(super.runInContext, this, args); | ||
| 131 | 130 | } | |
| 132 | 131 | ||
| 133 | 132 | runInContext(contextifiedObject, options) { | |
| 134 | 133 | validateContext(contextifiedObject); | |
| 135 | - const { breakOnSigint, args } = getRunInContextArgs(options); | ||
| 136 | - ArrayPrototypeUnshift(args, contextifiedObject); | ||
| 134 | + const { breakOnSigint, args } = getRunInContextArgs( | ||
| 135 | + contextifiedObject, | ||
| 136 | + options, | ||
| 137 | + ); | ||
| 137 | 138 | if (breakOnSigint && process.listenerCount('SIGINT') > 0) { | |
| 138 | 139 | return sigintHandlersWrap(super.runInContext, this, args); | |
| 139 | 140 | } | |
@@ -153,7 +154,7 @@ function validateContext(contextifiedObject) { | |||
| 153 | 154 | } | |
| 154 | 155 | } | |
| 155 | 156 | ||
| 156 | - function getRunInContextArgs(options = kEmptyObject) { | ||
| 157 | + function getRunInContextArgs(contextifiedObject, options = kEmptyObject) { | ||
| 157 | 158 | validateObject(options, 'options'); | |
| 158 | 159 | ||
| 159 | 160 | let timeout = options.timeout; | |
@@ -174,7 +175,13 @@ function getRunInContextArgs(options = kEmptyObject) { | |||
| 174 | 175 | ||
| 175 | 176 | return { | |
| 176 | 177 | breakOnSigint, | |
| 177 | - args: [timeout, displayErrors, breakOnSigint, breakFirstLine] | ||
| 178 | + args: [ | ||
| 179 | + contextifiedObject, | ||
| 180 | + timeout, | ||
| 181 | + displayErrors, | ||
| 182 | + breakOnSigint, | ||
| 183 | + breakFirstLine, | ||
| 184 | + ], | ||
| 178 | 185 | }; | |
| 179 | 186 | } | |
| 180 | 187 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,9 +148,7 @@ class ContextifyScript : public BaseObject { | |||
| 148 | 148 | static void RegisterExternalReferences(ExternalReferenceRegistry* registry); | |
| 149 | 149 | static void New(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 150 | 150 | static bool InstanceOf(Environment* env, const v8::Local<v8::Value>& args); | |
| 151 | - static void CreateCachedData( | ||
| 152 | - const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 153 | - static void RunInThisContext(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 151 | + static void CreateCachedData(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 154 | 152 | static void RunInContext(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 155 | 153 | static bool EvalMachine(Environment* env, | |
| 156 | 154 | const int64_t timeout, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ const tmpdir = require('../common/tmpdir'); | |||
| 8 | 8 | ||
| 9 | 9 | const names = [ | |
| 10 | 10 | 'ContextifyScript::New', | |
| 11 | - 'RunInThisContext', | ||
| 12 | 11 | 'RunInContext', | |
| 13 | 12 | ]; | |
| 14 | 13 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments