console: console.timeLog() using the default label
PR-URL: https://github.com/nodejs/node/pull/24286 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
0603c0a53f
commit
733278b81b
@ -260,7 +260,7 @@ Console.prototype.timeEnd = function timeEnd(label = 'default') {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Console.prototype.timeLog = function timeLog(label, ...data) {
|
Console.prototype.timeLog = function timeLog(label = 'default', ...data) {
|
||||||
// Coerces everything other than Symbol to a string
|
// Coerces everything other than Symbol to a string
|
||||||
label = `${label}`;
|
label = `${label}`;
|
||||||
timeLogImpl(this, 'timeLog', label, data);
|
timeLogImpl(this, 'timeLog', label, data);
|
||||||
@ -268,7 +268,7 @@ Console.prototype.timeLog = function timeLog(label, ...data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Returns true if label was not found
|
// Returns true if label was not found
|
||||||
function timeLogImpl(self, name, label = 'default', data) {
|
function timeLogImpl(self, name, label, data) {
|
||||||
const time = self._times.get(label);
|
const time = self._times.get(label);
|
||||||
if (!time) {
|
if (!time) {
|
||||||
process.emitWarning(`No such label '${label}' for console.${name}()`);
|
process.emitWarning(`No such label '${label}' for console.${name}()`);
|
||||||
|
@ -45,6 +45,10 @@ common.expectWarning(
|
|||||||
['Count for \'noLabel\' does not exist', common.noWarnCode],
|
['Count for \'noLabel\' does not exist', common.noWarnCode],
|
||||||
['No such label \'noLabel\' for console.timeLog()', common.noWarnCode],
|
['No such label \'noLabel\' for console.timeLog()', common.noWarnCode],
|
||||||
['No such label \'noLabel\' for console.timeEnd()', common.noWarnCode],
|
['No such label \'noLabel\' for console.timeEnd()', common.noWarnCode],
|
||||||
|
['Count for \'default\' does not exist', common.noWarnCode],
|
||||||
|
['No such label \'default\' for console.timeLog()', common.noWarnCode],
|
||||||
|
['No such label \'default\' for console.timeEnd()', common.noWarnCode],
|
||||||
|
['Label \'default\' already exists for console.time()', common.noWarnCode],
|
||||||
['Label \'test\' already exists for console.time()', common.noWarnCode]
|
['Label \'test\' already exists for console.time()', common.noWarnCode]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -56,6 +60,17 @@ console.timeEnd('noLabel');
|
|||||||
console.time('label');
|
console.time('label');
|
||||||
console.timeEnd('label');
|
console.timeEnd('label');
|
||||||
|
|
||||||
|
// Test using the default label
|
||||||
|
// on console.time(), console.countReset(), console.timeLog(), console.timeEnd()
|
||||||
|
console.countReset();
|
||||||
|
console.timeLog();
|
||||||
|
console.timeEnd();
|
||||||
|
|
||||||
|
console.time();
|
||||||
|
console.time();
|
||||||
|
console.timeLog();
|
||||||
|
console.timeEnd();
|
||||||
|
|
||||||
// Check that the `Error` is a `TypeError` but do not check the message as it
|
// Check that the `Error` is a `TypeError` but do not check the message as it
|
||||||
// will be different in different JavaScript engines.
|
// will be different in different JavaScript engines.
|
||||||
assert.throws(() => console.time(Symbol('test')),
|
assert.throws(() => console.time(Symbol('test')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user