Skip to content

Commit ce6b9d1

Browse files
lundibundicodebytere
authored andcommitted
src: reduce code duplication in BootstrapNode
PR-URL: #31465 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent e3e056d commit ce6b9d1

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

src/node.cc

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -306,48 +306,32 @@ MaybeLocal<Value> Environment::BootstrapNode() {
306306
return scope.EscapeMaybe(result);
307307
}
308308

309-
if (is_main_thread()) {
310-
result = ExecuteBootstrapper(this,
311-
"internal/bootstrap/switches/is_main_thread",
312-
&node_params,
313-
&node_args);
314-
} else {
315-
result =
316-
ExecuteBootstrapper(this,
317-
"internal/bootstrap/switches/is_not_main_thread",
318-
&node_params,
319-
&node_args);
320-
}
309+
auto thread_switch_id =
310+
is_main_thread() ? "internal/bootstrap/switches/is_main_thread"
311+
: "internal/bootstrap/switches/is_not_main_thread";
312+
result =
313+
ExecuteBootstrapper(this, thread_switch_id, &node_params, &node_args);
321314

322315
if (result.IsEmpty()) {
323316
return scope.EscapeMaybe(result);
324317
}
325318

326-
if (owns_process_state()) {
327-
result = ExecuteBootstrapper(
328-
this,
329-
"internal/bootstrap/switches/does_own_process_state",
330-
&node_params,
331-
&node_args);
332-
} else {
333-
result = ExecuteBootstrapper(
334-
this,
335-
"internal/bootstrap/switches/does_not_own_process_state",
336-
&node_params,
337-
&node_args);
338-
}
319+
auto process_state_switch_id =
320+
owns_process_state()
321+
? "internal/bootstrap/switches/does_own_process_state"
322+
: "internal/bootstrap/switches/does_not_own_process_state";
323+
result = ExecuteBootstrapper(
324+
this, process_state_switch_id, &node_params, &node_args);
339325

340326
if (result.IsEmpty()) {
341327
return scope.EscapeMaybe(result);
342328
}
343329

330+
Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env");
344331
Local<Object> env_var_proxy;
345332
if (!CreateEnvVarProxy(context(), isolate_, as_callback_data())
346333
.ToLocal(&env_var_proxy) ||
347-
process_object()
348-
->Set(
349-
context(), FIXED_ONE_BYTE_STRING(isolate_, "env"), env_var_proxy)
350-
.IsNothing()) {
334+
process_object()->Set(context(), env_string, env_var_proxy).IsNothing()) {
351335
return MaybeLocal<Value>();
352336
}
353337

0 commit comments

Comments
 (0)