Skip to content

Commit

Permalink
src: reduce code duplication in BootstrapNode
Browse files Browse the repository at this point in the history
PR-URL: #31465
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
lundibundi authored and codebytere committed Feb 17, 2020
1 parent f2dc694 commit 9e9dbd4
Showing 1 changed file with 13 additions and 29 deletions.
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

0 comments on commit 9e9dbd4

Please sign in to comment.