diff --git a/src/env.cc b/src/env.cc index 692a344703a196d..643fd7d3a4347c6 100644 --- a/src/env.cc +++ b/src/env.cc @@ -911,10 +911,11 @@ void Environment::InitializeLibuv() { StartProfilerIdleNotifier(); } -void Environment::ExitEnv() { +void Environment::ExitEnv(bool terminate) { // Should not access non-thread-safe methods here. set_stopping(true); - isolate_->TerminateExecution(); + if (terminate) + isolate_->TerminateExecution(); SetImmediateThreadsafe([](Environment* env) { env->set_can_call_into_js(false); uv_stop(env->event_loop()); diff --git a/src/env.h b/src/env.h index c2eb764e740400c..cc1187effbeab8d 100644 --- a/src/env.h +++ b/src/env.h @@ -636,7 +636,7 @@ class Environment : public MemoryRetainer { void RegisterHandleCleanups(); void CleanupHandles(); void Exit(ExitCode code); - void ExitEnv(); + void ExitEnv(bool terminate); // Register clean-up cb to be called on environment destruction. inline void RegisterHandleCleanup(uv_handle_t* handle, diff --git a/src/node.cc b/src/node.cc index f92be4b089db872..002e14aa410238b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1253,8 +1253,8 @@ int Start(int argc, char** argv) { return static_cast(StartInternal(argc, argv)); } -int Stop(Environment* env) { - env->ExitEnv(); +int Stop(Environment* env, bool terminate) { + env->ExitEnv(terminate); return 0; } diff --git a/src/node.h b/src/node.h index 48477e970829c33..4745ecad4ee7eb1 100644 --- a/src/node.h +++ b/src/node.h @@ -308,7 +308,7 @@ NODE_EXTERN int Start(int argc, char* argv[]); // Tear down Node.js while it is running (there are active handles // in the loop and / or actively executing JavaScript code). -NODE_EXTERN int Stop(Environment* env); +NODE_EXTERN int Stop(Environment* env, bool terminate = true); // Set up per-process state needed to run Node.js. This will consume arguments // from argv, fill exec_argv, and possibly add errors resulting from parsing