Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
setMaxListeners should initialize _events
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Mar 7, 2011
1 parent 7a272d9 commit 81d3de7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/events.js
Expand Up @@ -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;
};

Expand Down
6 changes: 6 additions & 0 deletions test/simple/test-event-emitter-add-listeners.js
Expand Up @@ -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);
Expand Down

0 comments on commit 81d3de7

Please sign in to comment.