From 7f93c5047d1789811bcf3cef81ff09573e80c378 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 2 Jun 2020 11:12:38 +0200 Subject: [PATCH] src: use ToLocal in SafeGetenv This commit replaces the IsEmpty call to use ToLocal instead which allows for the following ToLocalChecked function call to be avoided. --- src/node_credentials.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/node_credentials.cc b/src/node_credentials.cc index d7be988d978b8a..d552a501726396 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -44,12 +44,13 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) { if (env != nullptr) { HandleScope handle_scope(env->isolate()); TryCatch ignore_errors(env->isolate()); - MaybeLocal value = env->env_vars()->Get( + MaybeLocal maybe_value = env->env_vars()->Get( env->isolate(), String::NewFromUtf8(env->isolate(), key, NewStringType::kNormal) .ToLocalChecked()); - if (value.IsEmpty()) goto fail; - String::Utf8Value utf8_value(env->isolate(), value.ToLocalChecked()); + Local value; + if (!maybe_value.ToLocal(&value)) goto fail; + String::Utf8Value utf8_value(env->isolate(), value); if (*utf8_value == nullptr) goto fail; *text = std::string(*utf8_value, utf8_value.length()); return true;