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:
parent
69f1a2bb85
commit
d8baf67d4a
@ -17,6 +17,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;
|
||||
|
||||
@ -82,6 +84,17 @@ function Timeout(callback, after, args, isRepeat) {
|
||||
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[kRefed])
|
||||
getTimers().active(this);
|
||||
|
@ -239,6 +239,17 @@ function TimersList(expiry, msecs) {
|
||||
this.priorityQueuePosition = null;
|
||||
}
|
||||
|
||||
// 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
|
||||
});
|
||||
};
|
||||
|
||||
const { _tickCallback: runNextTicks } = process;
|
||||
function processTimers(now) {
|
||||
debug('process timer lists %d', now);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user