From 234a850daa235303274808fa45e8aaf1d0726147 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 7 Sep 2018 15:37:31 -0700 Subject: [PATCH 1/2] src: move getActiveResources/Handles to node_process.cc --- 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 89e4f76caca049..3e23ab43396220 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1105,61 +1105,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 edfc00e53f13a7..30ac70e9f165fe 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -888,6 +888,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 ba774fd8fa652e..19596f0cfd261d 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 From 1d9e15cafbee380eaa8e3fa93bbd23b2fe27d956 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 7 Sep 2018 16:19:03 -0700 Subject: [PATCH 2/2] src: move DebugPortGetter/Setter to node_process.cc --- src/node.cc | 27 --------------------------- src/node_internals.h | 5 +++++ src/node_process.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/node.cc b/src/node.cc index 3e23ab43396220..ea67b1e2789b5f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -160,7 +160,6 @@ using v8::Object; using v8::ObjectTemplate; using v8::Promise; using v8::PropertyAttribute; -using v8::PropertyCallbackInfo; using v8::ReadOnly; using v8::Script; using v8::ScriptCompiler; @@ -1737,32 +1736,6 @@ static Local GetFeatures(Environment* env) { return scope.Escape(obj); } - -static void DebugPortGetter(Local property, - const PropertyCallbackInfo& info) { - Environment* env = Environment::GetCurrent(info); - Mutex::ScopedLock lock(process_mutex); - int port = env->options()->debug_options->port(); -#if HAVE_INSPECTOR - if (port == 0) { - if (auto io = env->inspector_agent()->io()) - port = io->port(); - } -#endif // HAVE_INSPECTOR - info.GetReturnValue().Set(port); -} - - -static void DebugPortSetter(Local property, - Local value, - const PropertyCallbackInfo& info) { - Environment* env = Environment::GetCurrent(info); - Mutex::ScopedLock lock(process_mutex); - env->options()->debug_options->host_port.port = - value->Int32Value(env->context()).FromMaybe(0); -} - - static void DebugProcess(const FunctionCallbackInfo& args); static void DebugEnd(const FunctionCallbackInfo& args); diff --git a/src/node_internals.h b/src/node_internals.h index 30ac70e9f165fe..8a84214868a1ad 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -910,6 +910,11 @@ void EnvSetter(v8::Local property, void EnvQuery(v8::Local property, const v8::PropertyCallbackInfo& info); void EnvEnumerator(const v8::PropertyCallbackInfo& info); +void DebugPortGetter(v8::Local property, + const v8::PropertyCallbackInfo& info); +void DebugPortSetter(v8::Local property, + v8::Local value, + const v8::PropertyCallbackInfo& info); void GetParentProcessId(v8::Local property, const v8::PropertyCallbackInfo& info); diff --git a/src/node_process.cc b/src/node_process.cc index 19596f0cfd261d..c223b482cf4dbd 100644 --- a/src/node_process.cc +++ b/src/node_process.cc @@ -7,6 +7,10 @@ #include "uv.h" #include "v8.h" +#if HAVE_INSPECTOR +#include "inspector_io.h" +#endif + #include // PATH_MAX #include @@ -842,4 +846,29 @@ void GetActiveHandles(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(ary); } +void DebugPortGetter(Local property, + const PropertyCallbackInfo& info) { + Environment* env = Environment::GetCurrent(info); + Mutex::ScopedLock lock(process_mutex); + int port = env->options()->debug_options->port(); +#if HAVE_INSPECTOR + if (port == 0) { + if (auto io = env->inspector_agent()->io()) + port = io->port(); + } +#endif // HAVE_INSPECTOR + info.GetReturnValue().Set(port); +} + + +void DebugPortSetter(Local property, + Local value, + const PropertyCallbackInfo& info) { + Environment* env = Environment::GetCurrent(info); + Mutex::ScopedLock lock(process_mutex); + env->options()->debug_options->host_port.port = + value->Int32Value(env->context()).FromMaybe(0); +} + + } // namespace node