Skip to content

Commit 99371ad

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 0a949c3 commit 99371ad

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
@@ -513,9 +513,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
513513
#ifndef NODE_WITHOUT_NODE_OPTIONS
514514
MaybeLocal<String> maybe_node_opts =
515515
env_vars->Get(isolate, OneByteString(isolate, "NODE_OPTIONS"));
516-
if (!maybe_node_opts.IsEmpty()) {
517-
std::string node_options(
518-
*String::Utf8Value(isolate, maybe_node_opts.ToLocalChecked()));
516+
Local<String> node_opts;
517+
if (maybe_node_opts.ToLocal(&node_opts)) {
518+
std::string node_options(*String::Utf8Value(isolate, node_opts));
519519
std::vector<std::string> errors{};
520520
std::vector<std::string> env_argv =
521521
ParseNodeOptionsEnvVar(node_options, &errors);
@@ -555,14 +555,11 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
555555
if (!array->Get(env->context(), i).ToLocal(&arg)) {
556556
return;
557557
}
558-
MaybeLocal<String> arg_v8_string =
559-
arg->ToString(env->context());
560-
if (arg_v8_string.IsEmpty()) {
558+
Local<String> arg_v8;
559+
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
561560
return;
562561
}
563-
Utf8Value arg_utf8_value(
564-
args.GetIsolate(),
565-
arg_v8_string.FromMaybe(Local<String>()));
562+
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
566563
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
567564
exec_argv.push_back(arg_string);
568565
}

0 commit comments

Comments
 (0)