Skip to content

Commit

Permalink
bootstrap: split NodeMainInstance::Run()
Browse files Browse the repository at this point in the history
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: #39007
Refs: #35711
Refs: #38905
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joyeecheung committed Jun 21, 2021
1 parent 0f3328a commit 44c5981
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/node_main_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down

0 comments on commit 44c5981

Please sign in to comment.