react / wstein / node_modules / browserify / node_modules / events / tests / check-listener-leaks.js
80529 views// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.2021var assert = require('assert');22var events = require('../');2324var e = new events.EventEmitter();2526// default27for (var i = 0; i < 10; i++) {28e.on('default', function() {});29}30assert.ok(!e._events['default'].hasOwnProperty('warned'));31e.on('default', function() {});32assert.ok(e._events['default'].warned);3334// specific35e.setMaxListeners(5);36for (var i = 0; i < 5; i++) {37e.on('specific', function() {});38}39assert.ok(!e._events['specific'].hasOwnProperty('warned'));40e.on('specific', function() {});41assert.ok(e._events['specific'].warned);4243// only one44e.setMaxListeners(1);45e.on('only one', function() {});46assert.ok(!e._events['only one'].hasOwnProperty('warned'));47e.on('only one', function() {});48assert.ok(e._events['only one'].hasOwnProperty('warned'));4950// unlimited51e.setMaxListeners(0);52for (var i = 0; i < 1000; i++) {53e.on('unlimited', function() {});54}55assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));5657// process-wide58events.EventEmitter.defaultMaxListeners = 42;59e = new events.EventEmitter();6061for (var i = 0; i < 42; ++i) {62e.on('fortytwo', function() {});63}64assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));65e.on('fortytwo', function() {});66assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));67delete e._events['fortytwo'].warned;6869events.EventEmitter.defaultMaxListeners = 44;70e.on('fortytwo', function() {});71assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));72e.on('fortytwo', function() {});73assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));7475// but _maxListeners still has precedence over defaultMaxListeners76events.EventEmitter.defaultMaxListeners = 42;77e = new events.EventEmitter();78e.setMaxListeners(1);79e.on('uno', function() {});80assert.ok(!e._events['uno'].hasOwnProperty('warned'));81e.on('uno', function() {});82assert.ok(e._events['uno'].hasOwnProperty('warned'));8384// chainable85assert.strictEqual(e, e.setMaxListeners(1));868788