-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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: _events should be an own property #2046
Conversation
2c6b424 fixed this problem for the case where EventEmitter constructor is invoked. If is not, shared _events were still used. This commit ensures that listeners are added only to own _events. See: nodejs/node-v0.x-archive#7405
@@ -20,6 +20,17 @@ EventEmitter.prototype._maxListeners = undefined; | |||
// added to it. This is a useful default which helps finding memory leaks. | |||
EventEmitter.defaultMaxListeners = 10; | |||
|
|||
function ensureEvents(emitter) { |
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.
ensureXxx
function should not have a side-effect (no modified state).
I feel initializeXxx
is better or remove side-effects like:
function ensureEvents(emitter) {
if (!emitter._events ||
emitter._events === Object.getPrototypeOf(emitter)._events) {
return false;
}
return true;
}
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.
Disagree. ensure
implies idempotency, nothing more
LGTM but maybe you can add a regression test for the two-level inheritance I described here? |
Not sure about this. If it is incorrect, why should we support it? It isn't supported in any other inheritable node class and just leads to lots of annoying legacy code. |
@vkurchatkin ... is this still something you'd like to pursue? |
@jasnell actually, no, I don't think it's a good idea anymore |
Thanks @vkurchatkin ! |
Fixes #2044
R=@mscdex, @bnoordhuis