Permalink
Browse files

events: don't delete the listeners array in removeListener()

  • Loading branch information...
1 parent 761a82b commit 928ea564d16da47e615ddac627e0b4d4a40d8196 @TooTallNate TooTallNate committed Mar 15, 2012
Showing with 9 additions and 2 deletions.
  1. +0 −2 lib/events.js
  2. +9 −0 test/simple/test-event-emitter-remove-listeners.js
View
@@ -186,8 +186,6 @@ EventEmitter.prototype.removeListener = function(type, listener) {
if (position < 0) return this;
list.splice(position, 1);
- if (list.length == 0)
- delete this._events[type];
} else if (list === listener ||
(list.listener && list.listener === listener))
{
@@ -42,10 +42,15 @@ function listener3() {
}
var e1 = new events.EventEmitter();
+var e1listeners = e1.listeners('hello');
e1.on('hello', listener1);
+assert.equal(e1listeners.length, 1);
e1.removeListener('hello', listener1);
assert.deepEqual([], e1.listeners('hello'));
+// identity check, listeners array should be the same
+assert.equal(e1listeners, e1.listeners('hello'));
+
var e2 = new events.EventEmitter();
e2.on('hello', listener1);
e2.removeListener('hello', listener2);
@@ -54,8 +59,12 @@ assert.deepEqual([listener1], e2.listeners('hello'));
var e3 = new events.EventEmitter();
e3.on('hello', listener1);
e3.on('hello', listener2);
+var e3listeners = e3.listeners('hello');
+assert.equal(e3listeners.length, 2)
e3.removeListener('hello', listener1);
+assert.equal(e3listeners.length, 1)
assert.deepEqual([listener2], e3.listeners('hello'));
+assert.equal(e3listeners, e3.listeners('hello'));

0 comments on commit 928ea56

Please sign in to comment.