mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/pull/33695 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
This commit is contained in:
1 parent
0372b94f2f
commit
d6d845dd82
1 file changed
+4
-3
@@ -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<String> value = env->env_vars()->Get(
|
||||
MaybeLocal<String> 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<String> 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;
|
||||
|
||||
Reference in new issue
Block a user