Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
joyeecheung committed Jun 11, 2021
commit 2ee344b3318ad28c95e75bc24c260e9b931ffe5a
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