Skip to content

Commit 1d3a63f

Browse files
jasnelltargos
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 cadb360 commit 1d3a63f

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
@@ -1102,61 +1102,6 @@ static MaybeLocal<Value> ExecuteString(Environment* env,
11021102
}
11031103

11041104

1105-
static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
1106-
Environment* env = Environment::GetCurrent(args);
1107-
1108-
Local<Array> ary = Array::New(args.GetIsolate());
1109-
Local<Context> ctx = env->context();
1110-
Local<Function> fn = env->push_values_to_array_function();
1111-
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1112-
size_t idx = 0;
1113-
1114-
for (auto w : *env->req_wrap_queue()) {
1115-
if (w->persistent().IsEmpty())
1116-
continue;
1117-
argv[idx] = w->GetOwner();
1118-
if (++idx >= arraysize(argv)) {
1119-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1120-
idx = 0;
1121-
}
1122-
}
1123-
1124-
if (idx > 0) {
1125-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1126-
}
1127-
1128-
args.GetReturnValue().Set(ary);
1129-
}
1130-
1131-
1132-
// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
1133-
// implemented here for consistency with GetActiveRequests().
1134-
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
1135-
Environment* env = Environment::GetCurrent(args);
1136-
1137-
Local<Array> ary = Array::New(env->isolate());
1138-
Local<Context> ctx = env->context();
1139-
Local<Function> fn = env->push_values_to_array_function();
1140-
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1141-
size_t idx = 0;
1142-
1143-
for (auto w : *env->handle_wrap_queue()) {
1144-
if (!HandleWrap::HasRef(w))
1145-
continue;
1146-
argv[idx] = w->GetOwner();
1147-
if (++idx >= arraysize(argv)) {
1148-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1149-
idx = 0;
1150-
}
1151-
}
1152-
if (idx > 0) {
1153-
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
1154-
}
1155-
1156-
args.GetReturnValue().Set(ary);
1157-
}
1158-
1159-
11601105
NO_RETURN void Abort() {
11611106
DumpBacktrace(stderr);
11621107
fflush(stderr);

src/node_internals.h

+2
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ void Abort(const v8::FunctionCallbackInfo<v8::Value>& args);
888888
void Chdir(const v8::FunctionCallbackInfo<v8::Value>& args);
889889
void CPUUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
890890
void Cwd(const v8::FunctionCallbackInfo<v8::Value>& args);
891+
void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>& args);
892+
void GetActiveRequests(const v8::FunctionCallbackInfo<v8::Value>& args);
891893
void Hrtime(const v8::FunctionCallbackInfo<v8::Value>& args);
892894
void HrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
893895
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"
@@ -777,5 +779,58 @@ void GetParentProcessId(Local<Name> property,
777779
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid()));
778780
}
779781

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+
}
780835

781836
} // namespace node

0 commit comments

Comments
 (0)