-
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
events: prefix events to prevent breaking on known object properties #728
Comments
We just solved a similar problem with console timer labels. We ended up going with a |
Sounds like a spot to use |
I don't think that the performance of Map and Weakmap are better than |
According to this micro-benchmark (yep) you could expect map to be twice as slow: http://jsperf.com/map-vs-object-as-hashes/14 Hash access may well not be the/a performance bottleneck in events though. |
@meandmycode You are comparing linear array to hash map.. you need to either use string keys or very sparse numeric indices to force the object into a dictionary mode. Secondly the comparison is not fair unless you also factor in the cost of checking if a key is So when using an object as a true string hash map (arbitrary string is supported, including proto) vs using Map, the speed is not surprisingly very much equal http://jsperf.com/map-vs-object-as-hashes/24 |
One thing to note is that the current version of v8 hasn't required explicit checking for |
Also, @bnoordhuis just pointed out on another issue that |
I opened pull request to add a test for this to |
This commit adds tests for several known issues. Refs: nodejs#1901 Refs: nodejs#728 Refs: nodejs#4778 Refs: nodejs#947 Refs: nodejs#2734 PR-URL: nodejs#5653 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit safely allows event names that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Fixes: nodejs#728 PR-URL: nodejs#6092 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit safely allows event names that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Fixes: nodejs#728 PR-URL: nodejs#6092 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
In the EventEmitter the events are stored in an plain
Object
instance. The event names that you use are added directly as property on the object so when you event names such as__proto__
it will break. One solution is to prefix the keys with a char such as~
.Example case:
Willing to create pull request if bug requires fixing ;)
The text was updated successfully, but these errors were encountered: