-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
console: coerce label to string in console.time() #14643
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
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}`; | ||
|
Contributor
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
Member
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
Contributor
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 😖
Contributor
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
Member
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
Contributor
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()); | ||
|
Member
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
thisvalue. And for the strictest compliancemethod.length === 0because 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
lengthunless it was bound, which some (@jasnell) considersemver-major.It does change
console.__proto__.time.lengtha.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.