From 6ef2efe33ace9d0ae90da4505800718aeeb60f8c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 28 May 2020 05:34:29 +0200 Subject: [PATCH] src: use MaybeLocal.ToLocal instead of IsEmpty worker This commit suggest using MaybeLocal.ToLocal and passing in the Local node_opts. It also introduces a variable, arg_v8, of type Local 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: https://github.com/nodejs/node/pull/33599 Reviewed-By: Zeyu Yang Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- src/node_worker.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/node_worker.cc b/src/node_worker.cc index f7d5434efd9e7c..403c054ab21e77 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -487,9 +487,9 @@ void Worker::New(const FunctionCallbackInfo& args) { #ifndef NODE_WITHOUT_NODE_OPTIONS MaybeLocal 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 node_opts; + if (maybe_node_opts.ToLocal(&node_opts)) { + std::string node_options(*String::Utf8Value(isolate, node_opts)); std::vector errors{}; std::vector env_argv = ParseNodeOptionsEnvVar(node_options, &errors); @@ -529,14 +529,11 @@ void Worker::New(const FunctionCallbackInfo& args) { if (!array->Get(env->context(), i).ToLocal(&arg)) { return; } - MaybeLocal arg_v8_string = - arg->ToString(env->context()); - if (arg_v8_string.IsEmpty()) { + Local arg_v8; + if (!arg->ToString(env->context()).ToLocal(&arg_v8)) { return; } - Utf8Value arg_utf8_value( - args.GetIsolate(), - arg_v8_string.FromMaybe(Local())); + 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); }