Skip to content

Commit

Permalink
console: console.timeLog() using the default label
Browse files Browse the repository at this point in the history
PR-URL: #24286
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
meelie authored and BridgeAR committed Nov 13, 2018
1 parent 7601cdf commit a2c13fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ 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
label = `${label}`;
timeLogImpl(this, 'timeLog', label, data);
trace(kTraceInstant, kTraceConsoleCategory, `time::${label}`, 0);
};

// 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);
if (!time) {
process.emitWarning(`No such label '${label}' for console.${name}()`);
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ common.expectWarning(
['Count for \'noLabel\' does not exist', common.noWarnCode],
['No such label \'noLabel\' for console.timeLog()', 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]
]
);
Expand All @@ -56,6 +60,17 @@ console.timeEnd('noLabel');
console.time('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
// will be different in different JavaScript engines.
assert.throws(() => console.time(Symbol('test')),
Expand Down

0 comments on commit a2c13fa

Please sign in to comment.