Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: pass along errors from PromiseWrap instantiation
  • Loading branch information
addaleax committed Jan 27, 2019
commit a175796984baa53de421e5e756f9e69d40ad00c9
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