Skip to content

Commit 8822df8

Browse files
joyeecheungBridgeAR
authored andcommitted
src: rename Init and Start overloads to something more distinctive
In addition, move the `--help` and `--v8-help` processing out of `StartNodeWithLoopAndArgs()` and process them earlier - right after `InitializeNodeWithArgs()`, similar to how they are handled in the legacy `Init()`. PR-URL: #26499 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent e2aaee0 commit 8822df8

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

src/api/environment.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
216216
static_cast<Environment::Flags>(Environment::kIsMainThread |
217217
Environment::kOwnsProcessState |
218218
Environment::kOwnsInspector));
219-
env->Start(per_process::v8_is_profiling);
219+
env->InitializeLibuv(per_process::v8_is_profiling);
220220
env->ProcessCliArgs(args, exec_args);
221221
return env;
222222
}

src/env.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ Environment::~Environment() {
320320
}
321321
}
322322

323-
void Environment::Start(bool start_profiler_idle_notifier) {
323+
void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
324324
HandleScope handle_scope(isolate());
325325
Context::Scope context_scope(context());
326326

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ class Environment {
673673
uint64_t thread_id = kNoThreadId);
674674
~Environment();
675675

676-
void Start(bool start_profiler_idle_notifier);
676+
void InitializeLibuv(bool start_profiler_idle_notifier);
677677
v8::MaybeLocal<v8::Object> ProcessCliArgs(
678678
const std::vector<std::string>& args,
679679
const std::vector<std::string>& exec_args);

src/node.cc

+26-25
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,10 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
610610

611611
static std::atomic_bool init_called{false};
612612

613-
int Init(std::vector<std::string>* argv,
614-
std::vector<std::string>* exec_argv,
615-
std::vector<std::string>* errors) {
616-
// Make sure Init() is called only once.
613+
int InitializeNodeWithArgs(std::vector<std::string>* argv,
614+
std::vector<std::string>* exec_argv,
615+
std::vector<std::string>* errors) {
616+
// Make sure InitializeNodeWithArgs() is called only once.
617617
CHECK(!init_called.exchange(true));
618618

619619
// Register built-in modules
@@ -724,7 +724,7 @@ void Init(int* argc,
724724

725725
// This (approximately) duplicates some logic that has been moved to
726726
// node::Start(), with the difference that here we explicitly call `exit()`.
727-
int exit_code = Init(&argv_, &exec_argv_, &errors);
727+
int exit_code = InitializeNodeWithArgs(&argv_, &exec_argv_, &errors);
728728

729729
for (const std::string& error : errors)
730730
fprintf(stderr, "%s: %s\n", argv_.at(0).c_str(), error.c_str());
@@ -759,9 +759,10 @@ void RunBeforeExit(Environment* env) {
759759
EmitBeforeExit(env);
760760
}
761761

762-
inline int Start(Isolate* isolate, IsolateData* isolate_data,
763-
const std::vector<std::string>& args,
764-
const std::vector<std::string>& exec_args) {
762+
inline int StartNodeWithIsolate(Isolate* isolate,
763+
IsolateData* isolate_data,
764+
const std::vector<std::string>& args,
765+
const std::vector<std::string>& exec_args) {
765766
HandleScope handle_scope(isolate);
766767
Local<Context> context = NewContext(isolate);
767768
Context::Scope context_scope(context);
@@ -772,7 +773,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
772773
static_cast<Environment::Flags>(Environment::kIsMainThread |
773774
Environment::kOwnsProcessState |
774775
Environment::kOwnsInspector));
775-
env.Start(per_process::v8_is_profiling);
776+
env.InitializeLibuv(per_process::v8_is_profiling);
776777
env.ProcessCliArgs(args, exec_args);
777778

778779
#if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM
@@ -848,25 +849,15 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
848849
return exit_code;
849850
}
850851

851-
inline int Start(uv_loop_t* event_loop,
852-
const std::vector<std::string>& args,
853-
const std::vector<std::string>& exec_args) {
852+
inline int StartNodeWithLoopAndArgs(uv_loop_t* event_loop,
853+
const std::vector<std::string>& args,
854+
const std::vector<std::string>& exec_args) {
854855
std::unique_ptr<ArrayBufferAllocator, decltype(&FreeArrayBufferAllocator)>
855856
allocator(CreateArrayBufferAllocator(), &FreeArrayBufferAllocator);
856857
Isolate* const isolate = NewIsolate(allocator.get(), event_loop);
857858
if (isolate == nullptr)
858859
return 12; // Signal internal error.
859860

860-
if (per_process::cli_options->print_version) {
861-
printf("%s\n", NODE_VERSION);
862-
return 0;
863-
}
864-
865-
if (per_process::cli_options->print_v8_help) {
866-
V8::SetFlagsFromString("--help", 6); // Doesn't return.
867-
UNREACHABLE();
868-
}
869-
870861
int exit_code;
871862
{
872863
Locker locker(isolate);
@@ -884,7 +875,7 @@ inline int Start(uv_loop_t* event_loop,
884875
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);
885876
}
886877
exit_code =
887-
Start(isolate, isolate_data.get(), args, exec_args);
878+
StartNodeWithIsolate(isolate, isolate_data.get(), args, exec_args);
888879
}
889880

890881
isolate->Dispose();
@@ -916,12 +907,22 @@ int Start(int argc, char** argv) {
916907
std::vector<std::string> errors;
917908
// This needs to run *before* V8::Initialize().
918909
{
919-
const int exit_code = Init(&args, &exec_args, &errors);
910+
const int exit_code = InitializeNodeWithArgs(&args, &exec_args, &errors);
920911
for (const std::string& error : errors)
921912
fprintf(stderr, "%s: %s\n", args.at(0).c_str(), error.c_str());
922913
if (exit_code != 0) return exit_code;
923914
}
924915

916+
if (per_process::cli_options->print_version) {
917+
printf("%s\n", NODE_VERSION);
918+
return 0;
919+
}
920+
921+
if (per_process::cli_options->print_v8_help) {
922+
V8::SetFlagsFromString("--help", 6); // Doesn't return.
923+
UNREACHABLE();
924+
}
925+
925926
#if HAVE_OPENSSL
926927
{
927928
std::string extra_ca_certs;
@@ -943,7 +944,7 @@ int Start(int argc, char** argv) {
943944
performance::performance_v8_start = PERFORMANCE_NOW();
944945
per_process::v8_initialized = true;
945946
const int exit_code =
946-
Start(uv_default_loop(), args, exec_args);
947+
StartNodeWithLoopAndArgs(uv_default_loop(), args, exec_args);
947948
per_process::v8_initialized = false;
948949
V8::Dispose();
949950

src/node_worker.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void Worker::Run() {
284284
env_->set_abort_on_uncaught_exception(false);
285285
env_->set_worker_context(this);
286286

287-
env_->Start(profiler_idle_notifier_started_);
287+
env_->InitializeLibuv(profiler_idle_notifier_started_);
288288
env_->ProcessCliArgs(std::vector<std::string>{},
289289
std::move(exec_argv_));
290290
}

0 commit comments

Comments
 (0)