diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-20 07:55:59 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-04 05:14:52 +0800 |
commit | d005f382cdcec7dff1d61cf5ab3604e55f004471 (patch) | |
tree | 1bd90722e3a03aadfe6722d2e486185ead6eef9e /src | |
parent | 10eaf6a09feee78275d5c1f84ce46815d8a8772f (diff) | |
download | android-node-v8-d005f382cdcec7dff1d61cf5ab3604e55f004471.tar.gz android-node-v8-d005f382cdcec7dff1d61cf5ab3604e55f004471.tar.bz2 android-node-v8-d005f382cdcec7dff1d61cf5ab3604e55f004471.zip |
process: store argv in Environment
This gets rid of Environment::ExecutionMode as well now that
we use the original arguments to determine execution mode.
PR-URL: https://github.com/nodejs/node/pull/26945
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/env-inl.h | 4 | ||||
-rw-r--r-- | src/env.cc | 13 | ||||
-rw-r--r-- | src/env.h | 20 | ||||
-rw-r--r-- | src/node.cc | 17 | ||||
-rw-r--r-- | src/node_worker.cc | 4 | ||||
-rw-r--r-- | src/node_worker.h | 2 |
6 files changed, 19 insertions, 41 deletions
diff --git a/src/env-inl.h b/src/env-inl.h index ef13ffdcc0..bce36c0f69 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -630,6 +630,10 @@ inline std::shared_ptr<EnvironmentOptions> Environment::options() { return options_; } +inline const std::vector<std::string>& Environment::argv() { + return argv_; +} + inline const std::vector<std::string>& Environment::exec_argv() { return exec_argv_; } diff --git a/src/env.cc b/src/env.cc index 46f807a3c4..cc8554032e 100644 --- a/src/env.cc +++ b/src/env.cc @@ -350,16 +350,8 @@ void Environment::ExitEnv() { MaybeLocal<Object> Environment::ProcessCliArgs( const std::vector<std::string>& args, const std::vector<std::string>& exec_args) { - if (args.size() > 1) { - std::string first_arg = args[1]; - if (first_arg == "inspect") { - execution_mode_ = ExecutionMode::kInspect; - } else if (first_arg == "debug") { - execution_mode_ = ExecutionMode::kDebug; - } else if (first_arg != "-") { - execution_mode_ = ExecutionMode::kRunMainModule; - } - } + argv_ = args; + exec_argv_ = exec_args; if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( TRACING_CATEGORY_NODE1(environment)) != 0) { @@ -377,7 +369,6 @@ 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>()); @@ -761,6 +761,7 @@ class Environment { const std::vector<std::string>& args, const std::vector<std::string>& exec_args); inline const std::vector<std::string>& exec_argv(); + inline const std::vector<std::string>& argv(); typedef void (*HandleCleanupCb)(Environment* env, uv_handle_t* handle, @@ -1057,23 +1058,6 @@ class Environment { inline std::shared_ptr<EnvironmentOptions> options(); inline std::shared_ptr<HostPort> inspector_host_port(); - enum class ExecutionMode { - kDefault, - kInspect, // node inspect - kDebug, // node debug - kPrintHelp, // node --help - kPrintBashCompletion, // node --completion-bash - kProfProcess, // node --prof-process - kEvalString, // node --eval without --interactive - kCheckSyntax, // node --check (incompatible with --eval) - kRepl, - kEvalStdin, - kRunMainModule - }; - - inline ExecutionMode execution_mode() { return execution_mode_; } - - inline void set_execution_mode(ExecutionMode mode) { execution_mode_ = mode; } inline AsyncRequest* thread_stopper() { return &thread_stopper_; } private: @@ -1085,7 +1069,6 @@ class Environment { inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), const char* errmsg); - ExecutionMode execution_mode_ = ExecutionMode::kDefault; std::list<binding::DLib> loaded_addons_; v8::Isolate* const isolate_; IsolateData* const isolate_data_; @@ -1117,6 +1100,7 @@ class Environment { // used. std::shared_ptr<HostPort> inspector_host_port_; std::vector<std::string> exec_argv_; + std::vector<std::string> argv_; uint32_t module_id_counter_ = 0; uint32_t script_id_counter_ = 0; diff --git a/src/node.cc b/src/node.cc index b980493009..3401ce30b2 100644 --- a/src/node.cc +++ b/src/node.cc @@ -402,47 +402,44 @@ MaybeLocal<Value> StartMainThreadExecution(Environment* env) { return StartExecution(env, "internal/main/run_third_party_main"); } - if (env->execution_mode() == Environment::ExecutionMode::kInspect || - env->execution_mode() == Environment::ExecutionMode::kDebug) { + std::string first_argv; + if (env->argv().size() > 1) { + first_argv = env->argv()[1]; + } + + if (first_argv == "inspect" || first_argv == "debug") { return StartExecution(env, "internal/main/inspect"); } if (per_process::cli_options->print_help) { - env->set_execution_mode(Environment::ExecutionMode::kPrintHelp); return StartExecution(env, "internal/main/print_help"); } if (per_process::cli_options->print_bash_completion) { - env->set_execution_mode(Environment::ExecutionMode::kPrintBashCompletion); return StartExecution(env, "internal/main/print_bash_completion"); } if (env->options()->prof_process) { - env->set_execution_mode(Environment::ExecutionMode::kProfProcess); return StartExecution(env, "internal/main/prof_process"); } // -e/--eval without -i/--interactive if (env->options()->has_eval_string && !env->options()->force_repl) { - env->set_execution_mode(Environment::ExecutionMode::kEvalString); return StartExecution(env, "internal/main/eval_string"); } if (env->options()->syntax_check_only) { - env->set_execution_mode(Environment::ExecutionMode::kCheckSyntax); return StartExecution(env, "internal/main/check_syntax"); } - if (env->execution_mode() == Environment::ExecutionMode::kRunMainModule) { + if (!first_argv.empty() && first_argv != "-") { return StartExecution(env, "internal/main/run_main_module"); } if (env->options()->force_repl || uv_guess_handle(STDIN_FILENO) == UV_TTY) { - env->set_execution_mode(Environment::ExecutionMode::kRepl); return StartExecution(env, "internal/main/repl"); } - env->set_execution_mode(Environment::ExecutionMode::kEvalStdin); return StartExecution(env, "internal/main/eval_stdin"); } diff --git a/src/node_worker.cc b/src/node_worker.cc index 8fabbffba4..c93584c68c 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -96,6 +96,7 @@ Worker::Worker(Environment* env, env->inspector_agent()->GetParentHandle(thread_id_, url); #endif + argv_ = std::vector<std::string>{env->argv()[0]}; // Mark this Worker object as weak until we actually start the thread. MakeWeak(); @@ -260,8 +261,7 @@ void Worker::Run() { env_->set_worker_context(this); env_->InitializeLibuv(profiler_idle_notifier_started_); - env_->ProcessCliArgs(std::vector<std::string>{}, - std::move(exec_argv_)); + env_->ProcessCliArgs(std::move(argv_), std::move(exec_argv_)); } { Mutex::ScopedLock lock(mutex_); diff --git a/src/node_worker.h b/src/node_worker.h index 94af8160c6..8239826a0e 100644 --- a/src/node_worker.h +++ b/src/node_worker.h @@ -58,6 +58,8 @@ class Worker : public AsyncWrap { std::shared_ptr<PerIsolateOptions> per_isolate_opts_; std::vector<std::string> exec_argv_; + std::vector<std::string> argv_; + MultiIsolatePlatform* platform_; v8::Isolate* isolate_ = nullptr; bool profiler_idle_notifier_started_; |