Skip to content

Commit 72f0094

Browse files
committed
src: allow optional Isolate termination in node::Stop()
1 parent 5092346 commit 72f0094

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/env.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,11 @@ void Environment::InitializeLibuv() {
911911
StartProfilerIdleNotifier();
912912
}
913913

914-
void Environment::ExitEnv() {
914+
void Environment::ExitEnv(StopFlags flags) {
915915
// Should not access non-thread-safe methods here.
916916
set_stopping(true);
917-
isolate_->TerminateExecution();
917+
if ((flags & StopFlags::kDoNotTerminateIsolate) == 0)
918+
isolate_->TerminateExecution();
918919
SetImmediateThreadsafe([](Environment* env) {
919920
env->set_can_call_into_js(false);
920921
uv_stop(env->event_loop());

src/env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ class Environment : public MemoryRetainer {
636636
void RegisterHandleCleanups();
637637
void CleanupHandles();
638638
void Exit(ExitCode code);
639-
void ExitEnv();
639+
void ExitEnv(StopFlags flags);
640640

641641
// Register clean-up cb to be called on environment destruction.
642642
inline void RegisterHandleCleanup(uv_handle_t* handle,

src/node.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,11 @@ int Start(int argc, char** argv) {
12541254
}
12551255

12561256
int Stop(Environment* env) {
1257-
env->ExitEnv();
1257+
return Stop(env, StopFlags::kNoFlags);
1258+
}
1259+
1260+
int Stop(Environment* env, StopFlags flags) {
1261+
env->ExitEnv(flags);
12581262
return 0;
12591263
}
12601264

src/node.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,17 @@ class NODE_EXTERN InitializationResult {
306306
// better suited for a public embedder API.
307307
NODE_EXTERN int Start(int argc, char* argv[]);
308308

309+
enum StopFlags {
310+
kNoFlags = 0,
311+
// Do not explicitly terminate the Isolate
312+
// when exiting the Environment.
313+
kDoNotTerminateIsolate = 1 << 0,
314+
};
315+
309316
// Tear down Node.js while it is running (there are active handles
310317
// in the loop and / or actively executing JavaScript code).
311318
NODE_EXTERN int Stop(Environment* env);
319+
NODE_EXTERN int Stop(Environment* env, StopFlags flags);
312320

313321
// Set up per-process state needed to run Node.js. This will consume arguments
314322
// from argv, fill exec_argv, and possibly add errors resulting from parsing

0 commit comments

Comments
 (0)