Skip to content

Commit

Permalink
src: pass along errors from PromiseWrap instantiation
Browse files Browse the repository at this point in the history
PR-URL: #25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>

PR-URL: #25837
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
addaleax committed Feb 3, 2019
1 parent cdf3e84 commit 882902c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ PromiseWrap* PromiseWrap::New(Environment* env,
Local<Promise> promise,
PromiseWrap* parent_wrap,
bool silent) {
Local<Object> 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<Object> 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<String> property,
Expand Down Expand Up @@ -251,6 +251,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> 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);
Expand All @@ -260,7 +261,8 @@ static void PromiseHook(PromiseHookType type, Local<Promise> 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());
Expand Down

0 comments on commit 882902c

Please sign in to comment.