Fix #3425: removeAllListeners should delete array #3431

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

reid commented Jun 13, 2012

When removeAllListeners is called, the listeners array is deleted to maintain compatibility with v0.6.

This request fixes issue #3425 by reverting 78dc13f. In addition to the revert, I've updated the tests to match the reverted behavior.

@reid reid Fix #3425: removeAllListeners should delete array
When removeAllListeners is called, the listeners array
is deleted to maintain compatibility with v0.6.

Reverts "events: don't delete the listeners array"

This reverts commit 78dc13f.

Conflicts:

	test/simple/test-event-emitter-remove-all-listeners.js
2fd00b8

See joyent#3425 (comment) for my alternate proposal for a solution.

reid commented Jun 13, 2012

@isaacs This needs an API doc clarification, but I haven't yet come up with something that doesn't refer to EventEmitter's internals.

@reid reid commented on the diff Jun 13, 2012

lib/events.js
@@ -228,15 +228,8 @@ EventEmitter.prototype.removeAllListeners = function(type) {
return this;
}
- var events = this._events && this._events[type];
- if (!events) return this;
-
- if (isArray(events)) {
- events.splice(0);
- } else {
- this._events[type] = null;
- }
-
+ // does not use listeners(), so no side effect of creating _events[type]
@reid

reid Jun 13, 2012

@TooTallNate The reverted behavior explicitly tries to avoid calling listeners() to avoid creating _events[type]. Is that still needed?. Regarding your proposal in joyent#3425 (comment)

@TooTallNate

TooTallNate Jun 13, 2012

I personally think that's overkill. I don't consider removeAllListeners() to be a hot code path enough to justify that, but others would need to weigh in on that as well.

isaacs commented Jun 15, 2012

Landed, along with an alternate fix for the thing that this was fixing, and clarification in the docs. Thanks, everyone :)

isaacs closed this Jun 15, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment