Skip to content

Commit 6f1d38c

Browse files
danbevcodebytere
authored andcommitted
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. PR-URL: #33695 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent 5b8cac8 commit 6f1d38c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/node_credentials.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {
4444
if (env != nullptr) {
4545
HandleScope handle_scope(env->isolate());
4646
TryCatch ignore_errors(env->isolate());
47-
MaybeLocal<String> value = env->env_vars()->Get(
47+
MaybeLocal<String> maybe_value = env->env_vars()->Get(
4848
env->isolate(),
4949
String::NewFromUtf8(env->isolate(), key, NewStringType::kNormal)
5050
.ToLocalChecked());
51-
if (value.IsEmpty()) goto fail;
52-
String::Utf8Value utf8_value(env->isolate(), value.ToLocalChecked());
51+
Local<String> value;
52+
if (!maybe_value.ToLocal(&value)) goto fail;
53+
String::Utf8Value utf8_value(env->isolate(), value);
5354
if (*utf8_value == nullptr) goto fail;
5455
*text = std::string(*utf8_value, utf8_value.length());
5556
return true;

0 commit comments

Comments
 (0)