Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: fix timeEnd() not coercing the input #21779

Closed
wants to merge 2 commits into from
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
Next Next commit
console: fix timeEnd() not coercing the input
The input of console.timeEnd() was not coerced to a string. That way
labels were not found and the entry was not removed anymore.
  • Loading branch information
BridgeAR committed Jul 12, 2018
commit 452bbfb4b46a3c5db5e91a1866f9283601895d51
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