setMaxListeners should initialize _events

This commit is contained in:
Ryan Dahl 2011-03-07 13:16:00 -08:00
parent 7a272d92e3
commit 81d3de7e6d
2 changed files with 7 additions and 0 deletions

View File

@ -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;
};

View File

@ -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);