-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: coerce label to string in console.time() #14643
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,12 +139,14 @@ Console.prototype.dir = function dir(object, options) { | |
}; | ||
|
||
|
||
Console.prototype.time = function time(label) { | ||
Console.prototype.time = function time(label = 'default') { | ||
label = `${label}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @refack I guess it's because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What a weird language 😖 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the piece I was missing, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, IDL rules are weird. Before ES6 you could also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can write a line of comment to explain this? Or maybe next time who see it will be confused again. |
||
this._times.set(label, process.hrtime()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I would just use the template literal in this line and spare the assignment above. |
||
}; | ||
|
||
|
||
Console.prototype.timeEnd = function timeEnd(label) { | ||
Console.prototype.timeEnd = function timeEnd(label = 'default') { | ||
label = `${label}`; | ||
const time = this._times.get(label); | ||
if (!time) { | ||
process.emitWarning(`No such label '${label}' for console.timeEnd()`); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay because of the method binding in L62?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? It only binds the
this
value. And for the strictest compliancemethod.length === 0
because the IDL specifies label as an optional parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have changed the
length
unless it was bound, which some (@jasnell) considersemver-major
.It does change
console.__proto__.time.length
a.k.a.console.Console.prototype.time.length
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I do think this is semver-major, but because of the default change not
.length
.