Skip to content

Commit

Permalink
console: prevent internal timers storage from growing
Browse files Browse the repository at this point in the history
The instance of `Console` class doesn't remove links to arrays that
come from hrtimer after `timeEnd` had been called.
  • Loading branch information
Vladimir Varankin committed Nov 13, 2015
1 parent d9734b7 commit 474c066
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 474c066

Please sign in to comment.