mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
async_wrap,src: promise hook integration
This change provides unified tracking of asynchronous promise lifecycles for both domains and async hooks. PR-URL: https://github.com/nodejs/node/pull/13000 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
410b141764
commit
920278bd37
6 files changed
+223
-98
No files matched your search
+3
-32
@@ -1130,7 +1130,6 @@ void DomainPromiseHook(PromiseHookType type,
|
||||
Environment* env = static_cast<Environment*>(arg);
|
||||
Local<Context> context = env->context();
|
||||
|
||||
if (type == PromiseHookType::kResolve) return;
|
||||
if (type == PromiseHookType::kInit && env->in_domain()) {
|
||||
promise->Set(context,
|
||||
env->domain_string(),
|
||||
@@ -1139,38 +1138,10 @@ void DomainPromiseHook(PromiseHookType type,
|
||||
return;
|
||||
}
|
||||
|
||||
// Loosely based on node::MakeCallback().
|
||||
Local<Value> domain_v =
|
||||
promise->Get(context, env->domain_string()).ToLocalChecked();
|
||||
if (!domain_v->IsObject())
|
||||
return;
|
||||
|
||||
Local<Object> domain = domain_v.As<Object>();
|
||||
if (domain->Get(context, env->disposed_string())
|
||||
.ToLocalChecked()->IsTrue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == PromiseHookType::kBefore) {
|
||||
Local<Value> enter_v =
|
||||
domain->Get(context, env->enter_string()).ToLocalChecked();
|
||||
if (enter_v->IsFunction()) {
|
||||
if (enter_v.As<Function>()->Call(context, domain, 0, nullptr).IsEmpty()) {
|
||||
FatalError("node::PromiseHook",
|
||||
"domain enter callback threw, please report this "
|
||||
"as a bug in Node.js");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Local<Value> exit_v =
|
||||
domain->Get(context, env->exit_string()).ToLocalChecked();
|
||||
if (exit_v->IsFunction()) {
|
||||
if (exit_v.As<Function>()->Call(context, domain, 0, nullptr).IsEmpty()) {
|
||||
FatalError("node::MakeCallback",
|
||||
"domain exit callback threw, please report this "
|
||||
"as a bug in Node.js");
|
||||
}
|
||||
}
|
||||
DomainEnter(env, promise);
|
||||
} else if (type == PromiseHookType::kAfter) {
|
||||
DomainExit(env, promise);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user