diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-10-11 16:13:19 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-10-14 21:08:19 +0300 |
commit | 9fd6122659c4067b0d8bd2c590f4ba01b48c93a3 (patch) | |
tree | 89cdbb73d84f5ae87e1399f95aa0fba392b43f7f /src/node_main_instance.cc | |
parent | ef1645e2b3f609492af7f25e4468db9b7801f4aa (diff) |
src: add embedding helpers to reduce boilerplate code
Provide helpers for a) spinning the event loop and
b) setting up and tearing down the objects involved in a single
Node.js instance, as they would typically be used.
The former helper is also usable inside Node.js itself,
for both Worker and main threads.
PR-URL: https://github.com/nodejs/node/pull/35597
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'src/node_main_instance.cc')
-rw-r--r-- | src/node_main_instance.cc | 33 |
1 files changed, 1 insertions, 32 deletions
diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 597ce4c96e0..d406bf15444 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -23,7 +23,6 @@ using v8::Isolate; using v8::Local; using v8::Locker; using v8::Object; -using v8::SealHandleScope; std::unique_ptr<ExternalReferenceRegistry> NodeMainInstance::registry_ = nullptr; @@ -140,37 +139,7 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) { if (exit_code == 0) { LoadEnvironment(env.get()); - env->set_trace_sync_io(env->options()->trace_sync_io); - - { - SealHandleScope seal(isolate_); - bool more; - env->performance_state()->Mark( - node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_START); - do { - uv_run(env->event_loop(), UV_RUN_DEFAULT); - - per_process::v8_platform.DrainVMTasks(isolate_); - - more = uv_loop_alive(env->event_loop()); - if (more && !env->is_stopping()) continue; - - if (!uv_loop_alive(env->event_loop())) { - if (EmitProcessBeforeExit(env.get()).IsNothing()) - break; - } - - // Emit `beforeExit` if the loop became alive either after emitting - // event, or after running some callbacks. - more = uv_loop_alive(env->event_loop()); - } while (more == true && !env->is_stopping()); - env->performance_state()->Mark( - node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT); - } - - env->set_trace_sync_io(false); - if (!env->is_stopping()) env->VerifyNoStrongBaseObjects(); - exit_code = EmitProcessExit(env.get()).FromMaybe(1); + exit_code = SpinEventLoop(env.get()).FromMaybe(1); } ResetStdio(); |