Skip to content

Commit 08ef35c

Browse files
committed
fixup! async_hooks: add getActiveResources (prototype)
1 parent 1d6325f commit 08ef35c

File tree

5 files changed

+14
-53
lines changed

5 files changed

+14
-53
lines changed

lib/async_hooks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
NumberIsSafeInteger,
1010
ObjectDefineProperties,
1111
ObjectIs,
12+
ObjectValues,
1213
ReflectApply,
1314
Symbol,
1415
} = primordials;
@@ -154,7 +155,7 @@ function getActiveResources() {
154155
const reqs = process._getActiveRequests();
155156

156157
const timers = {};
157-
for (const list of Object.values(internalTimers.timerLists)) {
158+
for (const list of ObjectValues(internalTimers.timerLists)) {
158159
var timer = list._idlePrev === list ? null : list._idlePrev;
159160

160161
while (timer !== null) {
@@ -174,7 +175,7 @@ function getActiveResources() {
174175
immediate = immediate._idleNext;
175176
}
176177

177-
return Object.assign({}, handles, reqs, timers, immediates);
178+
return { ...handles, ...reqs, ...timers, ...immediates };
178179
}
179180

180181

lib/internal/timers.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const kRefed = Symbol('refed');
141141
//
142142
// - key = time in milliseconds
143143
// - value = linked list
144-
const timerLists = Object.create(null);
144+
const timerLists = ObjectCreate(null);
145145

146146
// A linked list for storing `setImmediate()` requests
147147
function ImmediateList() {
@@ -308,44 +308,6 @@ TimersList.prototype[inspect.custom] = function(_, options) {
308308
});
309309
};
310310

311-
// A linked list for storing `setImmediate()` requests
312-
function ImmediateList() {
313-
this.head = null;
314-
this.tail = null;
315-
}
316-
317-
// Appends an item to the end of the linked list, adjusting the current tail's
318-
// next pointer and the item's previous pointer where applicable
319-
ImmediateList.prototype.append = function(item) {
320-
if (this.tail !== null) {
321-
this.tail._idleNext = item;
322-
item._idlePrev = this.tail;
323-
} else {
324-
this.head = item;
325-
}
326-
this.tail = item;
327-
};
328-
329-
// Removes an item from the linked list, adjusting the pointers of adjacent
330-
// items and the linked list's head or tail pointers as necessary
331-
ImmediateList.prototype.remove = function(item) {
332-
if (item._idleNext !== null) {
333-
item._idleNext._idlePrev = item._idlePrev;
334-
}
335-
336-
if (item._idlePrev !== null) {
337-
item._idlePrev._idleNext = item._idleNext;
338-
}
339-
340-
if (item === this.head)
341-
this.head = item._idleNext;
342-
if (item === this.tail)
343-
this.tail = item._idlePrev;
344-
345-
item._idleNext = null;
346-
item._idlePrev = null;
347-
};
348-
349311
function incRefCount() {
350312
if (refCount++ === 0)
351313
toggleTimerRef(true);

lib/timers.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ const {
5151
active,
5252
unrefActive,
5353
insert,
54-
timerLists: lists,
55-
immediateQueue,
56-
outstandingQueue,
5754
} = require('internal/timers');
5855
const {
5956
promisify: { custom: customPromisify },

src/node_process_methods.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "async_wrap-inl.h"
12
#include "base_object-inl.h"
23
#include "debug_utils-inl.h"
34
#include "env-inl.h"
@@ -35,7 +36,6 @@ typedef int mode_t;
3536
namespace node {
3637

3738
using v8::ApiObject;
38-
using v8::Array;
3939
using v8::ArrayBuffer;
4040
using v8::BackingStore;
4141
using v8::CFunction;
@@ -254,13 +254,16 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
254254
Local<Context> ctx = env->context();
255255
Local<Object> return_obj = Object::New(args.GetIsolate());
256256

257-
for (auto w : *env->req_wrap_queue()) {
257+
for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) {
258+
AsyncWrap* w = req_wrap->GetAsyncWrap();
258259
if (w->persistent().IsEmpty())
259260
continue;
260261
double async_id = w->get_async_id();
261262
Local<Object> req_obj = w->object();
262263

263-
return_obj->Set(ctx, Number::New(args.GetIsolate(), async_id), req_obj);
264+
USE(return_obj->Set(ctx,
265+
Number::New(args.GetIsolate(), async_id),
266+
req_obj));
264267
}
265268

266269
args.GetReturnValue().Set(return_obj);
@@ -274,16 +277,14 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
274277
Local<Context> ctx = env->context();
275278
Local<Object> return_obj = Object::New(args.GetIsolate());
276279

277-
Local<String> owner_sym = env->owner_string();
278-
279280
for (auto w : *env->handle_wrap_queue()) {
280281
if (w->persistent().IsEmpty() || !HandleWrap::HasRef(w))
281282
continue;
282283
double async_id = w->get_async_id();
283284
Local<Object> handle_object = w->object();
284-
return_obj->Set(ctx, Number::New(args.GetIsolate(),
285-
async_id),
286-
handle_object);
285+
USE(return_obj->Set(ctx, Number::New(args.GetIsolate(),
286+
async_id),
287+
handle_object));
287288
}
288289

289290
args.GetReturnValue().Set(return_obj);

test/parallel/test-async-hooks-getactiveresources-requests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ const { getActiveResources } = require('async_hooks');
88
for (let i = 0; i < 12; i++)
99
fs.open(__filename, 'r', common.mustCall());
1010

11-
assert.strictEqual(12, Object.values(getActiveResources()).length);
11+
assert.strictEqual(Object.values(getActiveResources()).length, 12);

0 commit comments

Comments
 (0)