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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
danbev authored and codebytere committed Jun 18, 2020
1 parent 022dceb commit 6ef2efe
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 @@ -487,9 +487,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 @@ -529,14 +529,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 6ef2efe

Please sign in to comment.