Permalink
Browse files

setMaxListeners should initialize _events

  • Loading branch information...
1 parent 7a272d9 commit 81d3de7e6db6abe36ac907d8f0fa6dfc01f7bbcd @ry ry committed Mar 7, 2011
Showing with 7 additions and 0 deletions.
  1. +1 −0 lib/events.js
  2. +6 −0 test/simple/test-event-emitter-add-listeners.js
View
@@ -9,6 +9,7 @@ var isArray = Array.isArray;
// that to be increased. Set to zero for unlimited.
var defaultMaxListeners = 10;
EventEmitter.prototype.setMaxListeners = function(n) {
+ if (!this._events) this._events = {};
this._events.maxListeners = n;
};
@@ -23,6 +23,12 @@ console.log('start');
e.emit('hello', 'a', 'b');
+
+// just make sure that this doesn't throw:
+var f = new events.EventEmitter();
+f.setMaxListeners(0);
+
+
process.addListener('exit', function() {
assert.deepEqual(['hello'], events_new_listener_emited);
assert.equal(1, times_hello_emited);

0 comments on commit 81d3de7

Please sign in to comment.