Skip to content

Commit a2c13fa

Browse files
meelieBridgeAR
authored andcommitted
console: console.timeLog() using the default label
PR-URL: #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>
1 parent 7601cdf commit a2c13fa

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/console.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ Console.prototype.timeEnd = function timeEnd(label = 'default') {
253253
}
254254
};
255255

256-
Console.prototype.timeLog = function timeLog(label, ...data) {
256+
Console.prototype.timeLog = function timeLog(label = 'default', ...data) {
257257
// Coerces everything other than Symbol to a string
258258
label = `${label}`;
259259
timeLogImpl(this, 'timeLog', label, data);
260260
trace(kTraceInstant, kTraceConsoleCategory, `time::${label}`, 0);
261261
};
262262

263263
// Returns true if label was not found
264-
function timeLogImpl(self, name, label = 'default', data) {
264+
function timeLogImpl(self, name, label, data) {
265265
const time = self._times.get(label);
266266
if (!time) {
267267
process.emitWarning(`No such label '${label}' for console.${name}()`);

test/parallel/test-console.js

+15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ common.expectWarning(
4545
['Count for \'noLabel\' does not exist', common.noWarnCode],
4646
['No such label \'noLabel\' for console.timeLog()', common.noWarnCode],
4747
['No such label \'noLabel\' for console.timeEnd()', common.noWarnCode],
48+
['Count for \'default\' does not exist', common.noWarnCode],
49+
['No such label \'default\' for console.timeLog()', common.noWarnCode],
50+
['No such label \'default\' for console.timeEnd()', common.noWarnCode],
51+
['Label \'default\' already exists for console.time()', common.noWarnCode],
4852
['Label \'test\' already exists for console.time()', common.noWarnCode]
4953
]
5054
);
@@ -56,6 +60,17 @@ console.timeEnd('noLabel');
5660
console.time('label');
5761
console.timeEnd('label');
5862

63+
// Test using the default label
64+
// on console.time(), console.countReset(), console.timeLog(), console.timeEnd()
65+
console.countReset();
66+
console.timeLog();
67+
console.timeEnd();
68+
69+
console.time();
70+
console.time();
71+
console.timeLog();
72+
console.timeEnd();
73+
5974
// Check that the `Error` is a `TypeError` but do not check the message as it
6075
// will be different in different JavaScript engines.
6176
assert.throws(() => console.time(Symbol('test')),

0 commit comments

Comments
 (0)