Skip to content

Commit f390841

Browse files
codebytereMylesBorins
authored andcommitted
src: allow optional Isolate termination in node::Stop()
PR-URL: #46583 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 1cd22e7 commit f390841

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
@@ -910,10 +910,11 @@ void Environment::InitializeLibuv() {
910910
StartProfilerIdleNotifier();
911911
}
912912

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

src/env.h

+1-1
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 flags);
640640

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

src/node.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,11 @@ int Start(int argc, char** argv) {
12481248
}
12491249

12501250
int Stop(Environment* env) {
1251-
env->ExitEnv();
1251+
return Stop(env, StopFlags::kNoFlags);
1252+
}
1253+
1254+
int Stop(Environment* env, StopFlags::Flags flags) {
1255+
env->ExitEnv(flags);
12521256
return 0;
12531257
}
12541258

src/node.h

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

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

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

0 commit comments

Comments
 (0)