Skip to content

Commit

Permalink
src: move getActiveResources/Handles to node_process.cc
Browse files Browse the repository at this point in the history
PR-URL: #22758
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
jasnell authored and targos committed Sep 20, 2018
1 parent cadb360 commit 1d3a63f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 55 deletions.
55 changes: 0 additions & 55 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1102,61 +1102,6 @@ static MaybeLocal<Value> ExecuteString(Environment* env,
}


static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> ary = Array::New(args.GetIsolate());
Local<Context> ctx = env->context();
Local<Function> fn = env->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t idx = 0;

for (auto w : *env->req_wrap_queue()) {
if (w->persistent().IsEmpty())
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
}

if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
}

args.GetReturnValue().Set(ary);
}


// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
// implemented here for consistency with GetActiveRequests().
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> ary = Array::New(env->isolate());
Local<Context> ctx = env->context();
Local<Function> fn = env->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t idx = 0;

for (auto w : *env->handle_wrap_queue()) {
if (!HandleWrap::HasRef(w))
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
}
if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
}

args.GetReturnValue().Set(ary);
}


NO_RETURN void Abort() {
DumpBacktrace(stderr);
fflush(stderr);
Expand Down
2 changes: 2 additions & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ void Abort(const v8::FunctionCallbackInfo<v8::Value>& args);
void Chdir(const v8::FunctionCallbackInfo<v8::Value>& args);
void CPUUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
void Cwd(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetActiveRequests(const v8::FunctionCallbackInfo<v8::Value>& args);
void Hrtime(const v8::FunctionCallbackInfo<v8::Value>& args);
void HrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
void Kill(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
55 changes: 55 additions & 0 deletions src/node_process.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "node.h"
#include "node_internals.h"
#include "base_object.h"
#include "base_object-inl.h"
#include "env-inl.h"
#include "util-inl.h"
#include "uv.h"
Expand Down Expand Up @@ -777,5 +779,58 @@ void GetParentProcessId(Local<Name> property,
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid()));
}

void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> ary = Array::New(args.GetIsolate());
Local<Context> ctx = env->context();
Local<Function> fn = env->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t idx = 0;

for (auto w : *env->req_wrap_queue()) {
if (w->persistent().IsEmpty())
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
}

if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
}

args.GetReturnValue().Set(ary);
}


// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
// implemented here for consistency with GetActiveRequests().
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> ary = Array::New(env->isolate());
Local<Context> ctx = env->context();
Local<Function> fn = env->push_values_to_array_function();
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
size_t idx = 0;

for (auto w : *env->handle_wrap_queue()) {
if (!HandleWrap::HasRef(w))
continue;
argv[idx] = w->GetOwner();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
}
if (idx > 0) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
}

args.GetReturnValue().Set(ary);
}

} // namespace node

0 comments on commit 1d3a63f

Please sign in to comment.