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>
This commit is contained in:
parent
10eaf6a09f
commit
d005f382cd
@ -630,6 +630,10 @@ inline std::shared_ptr<EnvironmentOptions> Environment::options() {
|
|||||||
return options_;
|
return options_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const std::vector<std::string>& Environment::argv() {
|
||||||
|
return argv_;
|
||||||
|
}
|
||||||
|
|
||||||
inline const std::vector<std::string>& Environment::exec_argv() {
|
inline const std::vector<std::string>& Environment::exec_argv() {
|
||||||
return exec_argv_;
|
return exec_argv_;
|
||||||
}
|
}
|
||||||
|
13
src/env.cc
13
src/env.cc
@ -350,16 +350,8 @@ void Environment::ExitEnv() {
|
|||||||
MaybeLocal<Object> Environment::ProcessCliArgs(
|
MaybeLocal<Object> Environment::ProcessCliArgs(
|
||||||
const std::vector<std::string>& args,
|
const std::vector<std::string>& args,
|
||||||
const std::vector<std::string>& exec_args) {
|
const std::vector<std::string>& exec_args) {
|
||||||
if (args.size() > 1) {
|
argv_ = args;
|
||||||
std::string first_arg = args[1];
|
exec_argv_ = exec_args;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
|
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
|
||||||
TRACING_CATEGORY_NODE1(environment)) != 0) {
|
TRACING_CATEGORY_NODE1(environment)) != 0) {
|
||||||
@ -377,7 +369,6 @@ MaybeLocal<Object> Environment::ProcessCliArgs(
|
|||||||
std::move(traced_value));
|
std::move(traced_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_argv_ = exec_args;
|
|
||||||
Local<Object> process_object =
|
Local<Object> process_object =
|
||||||
node::CreateProcessObject(this, args, exec_args)
|
node::CreateProcessObject(this, args, exec_args)
|
||||||
.FromMaybe(Local<Object>());
|
.FromMaybe(Local<Object>());
|
||||||
|
20
src/env.h
20
src/env.h
@ -761,6 +761,7 @@ class Environment {
|
|||||||
const std::vector<std::string>& args,
|
const std::vector<std::string>& args,
|
||||||
const std::vector<std::string>& exec_args);
|
const std::vector<std::string>& exec_args);
|
||||||
inline const std::vector<std::string>& exec_argv();
|
inline const std::vector<std::string>& exec_argv();
|
||||||
|
inline const std::vector<std::string>& argv();
|
||||||
|
|
||||||
typedef void (*HandleCleanupCb)(Environment* env,
|
typedef void (*HandleCleanupCb)(Environment* env,
|
||||||
uv_handle_t* handle,
|
uv_handle_t* handle,
|
||||||
@ -1057,23 +1058,6 @@ class Environment {
|
|||||||
inline std::shared_ptr<EnvironmentOptions> options();
|
inline std::shared_ptr<EnvironmentOptions> options();
|
||||||
inline std::shared_ptr<HostPort> inspector_host_port();
|
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_; }
|
inline AsyncRequest* thread_stopper() { return &thread_stopper_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -1085,7 +1069,6 @@ class Environment {
|
|||||||
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
|
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
|
||||||
const char* errmsg);
|
const char* errmsg);
|
||||||
|
|
||||||
ExecutionMode execution_mode_ = ExecutionMode::kDefault;
|
|
||||||
std::list<binding::DLib> loaded_addons_;
|
std::list<binding::DLib> loaded_addons_;
|
||||||
v8::Isolate* const isolate_;
|
v8::Isolate* const isolate_;
|
||||||
IsolateData* const isolate_data_;
|
IsolateData* const isolate_data_;
|
||||||
@ -1117,6 +1100,7 @@ class Environment {
|
|||||||
// used.
|
// used.
|
||||||
std::shared_ptr<HostPort> inspector_host_port_;
|
std::shared_ptr<HostPort> inspector_host_port_;
|
||||||
std::vector<std::string> exec_argv_;
|
std::vector<std::string> exec_argv_;
|
||||||
|
std::vector<std::string> argv_;
|
||||||
|
|
||||||
uint32_t module_id_counter_ = 0;
|
uint32_t module_id_counter_ = 0;
|
||||||
uint32_t script_id_counter_ = 0;
|
uint32_t script_id_counter_ = 0;
|
||||||
|
17
src/node.cc
17
src/node.cc
@ -402,47 +402,44 @@ MaybeLocal<Value> StartMainThreadExecution(Environment* env) {
|
|||||||
return StartExecution(env, "internal/main/run_third_party_main");
|
return StartExecution(env, "internal/main/run_third_party_main");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env->execution_mode() == Environment::ExecutionMode::kInspect ||
|
std::string first_argv;
|
||||||
env->execution_mode() == Environment::ExecutionMode::kDebug) {
|
if (env->argv().size() > 1) {
|
||||||
|
first_argv = env->argv()[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first_argv == "inspect" || first_argv == "debug") {
|
||||||
return StartExecution(env, "internal/main/inspect");
|
return StartExecution(env, "internal/main/inspect");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (per_process::cli_options->print_help) {
|
if (per_process::cli_options->print_help) {
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kPrintHelp);
|
|
||||||
return StartExecution(env, "internal/main/print_help");
|
return StartExecution(env, "internal/main/print_help");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (per_process::cli_options->print_bash_completion) {
|
if (per_process::cli_options->print_bash_completion) {
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kPrintBashCompletion);
|
|
||||||
return StartExecution(env, "internal/main/print_bash_completion");
|
return StartExecution(env, "internal/main/print_bash_completion");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env->options()->prof_process) {
|
if (env->options()->prof_process) {
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kProfProcess);
|
|
||||||
return StartExecution(env, "internal/main/prof_process");
|
return StartExecution(env, "internal/main/prof_process");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -e/--eval without -i/--interactive
|
// -e/--eval without -i/--interactive
|
||||||
if (env->options()->has_eval_string && !env->options()->force_repl) {
|
if (env->options()->has_eval_string && !env->options()->force_repl) {
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kEvalString);
|
|
||||||
return StartExecution(env, "internal/main/eval_string");
|
return StartExecution(env, "internal/main/eval_string");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env->options()->syntax_check_only) {
|
if (env->options()->syntax_check_only) {
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kCheckSyntax);
|
|
||||||
return StartExecution(env, "internal/main/check_syntax");
|
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");
|
return StartExecution(env, "internal/main/run_main_module");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env->options()->force_repl || uv_guess_handle(STDIN_FILENO) == UV_TTY) {
|
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");
|
return StartExecution(env, "internal/main/repl");
|
||||||
}
|
}
|
||||||
|
|
||||||
env->set_execution_mode(Environment::ExecutionMode::kEvalStdin);
|
|
||||||
return StartExecution(env, "internal/main/eval_stdin");
|
return StartExecution(env, "internal/main/eval_stdin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ Worker::Worker(Environment* env,
|
|||||||
env->inspector_agent()->GetParentHandle(thread_id_, url);
|
env->inspector_agent()->GetParentHandle(thread_id_, url);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
argv_ = std::vector<std::string>{env->argv()[0]};
|
||||||
// Mark this Worker object as weak until we actually start the thread.
|
// Mark this Worker object as weak until we actually start the thread.
|
||||||
MakeWeak();
|
MakeWeak();
|
||||||
|
|
||||||
@ -260,8 +261,7 @@ void Worker::Run() {
|
|||||||
env_->set_worker_context(this);
|
env_->set_worker_context(this);
|
||||||
|
|
||||||
env_->InitializeLibuv(profiler_idle_notifier_started_);
|
env_->InitializeLibuv(profiler_idle_notifier_started_);
|
||||||
env_->ProcessCliArgs(std::vector<std::string>{},
|
env_->ProcessCliArgs(std::move(argv_), std::move(exec_argv_));
|
||||||
std::move(exec_argv_));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Mutex::ScopedLock lock(mutex_);
|
Mutex::ScopedLock lock(mutex_);
|
||||||
|
@ -58,6 +58,8 @@ class Worker : public AsyncWrap {
|
|||||||
|
|
||||||
std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
|
std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
|
||||||
std::vector<std::string> exec_argv_;
|
std::vector<std::string> exec_argv_;
|
||||||
|
std::vector<std::string> argv_;
|
||||||
|
|
||||||
MultiIsolatePlatform* platform_;
|
MultiIsolatePlatform* platform_;
|
||||||
v8::Isolate* isolate_ = nullptr;
|
v8::Isolate* isolate_ = nullptr;
|
||||||
bool profiler_idle_notifier_started_;
|
bool profiler_idle_notifier_started_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user