2011-12-06 20:59:25 +00:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2012-02-20 12:22:12 +00:00
|
|
|
var common = require('../common');
|
2011-05-12 06:18:21 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
var events = require('events');
|
|
|
|
|
|
|
|
var e = new events.EventEmitter();
|
|
|
|
|
|
|
|
// default
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
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);
|
|
|
|
for (var i = 0; i < 5; i++) {
|
|
|
|
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);
|
|
|
|
for (var i = 0; i < 1000; i++) {
|
|
|
|
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
|
|
|
|