// 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();2526var events_new_listener_emited = [];27var listeners_new_listener_emited = [];28var times_hello_emited = 0;2930// sanity check31assert.equal(e.addListener, e.on);3233e.on('newListener', function(event, listener) {34console.log('newListener: ' + event);35events_new_listener_emited.push(event);36listeners_new_listener_emited.push(listener);37});3839function hello(a, b) {40console.log('hello');41times_hello_emited += 1;42assert.equal('a', a);43assert.equal('b', b);44}45e.on('hello', hello);4647var foo = function() {};48e.once('foo', foo);4950console.log('start');5152e.emit('hello', 'a', 'b');535455// just make sure that this doesn't throw:56var f = new events.EventEmitter();57f.setMaxListeners(0);5859assert.deepEqual(['hello', 'foo'], events_new_listener_emited);60assert.deepEqual([hello, foo], listeners_new_listener_emited);61assert.equal(1, times_hello_emited);62636465