diff --git a/src/node.cc b/src/node.cc index 035b64e856..d8ebc9a427 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1945,6 +1945,10 @@ NODE_EXTERN void g_stop_nw_instance() { NODE_EXTERN void g_start_nw_instance(int argc, char *argv[], v8::Handle context, void* icu_data) { + static bool node_init_called = false; + static std::vector args; + static std::vector exec_args; + UErrorCode err = U_ZERO_ERROR; if (icu_data) udata_setCommonData((uint8_t*)icu_data, &err); @@ -1954,12 +1958,17 @@ NODE_EXTERN void g_start_nw_instance(int argc, char *argv[], v8::Handle result = - node::InitializeOncePerProcessInternal( + if (!node_init_called) { + std::shared_ptr result = + node::InitializeOncePerProcessInternal( std::vector(argv, argv + argc), node::ProcessInitializationFlags::kNWJS); - for (const std::string& error : result->errors()) { - node::FPrintF(stderr, "%s: %s\n", result->args().at(0), error); + args = result->args(); + exec_args = result->exec_args(); + node_init_called = true; + for (const std::string& error : result->errors()) { + node::FPrintF(stderr, "%s: %s\n", result->args().at(0), error); + } } if (!node::thread_ctx_created) { @@ -1977,9 +1986,7 @@ NODE_EXTERN void g_start_nw_instance(int argc, char *argv[], v8::HandleRegisterIsolate(isolate, uv_default_loop()); node::IsolateData* isolate_data = node::CreateIsolateData(isolate, uv_default_loop(), platform); node::NewContext(isolate, v8::Local(), false); - std::vector args(argv, argv + argc); - std::vector exec_args; - tls_ctx->env = node::CreateEnvironment(isolate_data, context, result->args(), result->exec_args()); + tls_ctx->env = node::CreateEnvironment(isolate_data, context, args, exec_args); isolate->SetFatalErrorHandler(node::OnFatalError); isolate->AddMessageListener(node::errors::PerIsolateMessageListener); //isolate->SetAutorunMicrotasks(false);