-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
Per the console spec, the label in console.time() is a string.
Per the console spec, the default value of label is `'default'`.
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.
1 nit
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply String(label)
?
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.
@refack I guess it's because String(Symbol('s'))
does not throw.
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 a weird language 😖
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.
Found the piece I was missing, the console
IDL - https://console.spec.whatwg.org/#console-namespace
@jasnell could you find a suitable place to reference that in the code?
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.
Yep, IDL rules are weird. Before ES6 you could also use label + ''
but not anymore due to some @@toPrimitive
semantics that wouldn't work with Dates.
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.
Maybe we can write a line of comment to explain this? Or maybe next time who see it will be confused again.
@@ -139,12 +139,14 @@ Console.prototype.dir = function dir(object, options) { | |||
}; | |||
|
|||
|
|||
Console.prototype.time = function time(label) { | |||
Console.prototype.time = function time(label = 'default') { |
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 compliance method.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) consider semver-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
.
@@ -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 comment
The 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.
@@ -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}`; | |||
this._times.set(label, process.hrtime()); |
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.
Personally, I would just use the template literal in this line and spare the assignment above.
Per the console spec, the label in console.time() is a string. Per the console spec, the default value of label is `'default'`. PR-URL: #14643 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in 4da8b99 |
Added assertions to verify that console.time() coerces labels to strings correctly, by comparing against the expected output values of console.timeEnd(). This helps resolve nodejs#14544 but will not address the whole thing. Refs: nodejs#14643
Added assertions to verify that console.time() coerces labels to strings correctly, by comparing against the expected output values of console.timeEnd(). This helps resolve #14544 but will not address the whole thing. PR-URL: #17368 Refs: #14643 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Added assertions to verify that console.time() coerces labels to strings correctly, by comparing against the expected output values of console.timeEnd(). This helps resolve #14544 but will not address the whole thing. PR-URL: #17368 Refs: #14643 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Added assertions to verify that console.time() coerces labels to strings correctly, by comparing against the expected output values of console.timeEnd(). This helps resolve #14544 but will not address the whole thing. PR-URL: #17368 Refs: #14643 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Per the console spec, the label in console.time() is a string. Change is made for consistency with browser behavior.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
console