@@ -610,10 +610,10 @@ int ProcessGlobalArgs(std::vector<std::string>* args, |
610 | 610 |
|
611 | 611 | static std::atomic_bool init_called{false}; |
612 | 612 |
|
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. |
617 | 617 | CHECK(!init_called.exchange(true)); |
618 | 618 |
|
619 | 619 | // Register built-in modules |
@@ -724,7 +724,7 @@ void Init(int* argc, |
724 | 724 |
|
725 | 725 | // This (approximately) duplicates some logic that has been moved to |
726 | 726 | // 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); |
728 | 728 |
|
729 | 729 | for (const std::string& error : errors) |
730 | 730 | fprintf(stderr, "%s: %s\n", argv_.at(0).c_str(), error.c_str()); |
@@ -759,9 +759,10 @@ void RunBeforeExit(Environment* env) { |
759 | 759 | EmitBeforeExit(env); |
760 | 760 | } |
761 | 761 |
|
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) { |
765 | 766 | HandleScope handle_scope(isolate); |
766 | 767 | Local<Context> context = NewContext(isolate); |
767 | 768 | Context::Scope context_scope(context); |
@@ -772,7 +773,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, |
772 | 773 | static_cast<Environment::Flags>(Environment::kIsMainThread | |
773 | 774 | Environment::kOwnsProcessState | |
774 | 775 | Environment::kOwnsInspector)); |
775 | | - env.Start(per_process::v8_is_profiling); |
| 776 | + env.InitializeLibuv(per_process::v8_is_profiling); |
776 | 777 | env.ProcessCliArgs(args, exec_args); |
777 | 778 |
|
778 | 779 | #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM |
@@ -848,25 +849,15 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, |
848 | 849 | return exit_code; |
849 | 850 | } |
850 | 851 |
|
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) { |
854 | 855 | std::unique_ptr<ArrayBufferAllocator, decltype(&FreeArrayBufferAllocator)> |
855 | 856 | allocator(CreateArrayBufferAllocator(), &FreeArrayBufferAllocator); |
856 | 857 | Isolate* const isolate = NewIsolate(allocator.get(), event_loop); |
857 | 858 | if (isolate == nullptr) |
858 | 859 | return 12; // Signal internal error. |
859 | 860 |
|
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 | | - |
870 | 861 | int exit_code; |
871 | 862 | { |
872 | 863 | Locker locker(isolate); |
@@ -884,7 +875,7 @@ inline int Start(uv_loop_t* event_loop, |
884 | 875 | isolate->GetHeapProfiler()->StartTrackingHeapObjects(true); |
885 | 876 | } |
886 | 877 | exit_code = |
887 | | - Start(isolate, isolate_data.get(), args, exec_args); |
| 878 | + StartNodeWithIsolate(isolate, isolate_data.get(), args, exec_args); |
888 | 879 | } |
889 | 880 |
|
890 | 881 | isolate->Dispose(); |
@@ -916,12 +907,22 @@ int Start(int argc, char** argv) { |
916 | 907 | std::vector<std::string> errors; |
917 | 908 | // This needs to run *before* V8::Initialize(). |
918 | 909 | { |
919 | | - const int exit_code = Init(&args, &exec_args, &errors); |
| 910 | + const int exit_code = InitializeNodeWithArgs(&args, &exec_args, &errors); |
920 | 911 | for (const std::string& error : errors) |
921 | 912 | fprintf(stderr, "%s: %s\n", args.at(0).c_str(), error.c_str()); |
922 | 913 | if (exit_code != 0) return exit_code; |
923 | 914 | } |
924 | 915 |
|
| 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 | + |
925 | 926 | #if HAVE_OPENSSL |
926 | 927 | { |
927 | 928 | std::string extra_ca_certs; |
@@ -943,7 +944,7 @@ int Start(int argc, char** argv) { |
943 | 944 | performance::performance_v8_start = PERFORMANCE_NOW(); |
944 | 945 | per_process::v8_initialized = true; |
945 | 946 | const int exit_code = |
946 | | - Start(uv_default_loop(), args, exec_args); |
| 947 | + StartNodeWithLoopAndArgs(uv_default_loop(), args, exec_args); |
947 | 948 | per_process::v8_initialized = false; |
948 | 949 | V8::Dispose(); |
949 | 950 |
|
|