-
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: allow Object.prototype fields as labels #563
Conversation
LGTM! |
|
||
// Verify that Object.prototype properties can be used as labels | ||
assert.doesNotThrow(function () { | ||
console.time('__proto__'); |
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.
did this actually 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.
No. It returns NaN
like I noted in the commit log :-/. Will update the test.
@vkurchatkin updated the test. PTAL |
LGTM |
if (!time) { | ||
throw new Error('No such label: ' + label); | ||
} | ||
var duration = Date.now() - time; | ||
let duration = Date.now() - time; |
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.
I'm generally -0 on replacing var
with let
unless there's a distinct need for block-scoping.
Edit: This is a non-blocking nit. It would make me feel better if these remained var
s, though.
@chrisdickinson changed the |
I'll just leave it here: http://www.reddit.com/r/javascript/comments/1sgsmj/let_var_die/ |
If we are going to switch, I think it most reasonable to only change lines that we are already editing. |
@vkurchatkin I'm in the camp of being as restrictive as possible, which I think |
The test should still fail for console._times = Object.create(null);
console.time('__proto__'); // => console._times.__proto__ = Date.now();
console.timeEnd('__proto__'); // throws
console._times.__proto__ === null; // true |
@pluma seems to work fine with the latest iojs code. |
@cjihrig Interesting. Is this related to the newer version of V8 being used? |
@pluma that would be my guess - I see the same behavior in the Chrome console. |
Hm, odd. I guess the semantics of |
Is anyone opposed to this landing? Another alternative would be to use a |
+1 for landing, and also +1 for experimenting with |
Console.prototype.timeEnd() returns NaN if the timer label corresponds to a property on Object.prototype. This commit uses a Map to construct the _times object.
@rvagg updated to use a |
love it! |
@@ -21,7 +21,7 @@ function Console(stdout, stderr) { | |||
Object.defineProperty(this, '_stdout', prop); | |||
prop.value = stderr; | |||
Object.defineProperty(this, '_stderr', prop); | |||
prop.value = {}; |
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.
It might be better (perf-wise) to just replace this with { __proto__: null }
or Object.create(null)
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.
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.
fair enough, try it out
Console.prototype.timeEnd() returns NaN if the timer label corresponds to a property on Object.prototype. This commit uses a Map to construct the _times object. Fixes: nodejs/node-v0.x-archive#9069 PR-URL: #563 Reviewed-By: Vladimir Kurchatkin <[email protected]> Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
Landed in 3cbb5cd |
Console.prototype.timeEnd()
returnsNaN
if the timer label corresponds to a property onObject.prototype
. This commit usesObject.create(null)
to construct the_times
object. See nodejs/node-v0.x-archive#9069