Skip to content
Permalink
Browse files

console: console.time() should not reset a timer when it exists

PR-URL: #20442
Fixes: #20440
Refs: https://console.spec.whatwg.org/#time
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
  • Loading branch information
devsnek committed May 1, 2018
1 parent 0930d7e commit a59826403a76fcc7a6685a52ee82d19be323a699
Showing with 18 additions and 0 deletions.
  1. +4 −0 lib/console.js
  2. +14 −0 test/parallel/test-console.js
@@ -225,6 +225,10 @@ Console.prototype.dir = function dir(object, options) {
Console.prototype.time = function time(label = 'default') {
// Coerces everything other than Symbol to a string
label = `${label}`;
if (this._times.has(label)) {
process.emitWarning(`Label '${label}' already exists for console.time()`);
return;
}
this._times.set(label, process.hrtime());
};

@@ -138,6 +138,20 @@ console.timeEnd();
console.time(NaN);
console.timeEnd(NaN);

// make sure calling time twice without timeEnd doesn't reset the timer.
console.time('test');
const time = console._times.get('test');
setTimeout(() => {
assert.deepStrictEqual(console._times.get('test'), time);
common.expectWarning(
'Warning',
'Label \'test\' already exists for console.time()',
common.noWarnCode);
console.time('test');
console.timeEnd('test');
}, 1);


console.assert(false, '%s should', 'console.assert', 'not throw');
assert.strictEqual(errStrings[errStrings.length - 1],
'Assertion failed: console.assert should not throw\n');

0 comments on commit a598264

Please sign in to comment.
You can’t perform that action at this time.