From e92e318d8ea3c16b16212523206fdc9ebf28374b 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 --- src/node.cc | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/node.cc b/src/node.cc index d46c78a927b39c..c1bf5809e5edf7 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(); }