timers: use custom inspection for linked lists

Inspecting linked lists is something that is not really useful.
Instead, just use a custom inspection function and hide everything
besides the first level.

PR-URL: https://github.com/nodejs/node/pull/23108
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Ruben Bridgewater authored and Michaël Zasso committed 2018-10-03 07:59:08 +02:00
1 parent a2c1ce24b5
commit 4436a3d660
3 files changed
+41

No files matched your search

+13
View File
@@ -16,6 +16,8 @@ const {
} = require('internal/errors').codes;
const { validateNumber } = require('internal/validators');
const { inspect } = require('util');
// Timeout values > TIMEOUT_MAX are set to 1.
const TIMEOUT_MAX = 2 ** 31 - 1;
@@ -80,6 +82,17 @@ function Timeout(callback, after, args, isRepeat, isUnrefed) {
initAsyncResource(this, 'Timeout');
}
// Make sure the linked list only shows the minimal necessary information.
Timeout.prototype[inspect.custom] = function(_, options) {
return inspect(this, {
...options,
// Only inspect one level.
depth: 0,
// It should not recurse.
customInspect: false
});
};
Timeout.prototype.refresh = function() {
if (this._handle) {
// Would be more ideal with uv_timer_again(), however that API does not
+11
View File
@@ -206,6 +206,17 @@ function TimersList(msecs, unrefed) {
timer.start(msecs);
}
// Make sure the linked list only shows the minimal necessary information.
TimersList.prototype[util.inspect.custom] = function(_, options) {
return util.inspect(this, {
...options,
// Only inspect one level.
depth: 0,
// It should not recurse.
customInspect: false
});
};
function processTimers(now) {
if (this[owner_symbol])
return unrefdHandle(this[owner_symbol], now);
+17
View File
@@ -8,6 +8,7 @@ if (!common.hasCrypto)
const assert = require('assert');
const h2 = require('http2');
const net = require('net');
const util = require('util');
const { kTimeout } = require('internal/timers');
@@ -35,6 +36,22 @@ server.on('stream', common.mustCall(function(stream, headers) {
socket.setTimeout(987);
assert.strictEqual(session[kTimeout]._idleTimeout, 987);
// The indentation is corrected depending on the depth.
let inspectedTimeout = util.inspect(session[kTimeout]);
assert(inspectedTimeout.includes(' _idlePrev: [TimersList]'));
assert(inspectedTimeout.includes(' _idleNext: [TimersList]'));
assert(!inspectedTimeout.includes(' _idleNext: [TimersList]'));
inspectedTimeout = util.inspect([ session[kTimeout] ]);
assert(inspectedTimeout.includes(' _idlePrev: [TimersList]'));
assert(inspectedTimeout.includes(' _idleNext: [TimersList]'));
assert(!inspectedTimeout.includes(' _idleNext: [TimersList]'));
const inspectedTimersList = util.inspect([[ session[kTimeout]._idlePrev ]]);
assert(inspectedTimersList.includes(' _idlePrev: [Timeout]'));
assert(inspectedTimersList.includes(' _idleNext: [Timeout]'));
assert(!inspectedTimersList.includes(' _idleNext: [Timeout]'));
common.expectsError(() => socket.destroy, errMsg);
common.expectsError(() => socket.emit, errMsg);
common.expectsError(() => socket.end, errMsg);