Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,22 @@ Console.prototype.time = function time(label = 'default') {
};

Console.prototype.timeEnd = function timeEnd(label = 'default') {
// Coerces everything other than Symbol to a string
label = `${label}`;
const hasWarned = timeLogImpl(this, 'timeEnd', label);
if (!hasWarned) {
this._times.delete(label);
}
};

Console.prototype.timeLog = function timeLog(label, ...data) {
// Coerces everything other than Symbol to a string
label = `${label}`;
timeLogImpl(this, 'timeLog', label, data);
};

// Returns true if label was not found
function timeLogImpl(self, name, label = 'default', data) {
// Coerces everything other than Symbol to a string
label = `${label}`;
const time = self._times.get(label);
if (!time) {
process.emitWarning(`No such label '${label}' for console.${name}()`);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ console.timeEnd('constructor');
console.time('hasOwnProperty');
console.timeEnd('hasOwnProperty');

// verify that values are coerced to strings
// Verify that values are coerced to strings.
console.time([]);
console.timeEnd([]);
console.time({});
console.timeEnd({});
// Repeat the object call to verify that everything really worked.
console.time({});
console.timeEnd({});
console.time(null);
console.timeEnd(null);
console.time(undefined);
Expand Down