Skip to content

Commit ea411d6

Browse files
codebyteredanielleadams
authored andcommitted
src: allow optional Isolate termination in node::Stop()
PR-URL: #46583 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 665b742 commit ea411d6

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/env.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,11 @@ void Environment::InitializeLibuv() {
902902
StartProfilerIdleNotifier();
903903
}
904904

905-
void Environment::ExitEnv() {
905+
void Environment::ExitEnv(StopFlags::Flags flags) {
906906
// Should not access non-thread-safe methods here.
907907
set_stopping(true);
908-
isolate_->TerminateExecution();
908+
if ((flags & StopFlags::kDoNotTerminateIsolate) == 0)
909+
isolate_->TerminateExecution();
909910
SetImmediateThreadsafe([](Environment* env) {
910911
env->set_can_call_into_js(false);
911912
uv_stop(env->event_loop());

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class Environment : public MemoryRetainer {
628628
void RegisterHandleCleanups();
629629
void CleanupHandles();
630630
void Exit(int code);
631-
void ExitEnv();
631+
void ExitEnv(StopFlags::Flags flags);
632632

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

src/node.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,11 @@ int Start(int argc, char** argv) {
12311231
}
12321232

12331233
int Stop(Environment* env) {
1234-
env->ExitEnv();
1234+
return Stop(env, StopFlags::kNoFlags);
1235+
}
1236+
1237+
int Stop(Environment* env, StopFlags::Flags flags) {
1238+
env->ExitEnv(flags);
12351239
return 0;
12361240
}
12371241

src/node.h

+10
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ enum Flags : uint64_t {
274274
// TODO(addaleax): Make this the canonical name, as it is more descriptive.
275275
namespace ProcessInitializationFlags = ProcessFlags;
276276

277+
namespace StopFlags {
278+
enum Flags : uint32_t {
279+
kNoFlags = 0,
280+
// Do not explicitly terminate the Isolate
281+
// when exiting the Environment.
282+
kDoNotTerminateIsolate = 1 << 0,
283+
};
284+
} // namespace StopFlags
285+
277286
class NODE_EXTERN InitializationResult {
278287
public:
279288
virtual ~InitializationResult();
@@ -310,6 +319,7 @@ NODE_EXTERN int Start(int argc, char* argv[]);
310319
// Tear down Node.js while it is running (there are active handles
311320
// in the loop and / or actively executing JavaScript code).
312321
NODE_EXTERN int Stop(Environment* env);
322+
NODE_EXTERN int Stop(Environment* env, StopFlags::Flags flags);
313323

314324
// This runs a subset of the initialization performed by
315325
// InitializeOncePerProcess(), which supersedes this function.

0 commit comments

Comments
 (0)