Skip to content

Commit 9d100aa

Browse files
joyeecheungdanielleadams
authored andcommitted
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: #39007 Refs: #35711 Refs: #38905 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2aaf2f2 commit 9d100aa

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/node_main_instance.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,24 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
132132
int exit_code = 0;
133133
DeleteFnPtr<Environment, FreeEnvironment> env =
134134
CreateMainEnvironment(&exit_code, env_info);
135-
136135
CHECK_NOT_NULL(env);
137-
{
138-
Context::Scope context_scope(env->context());
139136

140-
if (exit_code == 0) {
141-
LoadEnvironment(env.get(), StartExecutionCallback{});
137+
Context::Scope context_scope(env->context());
138+
Run(&exit_code, env.get());
139+
return exit_code;
140+
}
142141

143-
exit_code = SpinEventLoop(env.get()).FromMaybe(1);
144-
}
142+
void NodeMainInstance::Run(int* exit_code, Environment* env) {
143+
if (*exit_code == 0) {
144+
LoadEnvironment(env, StartExecutionCallback{});
145145

146-
ResetStdio();
146+
*exit_code = SpinEventLoop(env).FromMaybe(1);
147+
}
147148

148-
// TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really
149-
// make sense here.
149+
ResetStdio();
150+
151+
// TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really
152+
// make sense here.
150153
#if HAVE_INSPECTOR && defined(__POSIX__) && !defined(NODE_SHARED_MODE)
151154
struct sigaction act;
152155
memset(&act, 0, sizeof(act));
@@ -161,9 +164,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
161164
#if defined(LEAK_SANITIZER)
162165
__lsan_do_leak_check();
163166
#endif
164-
}
165-
166-
return exit_code;
167167
}
168168

169169
DeleteFnPtr<Environment, FreeEnvironment>

src/node_main_instance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class NodeMainInstance {
5959

6060
// Start running the Node.js instances, return the exit code when finished.
6161
int Run(const EnvSerializeInfo* env_info);
62+
void Run(int* exit_code, Environment* env);
6263

6364
IsolateData* isolate_data() { return isolate_data_.get(); }
6465

0 commit comments

Comments
 (0)