From a29a712f70f48a61dfb0c99682fe468248a6f6d8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 27 Jan 2019 14:18:13 +0100 Subject: [PATCH] src: pass along errors from PromiseWrap instantiation PR-URL: https://github.com/nodejs/node/pull/25734 Reviewed-By: James M Snell Reviewed-By: Gus Caplan --- src/async_wrap.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 493581d27c5130..9798fc0de8471f 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -204,16 +204,16 @@ PromiseWrap* PromiseWrap::New(Environment* env, Local promise, PromiseWrap* parent_wrap, bool silent) { - Local object = env->promise_wrap_template() - ->NewInstance(env->context()).ToLocalChecked(); - object->SetInternalField(PromiseWrap::kPromiseField, promise); - object->SetInternalField(PromiseWrap::kIsChainedPromiseField, - parent_wrap != nullptr ? - v8::True(env->isolate()) : - v8::False(env->isolate())); + Local obj; + if (!env->promise_wrap_template()->NewInstance(env->context()).ToLocal(&obj)) + return nullptr; + obj->SetInternalField(PromiseWrap::kPromiseField, promise); + obj->SetInternalField(PromiseWrap::kIsChainedPromiseField, + parent_wrap != nullptr ? v8::True(env->isolate()) + : v8::False(env->isolate())); CHECK_EQ(promise->GetAlignedPointerFromInternalField(0), nullptr); - promise->SetInternalField(0, object); - return new PromiseWrap(env, object, silent); + promise->SetInternalField(0, obj); + return new PromiseWrap(env, obj, silent); } void PromiseWrap::GetPromise(Local property, @@ -251,6 +251,7 @@ static void PromiseHook(PromiseHookType type, Local promise, PromiseWrap* parent_wrap = extractPromiseWrap(parent_promise); if (parent_wrap == nullptr) { parent_wrap = PromiseWrap::New(env, parent_promise, nullptr, true); + if (parent_wrap == nullptr) return; } AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent_wrap); @@ -260,7 +261,8 @@ static void PromiseHook(PromiseHookType type, Local promise, } } - CHECK_NOT_NULL(wrap); + if (wrap == nullptr) return; + if (type == PromiseHookType::kBefore) { env->async_hooks()->push_async_ids( wrap->get_async_id(), wrap->get_trigger_async_id());