Skip to content

Commit 9e9dbd4

Browse files
lundibundicodebytere
authored andcommitted
src: reduce code duplication in BootstrapNode
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]>
1 parent f2dc694 commit 9e9dbd4

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
@@ -312,48 +312,32 @@ MaybeLocal<Value> Environment::BootstrapNode() {
312312
return scope.EscapeMaybe(result);
313313
}
314314

315-
if (is_main_thread()) {
316-
result = ExecuteBootstrapper(this,
317-
"internal/bootstrap/switches/is_main_thread",
318-
&node_params,
319-
&node_args);
320-
} else {
321-
result =
322-
ExecuteBootstrapper(this,
323-
"internal/bootstrap/switches/is_not_main_thread",
324-
&node_params,
325-
&node_args);
326-
}
315+
auto thread_switch_id =
316+
is_main_thread() ? "internal/bootstrap/switches/is_main_thread"
317+
: "internal/bootstrap/switches/is_not_main_thread";
318+
result =
319+
ExecuteBootstrapper(this, thread_switch_id, &node_params, &node_args);
327320

328321
if (result.IsEmpty()) {
329322
return scope.EscapeMaybe(result);
330323
}
331324

332-
if (owns_process_state()) {
333-
result = ExecuteBootstrapper(
334-
this,
335-
"internal/bootstrap/switches/does_own_process_state",
336-
&node_params,
337-
&node_args);
338-
} else {
339-
result = ExecuteBootstrapper(
340-
this,
341-
"internal/bootstrap/switches/does_not_own_process_state",
342-
&node_params,
343-
&node_args);
344-
}
325+
auto process_state_switch_id =
326+
owns_process_state()
327+
? "internal/bootstrap/switches/does_own_process_state"
328+
: "internal/bootstrap/switches/does_not_own_process_state";
329+
result = ExecuteBootstrapper(
330+
this, process_state_switch_id, &node_params, &node_args);
345331

346332
if (result.IsEmpty()) {
347333
return scope.EscapeMaybe(result);
348334
}
349335

336+
Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env");
350337
Local<Object> env_var_proxy;
351338
if (!CreateEnvVarProxy(context(), isolate_, as_callback_data())
352339
.ToLocal(&env_var_proxy) ||
353-
process_object()
354-
->Set(
355-
context(), FIXED_ONE_BYTE_STRING(isolate_, "env"), env_var_proxy)
356-
.IsNothing()) {
340+
process_object()->Set(context(), env_string, env_var_proxy).IsNothing()) {
357341
return MaybeLocal<Value>();
358342
}
359343

0 commit comments

Comments
 (0)