console: console.time() should not reset a timer when it exists
PR-URL: https://github.com/nodejs/node/pull/20442 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
0930d7ec05
commit
a59826403a
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user