From e813e3491e3b9d828ae678391b7c926c4ad1f180 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 15 May 2012 17:24:06 +0200 Subject: [PATCH] node: make _getActiveHandles() return user objects Before this commit, process._getActiveHandles() returned a list of internal handles. Now, it returns the user objects that handles are attached to. For example, a tcp_wrap handle will now return its parent net.Socket object. It works for all handle types except timers because timer handles are shared across multiple user objects. --- src/node.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 41dab06e52..c17eb47098 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1362,10 +1362,14 @@ Handle GetActiveHandles(const Arguments& args) { ngx_queue_t* q = NULL; int i = 0; + Local owner_sym = String::New("owner"); + ngx_queue_foreach(q, &handle_wrap_queue) { HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_); if (w->object_.IsEmpty() || w->unref) continue; - ary->Set(i++, w->object_); + Local obj = w->object_->Get(owner_sym); + if (obj->IsUndefined()) obj = *w->object_; + ary->Set(i++, obj); } return scope.Close(ary);