Skip to content

Commit 6ef2efe

Browse files
danbevcodebytere
authored andcommitted
src: use MaybeLocal.ToLocal instead of IsEmpty worker
This commit suggest using MaybeLocal.ToLocal and passing in the Local<String> node_opts. It also introduces a variable, arg_v8, of type Local<String> to enable the use of ToLocal. The motivation for doing this is that the following MaybeLocal::ToLocalChecked and MaybeLocal::FromMaybe calls can then be avoided. PR-URL: #33599 Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 022dceb commit 6ef2efe

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/node_worker.cc

+6-9
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
487487
#ifndef NODE_WITHOUT_NODE_OPTIONS
488488
MaybeLocal<String> maybe_node_opts =
489489
env_vars->Get(isolate, OneByteString(isolate, "NODE_OPTIONS"));
490-
if (!maybe_node_opts.IsEmpty()) {
491-
std::string node_options(
492-
*String::Utf8Value(isolate, maybe_node_opts.ToLocalChecked()));
490+
Local<String> node_opts;
491+
if (maybe_node_opts.ToLocal(&node_opts)) {
492+
std::string node_options(*String::Utf8Value(isolate, node_opts));
493493
std::vector<std::string> errors{};
494494
std::vector<std::string> env_argv =
495495
ParseNodeOptionsEnvVar(node_options, &errors);
@@ -529,14 +529,11 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
529529
if (!array->Get(env->context(), i).ToLocal(&arg)) {
530530
return;
531531
}
532-
MaybeLocal<String> arg_v8_string =
533-
arg->ToString(env->context());
534-
if (arg_v8_string.IsEmpty()) {
532+
Local<String> arg_v8;
533+
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
535534
return;
536535
}
537-
Utf8Value arg_utf8_value(
538-
args.GetIsolate(),
539-
arg_v8_string.FromMaybe(Local<String>()));
536+
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
540537
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
541538
exec_argv.push_back(arg_string);
542539
}

0 commit comments

Comments
 (0)