Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c3897bf

Browse filesBrowse 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 3a69349 commit c3897bf
Copy full SHA for c3897bf

File tree

Expand file treeCollapse file tree

4 files changed

+19
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+19
-4
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+3-2Lines changed: 3 additions & 2 deletions
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());
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1-1Lines 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 flags);
640640

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

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+5-1Lines changed: 5 additions & 1 deletion
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

Collapse file

‎src/node.h‎

Copy file name to clipboardExpand all lines: src/node.h
+10Lines changed: 10 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.