From 08f57265b5c58c16af9e93510cda39462ecf2713 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Wed, 22 Jan 2020 21:21:22 +0200 Subject: [PATCH] src: reduce code duplication in BootstrapNode PR-URL: https://github.com/nodejs/node/pull/31465 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: David Carlier Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- src/node.cc | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/node.cc b/src/node.cc index 0cb89044e58f74..d84f965f65aa00 100644 --- a/src/node.cc +++ b/src/node.cc @@ -312,48 +312,32 @@ MaybeLocal 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 env_string = FIXED_ONE_BYTE_STRING(isolate_, "env"); Local 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(); }