|
29 | 29 |
|
30 | 30 | #include "v8.h" |
31 | 31 |
|
| 32 | +using v8::Array; |
32 | 33 | using v8::Context; |
33 | 34 | using v8::DontDelete; |
34 | 35 | using v8::EscapableHandleScope; |
@@ -513,6 +514,36 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) { |
513 | 514 | p->env->AddCleanupHook(DestroyParamCleanupHook, p); |
514 | 515 | } |
515 | 516 |
|
| 517 | +static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { |
| 518 | + Environment* env = Environment::GetCurrent(args); |
| 519 | + |
| 520 | + std::vector<Local<Value>> request_v; |
| 521 | + for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) { |
| 522 | + AsyncWrap* w = req_wrap->GetAsyncWrap(); |
| 523 | + if (w->persistent().IsEmpty()) |
| 524 | + continue; |
| 525 | + request_v.emplace_back(w->GetOwner()); |
| 526 | + } |
| 527 | + |
| 528 | + args.GetReturnValue().Set( |
| 529 | + Array::New(env->isolate(), request_v.data(), request_v.size())); |
| 530 | +} |
| 531 | + |
| 532 | +// Non-static, friend of HandleWrap. Could have been a HandleWrap method but |
| 533 | +// implemented here for consistency with GetActiveRequests(). |
| 534 | +void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { |
| 535 | + Environment* env = Environment::GetCurrent(args); |
| 536 | + |
| 537 | + std::vector<Local<Value>> handle_v; |
| 538 | + for (auto w : *env->handle_wrap_queue()) { |
| 539 | + if (!HandleWrap::HasRef(w)) |
| 540 | + continue; |
| 541 | + handle_v.emplace_back(w->GetOwner()); |
| 542 | + } |
| 543 | + args.GetReturnValue().Set( |
| 544 | + Array::New(env->isolate(), handle_v.data(), handle_v.size())); |
| 545 | +} |
| 546 | + |
516 | 547 | void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) { |
517 | 548 | AsyncWrap* wrap; |
518 | 549 | args.GetReturnValue().Set(kInvalidAsyncId); |
@@ -634,6 +665,9 @@ void AsyncWrap::Initialize(Local<Object> target, |
634 | 665 | env->SetMethod(target, "disablePromiseHook", DisablePromiseHook); |
635 | 666 | env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook); |
636 | 667 |
|
| 668 | + env->SetMethod(target, "getActiveRequests", GetActiveRequests); |
| 669 | + env->SetMethod(target, "getActiveHandles", GetActiveHandles); |
| 670 | + |
637 | 671 | PropertyAttribute ReadOnlyDontDelete = |
638 | 672 | static_cast<PropertyAttribute>(ReadOnly | DontDelete); |
639 | 673 |
|
@@ -732,6 +766,8 @@ void AsyncWrap::RegisterExternalReferences( |
732 | 766 | registry->Register(AsyncWrap::GetProviderType); |
733 | 767 | registry->Register(PromiseWrap::GetAsyncId); |
734 | 768 | registry->Register(PromiseWrap::GetTriggerAsyncId); |
| 769 | + registry->Register(GetActiveRequests); |
| 770 | + registry->Register(GetActiveHandles); |
735 | 771 | } |
736 | 772 |
|
737 | 773 | AsyncWrap::AsyncWrap(Environment* env, |
|
0 commit comments