GeezerVison is showing github.com — src: allow optional Isolate termination in node::Stop() · nodejs/node@ea411d6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/env.cc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -902,10 +902,11 @@ void Environment::InitializeLibuv() { |
902 | 902 | StartProfilerIdleNotifier(); |
903 | 903 | } |
904 | 904 |
|
905 | | -void Environment::ExitEnv() { |
| 905 | +void Environment::ExitEnv(StopFlags::Flags flags) { |
906 | 906 | // Should not access non-thread-safe methods here. |
907 | 907 | set_stopping(true); |
908 | | - isolate_->TerminateExecution(); |
| 908 | + if ((flags & StopFlags::kDoNotTerminateIsolate) == 0) |
| 909 | + isolate_->TerminateExecution(); |
909 | 910 | SetImmediateThreadsafe([](Environment* env) { |
910 | 911 | env->set_can_call_into_js(false); |
911 | 912 | uv_stop(env->event_loop()); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/env.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -628,7 +628,7 @@ class Environment : public MemoryRetainer { |
628 | 628 | void RegisterHandleCleanups(); |
629 | 629 | void CleanupHandles(); |
630 | 630 | void Exit(int code); |
631 | | - void ExitEnv(); |
| 631 | + void ExitEnv(StopFlags::Flags flags); |
632 | 632 |
|
633 | 633 | // Register clean-up cb to be called on environment destruction. |
634 | 634 | inline void RegisterHandleCleanup(uv_handle_t* handle, |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node.cc +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1231,7 +1231,11 @@ int Start(int argc, char** argv) { |
1231 | 1231 | } |
1232 | 1232 |
|
1233 | 1233 | 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); |
1235 | 1239 | return 0; |
1236 | 1240 | } |
1237 | 1241 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: src/node.h +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -274,6 +274,15 @@ enum Flags : uint64_t { |
274 | 274 | // TODO(addaleax): Make this the canonical name, as it is more descriptive. |
275 | 275 | namespace ProcessInitializationFlags = ProcessFlags; |
276 | 276 |
|
| 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 | + |
277 | 286 | class NODE_EXTERN InitializationResult { |
278 | 287 | public: |
279 | 288 | virtual ~InitializationResult(); |
@@ -310,6 +319,7 @@ NODE_EXTERN int Start(int argc, char* argv[]); |
310 | 319 | // Tear down Node.js while it is running (there are active handles |
311 | 320 | // in the loop and / or actively executing JavaScript code). |
312 | 321 | NODE_EXTERN int Stop(Environment* env); |
| 322 | +NODE_EXTERN int Stop(Environment* env, StopFlags::Flags flags); |
313 | 323 |
|
314 | 324 | // This runs a subset of the initialization performed by |
315 | 325 | // InitializeOncePerProcess(), which supersedes this function. |
|