diff --git a/src/api/environment.cc b/src/api/environment.cc index 2e2bf9027804a2..29cf7ab808a2aa 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -216,7 +216,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data, static_cast(Environment::kIsMainThread | Environment::kOwnsProcessState | Environment::kOwnsInspector)); - env->Start(per_process::v8_is_profiling); + env->InitializeLibuv(per_process::v8_is_profiling); env->ProcessCliArgs(args, exec_args); return env; } diff --git a/src/env.cc b/src/env.cc index ac4266ab15ecab..767cde7ae79241 100644 --- a/src/env.cc +++ b/src/env.cc @@ -320,7 +320,7 @@ Environment::~Environment() { } } -void Environment::Start(bool start_profiler_idle_notifier) { +void Environment::InitializeLibuv(bool start_profiler_idle_notifier) { HandleScope handle_scope(isolate()); Context::Scope context_scope(context()); diff --git a/src/env.h b/src/env.h index a82502f81fdf2f..a43ca3034d31b8 100644 --- a/src/env.h +++ b/src/env.h @@ -673,7 +673,7 @@ class Environment { uint64_t thread_id = kNoThreadId); ~Environment(); - void Start(bool start_profiler_idle_notifier); + void InitializeLibuv(bool start_profiler_idle_notifier); v8::MaybeLocal ProcessCliArgs( const std::vector& args, const std::vector& exec_args); diff --git a/src/node.cc b/src/node.cc index 7b983e042d12fc..f7ce82b3258ce7 100644 --- a/src/node.cc +++ b/src/node.cc @@ -610,10 +610,10 @@ int ProcessGlobalArgs(std::vector* args, static std::atomic_bool init_called{false}; -int Init(std::vector* argv, - std::vector* exec_argv, - std::vector* errors) { - // Make sure Init() is called only once. +int InitializeNodeWithArgs(std::vector* argv, + std::vector* exec_argv, + std::vector* errors) { + // Make sure InitializeNodeWithArgs() is called only once. CHECK(!init_called.exchange(true)); // Register built-in modules @@ -724,7 +724,7 @@ void Init(int* argc, // This (approximately) duplicates some logic that has been moved to // node::Start(), with the difference that here we explicitly call `exit()`. - int exit_code = Init(&argv_, &exec_argv_, &errors); + int exit_code = InitializeNodeWithArgs(&argv_, &exec_argv_, &errors); for (const std::string& error : errors) fprintf(stderr, "%s: %s\n", argv_.at(0).c_str(), error.c_str()); @@ -759,9 +759,10 @@ void RunBeforeExit(Environment* env) { EmitBeforeExit(env); } -inline int Start(Isolate* isolate, IsolateData* isolate_data, - const std::vector& args, - const std::vector& exec_args) { +inline int StartNodeWithIsolate(Isolate* isolate, + IsolateData* isolate_data, + const std::vector& args, + const std::vector& exec_args) { HandleScope handle_scope(isolate); Local context = NewContext(isolate); Context::Scope context_scope(context); @@ -772,7 +773,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, static_cast(Environment::kIsMainThread | Environment::kOwnsProcessState | Environment::kOwnsInspector)); - env.Start(per_process::v8_is_profiling); + env.InitializeLibuv(per_process::v8_is_profiling); env.ProcessCliArgs(args, exec_args); #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM @@ -848,25 +849,15 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, return exit_code; } -inline int Start(uv_loop_t* event_loop, - const std::vector& args, - const std::vector& exec_args) { +inline int StartNodeWithLoopAndArgs(uv_loop_t* event_loop, + const std::vector& args, + const std::vector& exec_args) { std::unique_ptr allocator(CreateArrayBufferAllocator(), &FreeArrayBufferAllocator); Isolate* const isolate = NewIsolate(allocator.get(), event_loop); if (isolate == nullptr) return 12; // Signal internal error. - if (per_process::cli_options->print_version) { - printf("%s\n", NODE_VERSION); - return 0; - } - - if (per_process::cli_options->print_v8_help) { - V8::SetFlagsFromString("--help", 6); // Doesn't return. - UNREACHABLE(); - } - int exit_code; { Locker locker(isolate); @@ -884,7 +875,7 @@ inline int Start(uv_loop_t* event_loop, isolate->GetHeapProfiler()->StartTrackingHeapObjects(true); } exit_code = - Start(isolate, isolate_data.get(), args, exec_args); + StartNodeWithIsolate(isolate, isolate_data.get(), args, exec_args); } isolate->Dispose(); @@ -916,12 +907,22 @@ int Start(int argc, char** argv) { std::vector errors; // This needs to run *before* V8::Initialize(). { - const int exit_code = Init(&args, &exec_args, &errors); + const int exit_code = InitializeNodeWithArgs(&args, &exec_args, &errors); for (const std::string& error : errors) fprintf(stderr, "%s: %s\n", args.at(0).c_str(), error.c_str()); if (exit_code != 0) return exit_code; } + if (per_process::cli_options->print_version) { + printf("%s\n", NODE_VERSION); + return 0; + } + + if (per_process::cli_options->print_v8_help) { + V8::SetFlagsFromString("--help", 6); // Doesn't return. + UNREACHABLE(); + } + #if HAVE_OPENSSL { std::string extra_ca_certs; @@ -943,7 +944,7 @@ int Start(int argc, char** argv) { performance::performance_v8_start = PERFORMANCE_NOW(); per_process::v8_initialized = true; const int exit_code = - Start(uv_default_loop(), args, exec_args); + StartNodeWithLoopAndArgs(uv_default_loop(), args, exec_args); per_process::v8_initialized = false; V8::Dispose(); diff --git a/src/node_worker.cc b/src/node_worker.cc index b6a56b9b94b08e..982cf522a88e93 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -284,7 +284,7 @@ void Worker::Run() { env_->set_abort_on_uncaught_exception(false); env_->set_worker_context(this); - env_->Start(profiler_idle_notifier_started_); + env_->InitializeLibuv(profiler_idle_notifier_started_); env_->ProcessCliArgs(std::vector{}, std::move(exec_argv_)); }