Uh oh!
There was an error while loading. Please reload this page.
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'`.
| Console.prototype.time = function time(label) { | ||
| Console.prototype.time = function time(label = 'default') { | ||
| label = `${label}`; |
There was a problem hiding this comment.
@refack I guess it's because String(Symbol('s')) does not throw.
There was a problem hiding this comment.
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.
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.
Maybe we can write a line of comment to explain this? Or maybe next time who see it will be confused again.
| Console.prototype.time = function time(label) { | ||
| Console.prototype.time = function time(label = 'default') { |
There was a problem hiding this comment.
This is okay because of the method binding in L62?
There was a problem hiding this comment.
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.
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.
FWIW I do think this is semver-major, but because of the default change not .length.
| Console.prototype.time = function time(label) { | ||
| Console.prototype.time = function time(label = 'default') { | ||
| label = `${label}`; |
There was a problem hiding this comment.
Maybe we can write a line of comment to explain this? Or maybe next time who see it will be confused again.
| 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.
Personally, I would just use the template literal in this line and spare the assignment above.
jasnell
commented
Aug 8, 2017
jasnell
commented
Aug 8, 2017
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>
jasnell
commented
Aug 8, 2017
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 resolvenodejs#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