From e00b326f33f9d610e5856978d07d1e34977e38a1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 19 Dec 2018 23:11:35 +0100 Subject: [PATCH] src: pass along MaybeLocal<> state from `URL::ToObject()` PR-URL: https://github.com/nodejs/node/pull/25141 Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Gus Caplan --- src/module_wrap.cc | 4 +++- src/node_url.cc | 4 ++-- src/node_url.h | 6 +----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 3860ec745e0311..243352fe644e40 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -708,7 +708,9 @@ void ModuleWrap::Resolve(const FunctionCallbackInfo& args) { return node::THROW_ERR_MISSING_MODULE(env, msg.c_str()); } - args.GetReturnValue().Set(result.FromJust().ToObject(env)); + MaybeLocal obj = result.FromJust().ToObject(env); + if (!obj.IsEmpty()) + args.GetReturnValue().Set(obj.ToLocalChecked()); } static MaybeLocal ImportModuleDynamically( diff --git a/src/node_url.cc b/src/node_url.cc index d5dba61ae4cc84..d028a66dbea542 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -2381,7 +2381,7 @@ URL URL::FromFilePath(const std::string& file_path) { // This function works by calling out to a JS function that creates and // returns the JS URL object. Be mindful of the JS<->Native boundary // crossing that is required. -const Local URL::ToObject(Environment* env) const { +MaybeLocal URL::ToObject(Environment* env) const { Isolate* isolate = env->isolate(); Local context = env->context(); Context::Scope context_scope(context); @@ -2417,7 +2417,7 @@ const Local URL::ToObject(Environment* env) const { ->Call(env->context(), undef, arraysize(argv), argv); } - return ret.ToLocalChecked(); + return ret; } static void SetURLConstructor(const FunctionCallbackInfo& args) { diff --git a/src/node_url.h b/src/node_url.h index 055393d22e0f19..47b859b879bca4 100644 --- a/src/node_url.h +++ b/src/node_url.h @@ -11,10 +11,6 @@ namespace node { namespace url { -using v8::Local; -using v8::Value; - - #define PARSESTATES(XX) \ XX(kSchemeStart) \ XX(kScheme) \ @@ -171,7 +167,7 @@ class URL { // Get the file URL from native file system path. static URL FromFilePath(const std::string& file_path); - const Local ToObject(Environment* env) const; + v8::MaybeLocal ToObject(Environment* env) const; URL(const URL&) = default; URL& operator=(const URL&) = default;