Skip to content

Commit efd4796

Browse files
jasnelladdaleax
authored andcommitted
src: move getActiveResources/Handles to node_process.cc
PR-URL: #22758 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 48e8918 commit efd4796

File tree

3 files changed

+57
-55
lines changed

3 files changed

+57
-55
lines changed

src/node.cc

-55
Original file line numberDiff line numberDiff line change
@@ -1040,61 +1040,6 @@ static MaybeLocal<Value> ExecuteString(Environment* env,
10401040
}
10411041

10421042

1043-
static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
1044-
Environment* env = Environment::GetCurrent(args);
1045-
1046-
Local<Array> ary = Array::New(args.GetIsolate());
1047-
Local<Context> ctx = env->context();
1048-
Local<Function> fn = env->push_values_to_array_function();
1049-
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1050-
size_t idx = 0;
1051-
1052-
for (auto w : *env->req_wrap_queue()) {
1053-
if (w->persistent().IsEmpty())
1054-
continue;
1055-
argv[idx] = w->GetOwner();
1056-
if (++idx >= arraysize(argv)) {
1057-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1058-
idx = 0;
1059-
}
1060-
}
1061-
1062-
if (idx > 0) {
1063-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1064-
}
1065-
1066-
args.GetReturnValue().Set(ary);
1067-
}
1068-
1069-
1070-
// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
1071-
// implemented here for consistency with GetActiveRequests().
1072-
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
1073-
Environment* env = Environment::GetCurrent(args);
1074-
1075-
Local<Array> ary = Array::New(env->isolate());
1076-
Local<Context> ctx = env->context();
1077-
Local<Function> fn = env->push_values_to_array_function();
1078-
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1079-
size_t idx = 0;
1080-
1081-
for (auto w : *env->handle_wrap_queue()) {
1082-
if (!HandleWrap::HasRef(w))
1083-
continue;
1084-
argv[idx] = w->GetOwner();
1085-
if (++idx >= arraysize(argv)) {
1086-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1087-
idx = 0;
1088-
}
1089-
}
1090-
if (idx > 0) {
1091-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1092-
}
1093-
1094-
args.GetReturnValue().Set(ary);
1095-
}
1096-
1097-
10981043
NO_RETURN void Abort() {
10991044
DumpBacktrace(stderr);
11001045
fflush(stderr);

src/node_internals.h

+2
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,8 @@ void Abort(const v8::FunctionCallbackInfo<v8::Value>& args);
883883
void Chdir(const v8::FunctionCallbackInfo<v8::Value>& args);
884884
void CPUUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
885885
void Cwd(const v8::FunctionCallbackInfo<v8::Value>& args);
886+
void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>& args);
887+
void GetActiveRequests(const v8::FunctionCallbackInfo<v8::Value>& args);
886888
void Hrtime(const v8::FunctionCallbackInfo<v8::Value>& args);
887889
void HrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
888890
void Kill(const v8::FunctionCallbackInfo<v8::Value>& args);

src/node_process.cc

+55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "node.h"
22
#include "node_internals.h"
3+
#include "base_object.h"
4+
#include "base_object-inl.h"
35
#include "env-inl.h"
46
#include "util-inl.h"
57
#include "uv.h"
@@ -786,5 +788,58 @@ void GetParentProcessId(Local<Name> property,
786788
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid()));
787789
}
788790

791+
void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
792+
Environment* env = Environment::GetCurrent(args);
793+
794+
Local<Array> ary = Array::New(args.GetIsolate());
795+
Local<Context> ctx = env->context();
796+
Local<Function> fn = env->push_values_to_array_function();
797+
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
798+
size_t idx = 0;
799+
800+
for (auto w : *env->req_wrap_queue()) {
801+
if (w->persistent().IsEmpty())
802+
continue;
803+
argv[idx] = w->GetOwner();
804+
if (++idx >= arraysize(argv)) {
805+
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
806+
idx = 0;
807+
}
808+
}
809+
810+
if (idx > 0) {
811+
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
812+
}
813+
814+
args.GetReturnValue().Set(ary);
815+
}
816+
817+
818+
// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
819+
// implemented here for consistency with GetActiveRequests().
820+
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
821+
Environment* env = Environment::GetCurrent(args);
822+
823+
Local<Array> ary = Array::New(env->isolate());
824+
Local<Context> ctx = env->context();
825+
Local<Function> fn = env->push_values_to_array_function();
826+
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
827+
size_t idx = 0;
828+
829+
for (auto w : *env->handle_wrap_queue()) {
830+
if (!HandleWrap::HasRef(w))
831+
continue;
832+
argv[idx] = w->GetOwner();
833+
if (++idx >= arraysize(argv)) {
834+
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
835+
idx = 0;
836+
}
837+
}
838+
if (idx > 0) {
839+
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
840+
}
841+
842+
args.GetReturnValue().Set(ary);
843+
}
789844

790845
} // namespace node

0 commit comments

Comments
 (0)