|
1 | 1 | #include "node.h"
|
2 | 2 | #include "node_internals.h"
|
| 3 | +#include "base_object.h" |
| 4 | +#include "base_object-inl.h" |
3 | 5 | #include "env-inl.h"
|
4 | 6 | #include "util-inl.h"
|
5 | 7 | #include "uv.h"
|
@@ -777,5 +779,58 @@ void GetParentProcessId(Local<Name> property,
|
777 | 779 | info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid()));
|
778 | 780 | }
|
779 | 781 |
|
| 782 | +void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { |
| 783 | + Environment* env = Environment::GetCurrent(args); |
| 784 | + |
| 785 | + Local<Array> ary = Array::New(args.GetIsolate()); |
| 786 | + Local<Context> ctx = env->context(); |
| 787 | + Local<Function> fn = env->push_values_to_array_function(); |
| 788 | + Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; |
| 789 | + size_t idx = 0; |
| 790 | + |
| 791 | + for (auto w : *env->req_wrap_queue()) { |
| 792 | + if (w->persistent().IsEmpty()) |
| 793 | + continue; |
| 794 | + argv[idx] = w->GetOwner(); |
| 795 | + if (++idx >= arraysize(argv)) { |
| 796 | + fn->Call(ctx, ary, idx, argv).ToLocalChecked(); |
| 797 | + idx = 0; |
| 798 | + } |
| 799 | + } |
| 800 | + |
| 801 | + if (idx > 0) { |
| 802 | + fn->Call(ctx, ary, idx, argv).ToLocalChecked(); |
| 803 | + } |
| 804 | + |
| 805 | + args.GetReturnValue().Set(ary); |
| 806 | +} |
| 807 | + |
| 808 | + |
| 809 | +// Non-static, friend of HandleWrap. Could have been a HandleWrap method but |
| 810 | +// implemented here for consistency with GetActiveRequests(). |
| 811 | +void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { |
| 812 | + Environment* env = Environment::GetCurrent(args); |
| 813 | + |
| 814 | + Local<Array> ary = Array::New(env->isolate()); |
| 815 | + Local<Context> ctx = env->context(); |
| 816 | + Local<Function> fn = env->push_values_to_array_function(); |
| 817 | + Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; |
| 818 | + size_t idx = 0; |
| 819 | + |
| 820 | + for (auto w : *env->handle_wrap_queue()) { |
| 821 | + if (!HandleWrap::HasRef(w)) |
| 822 | + continue; |
| 823 | + argv[idx] = w->GetOwner(); |
| 824 | + if (++idx >= arraysize(argv)) { |
| 825 | + fn->Call(ctx, ary, idx, argv).ToLocalChecked(); |
| 826 | + idx = 0; |
| 827 | + } |
| 828 | + } |
| 829 | + if (idx > 0) { |
| 830 | + fn->Call(ctx, ary, idx, argv).ToLocalChecked(); |
| 831 | + } |
| 832 | + |
| 833 | + args.GetReturnValue().Set(ary); |
| 834 | +} |
780 | 835 |
|
781 | 836 | } // namespace node
|
0 commit comments