From 474c0660c5308e63c037e86f52c0b290a7eff7d9 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Wed, 28 Oct 2015 15:56:34 +0300 Subject: [PATCH] console: prevent internal timers storage from growing The instance of `Console` class doesn't remove links to arrays that come from hrtimer after `timeEnd` had been called. --- lib/console.js | 1 + test/parallel/test-console.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/console.js b/lib/console.js index 531a383876ce2b..a0eec4e34878be 100644 --- a/lib/console.js +++ b/lib/console.js @@ -68,6 +68,7 @@ Console.prototype.timeEnd = function(label) { const duration = process.hrtime(time); const ms = duration[0] * 1000 + duration[1] / 1e6; this.log('%s: %sms', label, ms.toFixed(3)); + this._times.delete(label); }; diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index f8a927398034cb..0162ddf1b88d57 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -57,6 +57,16 @@ console.timeEnd('hasOwnProperty'); global.process.stdout.write = stdout_write; +// verify that console.timeEnd() doesn't leave dead links +const timesMapSize = console._times.size; +console.time('label1'); +console.time('label2'); +console.time('label3'); +console.timeEnd('label1'); +console.timeEnd('label2'); +console.timeEnd('label3'); +assert.strictEqual(console._times.size, timesMapSize); + assert.equal('foo\n', strings.shift()); assert.equal('foo bar\n', strings.shift()); assert.equal('foo bar hop\n', strings.shift());