diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-06-11 15:56:08 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-06-21 18:08:09 +0300 |
commit | 9d100aa26913aa55eff40af30f3fd14a890b3198 (patch) | |
tree | aa023e50f16ea6d1fbbf0e2a294b46e27823832b /src | |
parent | 2aaf2f231f23fa280c82a5891b40fb7dc1582721 (diff) |
bootstrap: split NodeMainInstance::Run()
Split the running of the instance so that it can be reused
by the snapshot builder when we need to run the loop for
user code.
PR-URL: https://github.com/nodejs/node/pull/39007
Refs: https://github.com/nodejs/node/issues/35711
Refs: https://github.com/nodejs/node/pull/38905
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_main_instance.cc | 26 | ||||
-rw-r--r-- | src/node_main_instance.h | 1 |
2 files changed, 14 insertions, 13 deletions
diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index b4ceba6adb6..2320f556e9f 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -132,21 +132,24 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) { int exit_code = 0; DeleteFnPtr<Environment, FreeEnvironment> env = CreateMainEnvironment(&exit_code, env_info); - CHECK_NOT_NULL(env); - { - Context::Scope context_scope(env->context()); - if (exit_code == 0) { - LoadEnvironment(env.get(), StartExecutionCallback{}); + Context::Scope context_scope(env->context()); + Run(&exit_code, env.get()); + return exit_code; +} - exit_code = SpinEventLoop(env.get()).FromMaybe(1); - } +void NodeMainInstance::Run(int* exit_code, Environment* env) { + if (*exit_code == 0) { + LoadEnvironment(env, StartExecutionCallback{}); - ResetStdio(); + *exit_code = SpinEventLoop(env).FromMaybe(1); + } - // TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really - // make sense here. + ResetStdio(); + + // TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really + // make sense here. #if HAVE_INSPECTOR && defined(__POSIX__) && !defined(NODE_SHARED_MODE) struct sigaction act; memset(&act, 0, sizeof(act)); @@ -161,9 +164,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) { #if defined(LEAK_SANITIZER) __lsan_do_leak_check(); #endif - } - - return exit_code; } DeleteFnPtr<Environment, FreeEnvironment> diff --git a/src/node_main_instance.h b/src/node_main_instance.h index 75d4b7eac50..047bdca873e 100644 --- a/src/node_main_instance.h +++ b/src/node_main_instance.h @@ -59,6 +59,7 @@ class NodeMainInstance { // Start running the Node.js instances, return the exit code when finished. int Run(const EnvSerializeInfo* env_info); + void Run(int* exit_code, Environment* env); IsolateData* isolate_data() { return isolate_data_.get(); } |