pax_global_header00006660000000000000000000000064123777757760014546gustar00rootroot0000000000000052 comment=82020ee4e10570370b342863887fdc73e723ca7a events-1.0.2/000077500000000000000000000000001237777577600130525ustar00rootroot00000000000000events-1.0.2/.gitignore000066400000000000000000000000151237777577600150360ustar00rootroot00000000000000node_modules events-1.0.2/.travis.yml000066400000000000000000000006451237777577600151700ustar00rootroot00000000000000language: node_js node_js: - '0.10' env: global: - secure: XcBiD8yReflut9q7leKsigDZ0mI3qTKH+QrNVY8DaqlomJOZw8aOrVuX9Jz12l86ZJ41nbxmKnRNkFzcVr9mbP9YaeTb3DpeOBWmvaoSfud9Wnc16VfXtc1FCcwDhSVcSiM3UtnrmFU5cH+Dw1LPh5PbfylYOS/nJxUvG0FFLqI= - secure: jNWtEbqhUdQ0xXDHvCYfUbKYeJCi6a7B4LsrcxYCyWWn4NIgncE5x2YbB+FSUUFVYfz0dsn5RKP1oHB99f0laUEo18HBNkrAS/rtyOdVzcpJjbQ6kgSILGjnJD/Ty1B57Rcz3iyev5Y7bLZ6Y1FbDnk/i9/l0faOGz8vTC3Vdkc= events-1.0.2/.zuul.yml000066400000000000000000000003521237777577600146520ustar00rootroot00000000000000ui: mocha-qunit browsers: - name: chrome version: latest - name: firefox version: latest - name: safari version: 5..latest - name: iphone version: latest - name: ie version: 8..latest events-1.0.2/History.md000066400000000000000000000011271237777577600150360ustar00rootroot00000000000000# 1.0.2 (2014-08-28) - remove un-reachable code - update devDeps ## 1.0.1 / 2014-05-11 - check for console.trace before using it ## 1.0.0 / 2013-12-10 - Update to latest events code from node.js 0.10 - copy tests from node.js ## 0.4.0 / 2011-07-03 ## - Switching to graphquire@0.8.0 ## 0.3.0 / 2011-07-03 ## - Switching to URL based module require. ## 0.2.0 / 2011-06-10 ## - Simplified package structure. - Graphquire for dependency management. ## 0.1.1 / 2011-05-16 ## - Unhandled errors are logged via console.error ## 0.1.0 / 2011-04-22 ## - Initial release events-1.0.2/LICENSE000066400000000000000000000020711237777577600140570ustar00rootroot00000000000000MIT 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. events-1.0.2/Readme.md000066400000000000000000000005631237777577600145750ustar00rootroot00000000000000# events [![Build Status](https://travis-ci.org/Gozala/events.png?branch=master)](https://travis-ci.org/Gozala/events) Node's event emitter for all engines. ## Install ## ``` npm install events ``` ## Require ## ```javascript var EventEmitter = require('events').EventEmitter ``` ## Usage ## See the [node.js event emitter docs](http://nodejs.org/api/events.html) events-1.0.2/events.js000066400000000000000000000200731237777577600147160ustar00rootroot00000000000000// 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. function EventEmitter() { this._events = this._events || {}; this._maxListeners = this._maxListeners || undefined; } module.exports = EventEmitter; // Backwards-compat with node 0.10.x EventEmitter.EventEmitter = EventEmitter; EventEmitter.prototype._events = undefined; EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are // added to it. This is a useful default which helps finding memory leaks. EventEmitter.defaultMaxListeners = 10; // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. EventEmitter.prototype.setMaxListeners = function(n) { if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number'); this._maxListeners = n; return this; }; EventEmitter.prototype.emit = function(type) { var er, handler, len, args, i, listeners; if (!this._events) this._events = {}; // If there is no 'error' event listener then throw. if (type === 'error') { if (!this._events.error || (isObject(this._events.error) && !this._events.error.length)) { er = arguments[1]; if (er instanceof Error) { throw er; // Unhandled 'error' event } throw TypeError('Uncaught, unspecified "error" event.'); } } handler = this._events[type]; if (isUndefined(handler)) return false; if (isFunction(handler)) { switch (arguments.length) { // fast cases case 1: handler.call(this); break; case 2: handler.call(this, arguments[1]); break; case 3: handler.call(this, arguments[1], arguments[2]); break; // slower default: len = arguments.length; args = new Array(len - 1); for (i = 1; i < len; i++) args[i - 1] = arguments[i]; handler.apply(this, args); } } else if (isObject(handler)) { len = arguments.length; args = new Array(len - 1); for (i = 1; i < len; i++) args[i - 1] = arguments[i]; listeners = handler.slice(); len = listeners.length; for (i = 0; i < len; i++) listeners[i].apply(this, args); } return true; }; EventEmitter.prototype.addListener = function(type, listener) { var m; if (!isFunction(listener)) throw TypeError('listener must be a function'); if (!this._events) this._events = {}; // To avoid recursion in the case that type === "newListener"! Before // adding it to the listeners, first emit "newListener". if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener); if (!this._events[type]) // Optimize the case of one listener. Don't need the extra array object. this._events[type] = listener; else if (isObject(this._events[type])) // If we've already got an array, just append. this._events[type].push(listener); else // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; // Check for listener leak if (isObject(this._events[type]) && !this._events[type].warned) { var m; if (!isUndefined(this._maxListeners)) { m = this._maxListeners; } else { m = EventEmitter.defaultMaxListeners; } if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); if (typeof console.trace === 'function') { // not supported in IE 10 console.trace(); } } } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { if (!isFunction(listener)) throw TypeError('listener must be a function'); var fired = false; function g() { this.removeListener(type, g); if (!fired) { fired = true; listener.apply(this, arguments); } } g.listener = listener; this.on(type, g); return this; }; // emits a 'removeListener' event iff the listener was removed EventEmitter.prototype.removeListener = function(type, listener) { var list, position, length, i; if (!isFunction(listener)) throw TypeError('listener must be a function'); if (!this._events || !this._events[type]) return this; list = this._events[type]; length = list.length; position = -1; if (list === listener || (isFunction(list.listener) && list.listener === listener)) { delete this._events[type]; if (this._events.removeListener) this.emit('removeListener', type, listener); } else if (isObject(list)) { for (i = length; i-- > 0;) { if (list[i] === listener || (list[i].listener && list[i].listener === listener)) { position = i; break; } } if (position < 0) return this; if (list.length === 1) { list.length = 0; delete this._events[type]; } else { list.splice(position, 1); } if (this._events.removeListener) this.emit('removeListener', type, listener); } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { var key, listeners; if (!this._events) return this; // not listening for removeListener, no need to emit if (!this._events.removeListener) { if (arguments.length === 0) this._events = {}; else if (this._events[type]) delete this._events[type]; return this; } // emit removeListener for all listeners on all events if (arguments.length === 0) { for (key in this._events) { if (key === 'removeListener') continue; this.removeAllListeners(key); } this.removeAllListeners('removeListener'); this._events = {}; return this; } listeners = this._events[type]; if (isFunction(listeners)) { this.removeListener(type, listeners); } else { // LIFO order while (listeners.length) this.removeListener(type, listeners[listeners.length - 1]); } delete this._events[type]; return this; }; EventEmitter.prototype.listeners = function(type) { var ret; if (!this._events || !this._events[type]) ret = []; else if (isFunction(this._events[type])) ret = [this._events[type]]; else ret = this._events[type].slice(); return ret; }; EventEmitter.listenerCount = function(emitter, type) { var ret; if (!emitter._events || !emitter._events[type]) ret = 0; else if (isFunction(emitter._events[type])) ret = 1; else ret = emitter._events[type].length; return ret; }; function isFunction(arg) { return typeof arg === 'function'; } function isNumber(arg) { return typeof arg === 'number'; } function isObject(arg) { return typeof arg === 'object' && arg !== null; } function isUndefined(arg) { return arg === void 0; } events-1.0.2/package.json000066400000000000000000000013651237777577600153450ustar00rootroot00000000000000{ "name": "events", "id": "events", "version": "1.0.2", "description": "Node's event emitter for all engines.", "keywords": [ "events", "eventEmitter", "eventDispatcher", "listeners" ], "author": "Irakli Gozalishvili (http://jeditoolkit.com)", "repository": { "type": "git", "url": "git://github.com/Gozala/events.git", "web": "https://github.com/Gozala/events" }, "bugs": { "url": "http://github.com/Gozala/events/issues/" }, "main": "./events.js", "engines": { "node": ">=0.4.x" }, "devDependencies": { "mocha": "~1.21.4", "zuul": "~1.10.2" }, "scripts": { "test": "mocha --ui qunit -- tests/index.js && zuul -- tests/index.js" }, "licenses": "MIT" }events-1.0.2/tests/000077500000000000000000000000001237777577600142145ustar00rootroot00000000000000events-1.0.2/tests/add-listeners.js000066400000000000000000000040441237777577600173120ustar00rootroot00000000000000// 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. var assert = require('assert'); var events = require('../'); var e = new events.EventEmitter(); var events_new_listener_emited = []; var listeners_new_listener_emited = []; var times_hello_emited = 0; // sanity check assert.equal(e.addListener, e.on); e.on('newListener', function(event, listener) { console.log('newListener: ' + event); events_new_listener_emited.push(event); listeners_new_listener_emited.push(listener); }); function hello(a, b) { console.log('hello'); times_hello_emited += 1; assert.equal('a', a); assert.equal('b', b); } e.on('hello', hello); var foo = function() {}; e.once('foo', foo); console.log('start'); e.emit('hello', 'a', 'b'); // just make sure that this doesn't throw: var f = new events.EventEmitter(); f.setMaxListeners(0); assert.deepEqual(['hello', 'foo'], events_new_listener_emited); assert.deepEqual([hello, foo], listeners_new_listener_emited); assert.equal(1, times_hello_emited); events-1.0.2/tests/check-listener-leaks.js000066400000000000000000000057401237777577600205550ustar00rootroot00000000000000// 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. var assert = require('assert'); var events = require('../'); var e = new events.EventEmitter(); // default for (var i = 0; i < 10; i++) { e.on('default', function() {}); } assert.ok(!e._events['default'].hasOwnProperty('warned')); e.on('default', function() {}); assert.ok(e._events['default'].warned); // specific e.setMaxListeners(5); for (var i = 0; i < 5; i++) { e.on('specific', function() {}); } assert.ok(!e._events['specific'].hasOwnProperty('warned')); e.on('specific', function() {}); assert.ok(e._events['specific'].warned); // only one e.setMaxListeners(1); e.on('only one', function() {}); assert.ok(!e._events['only one'].hasOwnProperty('warned')); e.on('only one', function() {}); assert.ok(e._events['only one'].hasOwnProperty('warned')); // unlimited e.setMaxListeners(0); for (var i = 0; i < 1000; i++) { e.on('unlimited', function() {}); } assert.ok(!e._events['unlimited'].hasOwnProperty('warned')); // process-wide events.EventEmitter.defaultMaxListeners = 42; e = new events.EventEmitter(); for (var i = 0; i < 42; ++i) { 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')); // chainable assert.strictEqual(e, e.setMaxListeners(1)); events-1.0.2/tests/common.js000066400000000000000000000016401237777577600160430ustar00rootroot00000000000000var assert = require('assert'); var mustCallChecks = []; function runCallChecks() { var failed_count = 0; for (var i=0 ; i< mustCallChecks.length; ++i) { var context = mustCallChecks[i]; if (context.actual === context.expected) { continue; } failed_count++; console.log('Mismatched %s function calls. Expected %d, actual %d.', context.name, context.expected, context.actual); console.log(context.stack.split('\n').slice(2).join('\n')); } assert(failed_count === 0); } after(runCallChecks); exports.mustCall = function(fn, expected) { if (typeof expected !== 'number') expected = 1; var context = { expected: expected, actual: 0, stack: (new Error).stack, name: fn.name || '' }; mustCallChecks.push(context); return function() { context.actual++; return fn.apply(this, arguments); }; }; events-1.0.2/tests/index.js000066400000000000000000000012401237777577600156560ustar00rootroot00000000000000 require('./legacy-compat'); // we do this to easily wrap each file in a mocha test // and also have browserify be able to statically analyze this file var orig_require = require; var require = function(file) { test(file, function() { orig_require(file); }); } require('./add-listeners.js'); require('./check-listener-leaks.js'); require('./listeners-side-effects.js'); require('./listeners.js'); require('./max-listeners.js'); require('./modify-in-emit.js'); require('./num-args.js'); require('./once.js'); require('./set-max-listeners-side-effects.js'); require('./subclass.js'); require('./remove-all-listeners.js'); require('./remove-listeners.js'); events-1.0.2/tests/legacy-compat.js000066400000000000000000000005631237777577600173030ustar00rootroot00000000000000// sigh... life is hard if (!global.console) { console = {} } var fns = ['log', 'error', 'trace']; for (var i=0 ; ifoo should not be emitted', '!'); }; e.once('foo', remove); e.removeListener('foo', remove); e.emit('foo'); var times_recurse_emitted = 0; e.once('e', function() { e.emit('e'); times_recurse_emitted++; }); e.once('e', function() { times_recurse_emitted++; }); e.emit('e'); assert.equal(1, times_hello_emited); assert.equal(2, times_recurse_emitted); events-1.0.2/tests/remove-all-listeners.js000066400000000000000000000055301237777577600206260ustar00rootroot00000000000000// 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. var common = require('./common'); var assert = require('assert'); var events = require('../'); var after_checks = []; after(function() { for (var i=0 ; i