2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2015-12-24 00:02:12 +00:00
|
|
|
require('../common');
|
2011-05-12 06:18:21 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
var events = require('events');
|
|
|
|
|
|
|
|
var e = new events.EventEmitter();
|
|
|
|
|
|
|
|
// default
|
2016-01-31 04:16:14 +00:00
|
|
|
for (let i = 0; i < 10; i++) {
|
2011-05-12 06:18:21 +00:00
|
|
|
e.on('default', function() {});
|
|
|
|
}
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(!e._events['default'].hasOwnProperty('warned'));
|
2011-05-12 06:18:21 +00:00
|
|
|
e.on('default', function() {});
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(e._events['default'].warned);
|
2011-05-12 06:18:21 +00:00
|
|
|
|
|
|
|
// specific
|
|
|
|
e.setMaxListeners(5);
|
2016-01-31 04:16:14 +00:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2011-05-12 06:18:21 +00:00
|
|
|
e.on('specific', function() {});
|
|
|
|
}
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
|
2011-05-12 06:18:21 +00:00
|
|
|
e.on('specific', function() {});
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(e._events['specific'].warned);
|
2011-05-12 06:18:21 +00:00
|
|
|
|
2012-01-08 15:53:17 +00:00
|
|
|
// only one
|
|
|
|
e.setMaxListeners(1);
|
|
|
|
e.on('only one', function() {});
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
|
2012-01-08 15:53:17 +00:00
|
|
|
e.on('only one', function() {});
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(e._events['only one'].hasOwnProperty('warned'));
|
2012-01-08 15:53:17 +00:00
|
|
|
|
2011-05-12 06:18:21 +00:00
|
|
|
// unlimited
|
|
|
|
e.setMaxListeners(0);
|
2016-01-31 04:16:14 +00:00
|
|
|
for (let i = 0; i < 1000; i++) {
|
2011-05-12 06:18:21 +00:00
|
|
|
e.on('unlimited', function() {});
|
|
|
|
}
|
2013-01-17 21:20:22 +00:00
|
|
|
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
|
2011-05-12 06:18:21 +00:00
|
|
|
|
2012-05-04 15:45:27 +00:00
|
|
|
// process-wide
|
|
|
|
events.EventEmitter.defaultMaxListeners = 42;
|
|
|
|
e = new events.EventEmitter();
|
|
|
|
|
2016-01-31 04:16:14 +00:00
|
|
|
for (let i = 0; i < 42; ++i) {
|
2012-05-04 15:45:27 +00:00
|
|
|
e.on('fortytwo', function() {});
|
|
|
|
}
|
|
|
|
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
|
|
e.on('fortytwo', function() {});
|
|
|
|
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
|
|
delete e._events['fortytwo'].warned;
|
|
|
|
|
|
|
|
events.EventEmitter.defaultMaxListeners = 44;
|
|
|
|
e.on('fortytwo', function() {});
|
|
|
|
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
|
|
e.on('fortytwo', function() {});
|
|
|
|
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
|
|
|
|
|
|
// but _maxListeners still has precedence over defaultMaxListeners
|
|
|
|
events.EventEmitter.defaultMaxListeners = 42;
|
|
|
|
e = new events.EventEmitter();
|
|
|
|
e.setMaxListeners(1);
|
|
|
|
e.on('uno', function() {});
|
|
|
|
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
|
|
|
|
e.on('uno', function() {});
|
|
|
|
assert.ok(e._events['uno'].hasOwnProperty('warned'));
|
2013-05-02 23:38:16 +00:00
|
|
|
|
|
|
|
// chainable
|
|
|
|
assert.strictEqual(e, e.setMaxListeners(1));
|