diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-22 21:01:22 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-02 13:16:35 +0100 |
commit | f65b4afaea14446c4b313595c03b737ab710c124 (patch) | |
tree | 8c424301f605bcc6f0cd715c0822adb75c9f309f /src | |
parent | b8018f407b2ae2daa70d41b2aa9dbbc5ca921b0f (diff) | |
download | android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.tar.gz android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.tar.bz2 android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.zip |
worker: provide process.execArgv
Provide `process.execArgv`. If an `execArgv` option is passed to the
`Worker` constructor, that option is used as its value; if not,
the parent’s `process.execArgv` is inherited (since that also goes
for the actual options in that case).
PR-URL: https://github.com/nodejs/node/pull/26267
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/env-inl.h | 4 | ||||
-rw-r--r-- | src/env.cc | 1 | ||||
-rw-r--r-- | src/env.h | 2 | ||||
-rw-r--r-- | src/node_worker.cc | 16 | ||||
-rw-r--r-- | src/node_worker.h | 4 |
5 files changed, 22 insertions, 5 deletions
diff --git a/src/env-inl.h b/src/env-inl.h index 824b7529a9..b233d2fddf 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -605,6 +605,10 @@ inline std::shared_ptr<EnvironmentOptions> Environment::options() { return options_; } +inline const std::vector<std::string>& Environment::exec_argv() { + return exec_argv_; +} + inline std::shared_ptr<HostPort> Environment::inspector_host_port() { return inspector_host_port_; } diff --git a/src/env.cc b/src/env.cc index 321e259152..63ea65380d 100644 --- a/src/env.cc +++ b/src/env.cc @@ -386,6 +386,7 @@ MaybeLocal<Object> Environment::ProcessCliArgs( std::move(traced_value)); } + exec_argv_ = exec_args; Local<Object> process_object = node::CreateProcessObject(this, args, exec_args) .FromMaybe(Local<Object>()); @@ -676,6 +676,7 @@ class Environment { v8::MaybeLocal<v8::Object> ProcessCliArgs( const std::vector<std::string>& args, const std::vector<std::string>& exec_args); + inline const std::vector<std::string>& exec_argv(); typedef void (*HandleCleanupCb)(Environment* env, uv_handle_t* handle, @@ -1060,6 +1061,7 @@ class Environment { // the inspector_host_port_->port() will be the actual port being // used. std::shared_ptr<HostPort> inspector_host_port_; + std::vector<std::string> exec_argv_; uint32_t module_id_counter_ = 0; uint32_t script_id_counter_ = 0; diff --git a/src/node_worker.cc b/src/node_worker.cc index 0f1535074c..b6a56b9b94 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -101,10 +101,12 @@ void AsyncRequest::MemoryInfo(MemoryTracker* tracker) const { Worker::Worker(Environment* env, Local<Object> wrap, const std::string& url, - std::shared_ptr<PerIsolateOptions> per_isolate_opts) + std::shared_ptr<PerIsolateOptions> per_isolate_opts, + std::vector<std::string>&& exec_argv) : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_WORKER), url_(url), per_isolate_opts_(per_isolate_opts), + exec_argv_(exec_argv), platform_(env->isolate_data()->platform()), profiler_idle_notifier_started_(env->profiler_idle_notifier_started()), thread_id_(Environment::AllocateThreadId()) { @@ -284,7 +286,7 @@ void Worker::Run() { env_->Start(profiler_idle_notifier_started_); env_->ProcessCliArgs(std::vector<std::string>{}, - std::vector<std::string>{}); + std::move(exec_argv_)); } Debug(this, "Created Environment for worker with id %llu", thread_id_); @@ -434,6 +436,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { std::string url; std::shared_ptr<PerIsolateOptions> per_isolate_opts = nullptr; + std::vector<std::string> exec_argv_out; + bool has_explicit_exec_argv = false; + // Argument might be a string or URL if (args.Length() > 0 && !args[0]->IsNullOrUndefined()) { Utf8Value value( @@ -445,6 +450,7 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { v8::Local<v8::Array> array = args[1].As<v8::Array>(); // The first argument is reserved for program name, but we don't need it // in workers. + has_explicit_exec_argv = true; std::vector<std::string> exec_argv = {""}; uint32_t length = array->Length(); for (uint32_t i = 0; i < length; i++) { @@ -472,7 +478,7 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { // options for the per isolate parser. options_parser::PerIsolateOptionsParser::instance.Parse( &exec_argv, - nullptr, + &exec_argv_out, &invalid_args, per_isolate_opts.get(), kDisallowedInEnvironment, @@ -492,7 +498,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { } } } - new Worker(env, args.This(), url, per_isolate_opts); + if (!has_explicit_exec_argv) + exec_argv_out = env->exec_argv(); + new Worker(env, args.This(), url, per_isolate_opts, std::move(exec_argv_out)); } void Worker::StartThread(const FunctionCallbackInfo<Value>& args) { diff --git a/src/node_worker.h b/src/node_worker.h index fb94bdc307..442056eaac 100644 --- a/src/node_worker.h +++ b/src/node_worker.h @@ -38,7 +38,8 @@ class Worker : public AsyncWrap { Worker(Environment* env, v8::Local<v8::Object> wrap, const std::string& url, - std::shared_ptr<PerIsolateOptions> per_isolate_opts); + std::shared_ptr<PerIsolateOptions> per_isolate_opts, + std::vector<std::string>&& exec_argv); ~Worker() override; // Run the worker. This is only called from the worker thread. @@ -74,6 +75,7 @@ class Worker : public AsyncWrap { const std::string url_; std::shared_ptr<PerIsolateOptions> per_isolate_opts_; + std::vector<std::string> exec_argv_; MultiIsolatePlatform* platform_; v8::Isolate* isolate_ = nullptr; bool profiler_idle_notifier_started_; |