From efd4796fa905747985d6de215d5e64b4701cf347 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 7 Sep 2018 15:37:31 -0700 Subject: src: move getActiveResources/Handles to node_process.cc PR-URL: https://github.com/nodejs/node/pull/22758 Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan Reviewed-By: Refael Ackermann --- src/node.cc | 55 ---------------------------------------------------- src/node_internals.h | 2 ++ src/node_process.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/node.cc b/src/node.cc index 72a83d538f..ed4da64425 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1040,61 +1040,6 @@ static MaybeLocal ExecuteString(Environment* env, } -static void GetActiveRequests(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - - Local ary = Array::New(args.GetIsolate()); - Local ctx = env->context(); - Local fn = env->push_values_to_array_function(); - Local 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& args) { - Environment* env = Environment::GetCurrent(args); - - Local ary = Array::New(env->isolate()); - Local ctx = env->context(); - Local fn = env->push_values_to_array_function(); - Local 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); diff --git a/src/node_internals.h b/src/node_internals.h index 5cf606ddee..8ab79a1267 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -883,6 +883,8 @@ void Abort(const v8::FunctionCallbackInfo& args); void Chdir(const v8::FunctionCallbackInfo& args); void CPUUsage(const v8::FunctionCallbackInfo& args); void Cwd(const v8::FunctionCallbackInfo& args); +void GetActiveHandles(const v8::FunctionCallbackInfo& args); +void GetActiveRequests(const v8::FunctionCallbackInfo& args); void Hrtime(const v8::FunctionCallbackInfo& args); void HrtimeBigInt(const v8::FunctionCallbackInfo& args); void Kill(const v8::FunctionCallbackInfo& args); diff --git a/src/node_process.cc b/src/node_process.cc index ba774fd8fa..19596f0cfd 100644 --- a/src/node_process.cc +++ b/src/node_process.cc @@ -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" @@ -786,5 +788,58 @@ void GetParentProcessId(Local property, info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid())); } +void GetActiveRequests(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + + Local ary = Array::New(args.GetIsolate()); + Local ctx = env->context(); + Local fn = env->push_values_to_array_function(); + Local 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& args) { + Environment* env = Environment::GetCurrent(args); + + Local ary = Array::New(env->isolate()); + Local ctx = env->context(); + Local fn = env->push_values_to_array_function(); + Local 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 -- cgit v1.2.3