From d31fbec57101c9b70e4e3686274e6317e420daeb Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 19 Dec 2018 23:07:53 +0100 Subject: [PATCH 1/2] src: ignore termination exceptions in fatal TryCatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t want these to terminate the process in case of Worker threads receiving a termination exception, rather than a “real one”. --- src/node_errors.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index b7f7f59e70ef62..7775e36b69bc82 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -315,7 +315,7 @@ void OnFatalError(const char* location, const char* message) { namespace errors { TryCatchScope::~TryCatchScope() { - if (HasCaught() && mode_ == CatchMode::kFatal) { + if (HasCaught() && !HasTerminated() && mode_ == CatchMode::kFatal) { HandleScope scope(env_->isolate()); ReportException(env_, Exception(), Message()); exit(7); From b878ee1e6f654c3c51b4999dd131d9573dafb7a4 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 19 Dec 2018 23:11:35 +0100 Subject: [PATCH 2/2] src: pass along MaybeLocal<> state from `URL::ToObject()` --- 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;