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>
  • Loading branch information
addaleax committed Jan 29, 2019
1 parent 1a37fd6 commit 5556975
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ 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::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::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::getIsChainedPromise(Local<String> property,
Expand Down Expand Up @@ -242,6 +242,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 @@ -251,7 +252,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 5556975

Please sign in to comment.