-
Notifications
You must be signed in to change notification settings - Fork 7.3k
console.timeEnd('hasOwnProperty') fails hilariously #9069
Comments
Does changing the line at https://github.com/joyent/node/blob/master/lib/console.js#L43 to |
Nope, because even var x = Object.create(null);
x.__proto__ = 'lol';
console.log(x.__proto__); // null |
Sure, but at most, all you'll get is |
Yes, that should work with that caveat. |
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]>
I have verified that this can be solved with |
Indeed. The |
Console.prototype.timeEnd() returns NaN if the timer label corresponds to a property on Object.prototype. This commit uses Object.create(null) to construct the _times object. Fixes: #9069 PR-URL: #9116 Reviewed-By: Trevor Norris <[email protected]>
Fixed in 6c3647c |
@cjihrig Do we want to leave this issue open, or open another issue to fix this in v0.10? |
@misterdjules I don't think there is a really clean fix for 0.10. I would say either leave as is with the existing few edge cases, or apply this patch, which would leave |
@cjihrig We could use a different data structure for I have never used What do you think? |
@misterdjules I think that solution would work. The slight performance hit should be fine since it's a console operation. However, a similar problem exists with event names, and I wouldn't recommend this approach in that code. I would move the |
Fixed in v0.10 by c8239c0. |
Because the timers are currently stored as named properties of an object, timers with funny labels will result in
console.timeEnd
dutifully loggingNaNms
.This affects
hasOwnProperty
,__proto__
and likely anything else that lives onObject.prototype
.A solution would be using ES6 symbols when they land in node.
A workaround would be prefixing the property names with some arbitrary string (except
_
, which would re-create the problem for timers labelled_proto__
) instead of using the label verbatim.The text was updated successfully, but these errors were encountered: