Skip to content

Commit

Permalink
src: allow optional Isolate termination in node::Stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 9, 2023
1 parent 5092346 commit 24c6777
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/env.cc
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/node.cc
Expand Up @@ -1253,8 +1253,8 @@ int Start(int argc, char** argv) {
return static_cast<int>(StartInternal(argc, argv));
}

int Stop(Environment* env) {
env->ExitEnv();
int Stop(Environment* env, bool terminate) {
env->ExitEnv(terminate);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/node.h
Expand Up @@ -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
Expand Down

0 comments on commit 24c6777

Please sign in to comment.