@@ -610,10 +610,10 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
610610
611611static 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
0 commit comments