Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: reduce code duplication in BootstrapNode #31465

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,48 +312,32 @@ MaybeLocal<Value> Environment::BootstrapNode() {
return scope.EscapeMaybe(result);
}

if (is_main_thread()) {
result = ExecuteBootstrapper(this,
"internal/bootstrap/switches/is_main_thread",
&node_params,
&node_args);
} else {
result =
ExecuteBootstrapper(this,
"internal/bootstrap/switches/is_not_main_thread",
&node_params,
&node_args);
}
auto thread_switch_id =
is_main_thread() ? "internal/bootstrap/switches/is_main_thread"
: "internal/bootstrap/switches/is_not_main_thread";
result =
ExecuteBootstrapper(this, thread_switch_id, &node_params, &node_args);

if (result.IsEmpty()) {
return scope.EscapeMaybe(result);
}

if (owns_process_state()) {
result = ExecuteBootstrapper(
this,
"internal/bootstrap/switches/does_own_process_state",
&node_params,
&node_args);
} else {
result = ExecuteBootstrapper(
this,
"internal/bootstrap/switches/does_not_own_process_state",
&node_params,
&node_args);
}
auto process_state_switch_id =
owns_process_state()
? "internal/bootstrap/switches/does_own_process_state"
: "internal/bootstrap/switches/does_not_own_process_state";
result = ExecuteBootstrapper(
this, process_state_switch_id, &node_params, &node_args);

if (result.IsEmpty()) {
return scope.EscapeMaybe(result);
}

Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env");
Local<Object> env_var_proxy;
if (!CreateEnvVarProxy(context(), isolate_, as_callback_data())
.ToLocal(&env_var_proxy) ||
process_object()
->Set(
context(), FIXED_ONE_BYTE_STRING(isolate_, "env"), env_var_proxy)
.IsNothing()) {
process_object()->Set(context(), env_string, env_var_proxy).IsNothing()) {
return MaybeLocal<Value>();
}

Expand Down