Skip to content

Commit

Permalink
src: use MaybeLocal.ToLocal instead of IsEmpty worker
Browse files Browse the repository at this point in the history
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 <himself65@outlook.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
danbev authored and codebytere committed Jul 8, 2020
1 parent 0a949c3 commit 99371ad
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
#ifndef NODE_WITHOUT_NODE_OPTIONS
MaybeLocal<String> maybe_node_opts =
env_vars->Get(isolate, OneByteString(isolate, "NODE_OPTIONS"));
if (!maybe_node_opts.IsEmpty()) {
std::string node_options(
*String::Utf8Value(isolate, maybe_node_opts.ToLocalChecked()));
Local<String> node_opts;
if (maybe_node_opts.ToLocal(&node_opts)) {
std::string node_options(*String::Utf8Value(isolate, node_opts));
std::vector<std::string> errors{};
std::vector<std::string> env_argv =
ParseNodeOptionsEnvVar(node_options, &errors);
Expand Down Expand Up @@ -555,14 +555,11 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
if (!array->Get(env->context(), i).ToLocal(&arg)) {
return;
}
MaybeLocal<String> arg_v8_string =
arg->ToString(env->context());
if (arg_v8_string.IsEmpty()) {
Local<String> arg_v8;
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
return;
}
Utf8Value arg_utf8_value(
args.GetIsolate(),
arg_v8_string.FromMaybe(Local<String>()));
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
exec_argv.push_back(arg_string);
}
Expand Down

0 comments on commit 99371ad

Please sign in to comment.