mirror of https://gitee.com/bigwinds/arangodb
Updated events to 4.1.0
This commit is contained in:
parent
ca793a3f5d
commit
47f691ed36
|
@ -9,7 +9,7 @@ _stream_writable: 0.10.25
|
|||
assert: 0.11.0
|
||||
buffer: 0.11.0 (SlowBuffer)
|
||||
child_process: not supported
|
||||
events: 0.10.25
|
||||
events: 4.1.0
|
||||
http: not supported
|
||||
https: not supported
|
||||
net: compatibility
|
||||
|
|
|
@ -1,163 +1,263 @@
|
|||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
// Copyright Node.js contributors. All rights reserved.
|
||||
//
|
||||
// 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:
|
||||
// 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 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.
|
||||
// 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.
|
||||
|
||||
'use strict';
|
||||
|
||||
var domain;
|
||||
|
||||
exports.usingDomains = false;
|
||||
|
||||
function EventEmitter() {
|
||||
EventEmitter.init.call(this);
|
||||
}
|
||||
module.exports = EventEmitter;
|
||||
|
||||
// Backwards-compat with node 0.10.x
|
||||
EventEmitter.EventEmitter = EventEmitter;
|
||||
|
||||
EventEmitter.usingDomains = false;
|
||||
|
||||
EventEmitter.prototype.domain = undefined;
|
||||
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;
|
||||
|
||||
EventEmitter.init = function() {
|
||||
this.domain = null;
|
||||
if (exports.usingDomains) {
|
||||
if (EventEmitter.usingDomains) {
|
||||
// if there is an active domain, then attach to it.
|
||||
domain = domain || require('domain');
|
||||
if (domain.active && !(this instanceof domain.Domain)) {
|
||||
this.domain = domain.active;
|
||||
}
|
||||
}
|
||||
this._events = this._events || {};
|
||||
this._maxListeners = this._maxListeners || defaultMaxListeners;
|
||||
}
|
||||
exports.EventEmitter = EventEmitter;
|
||||
|
||||
// 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.
|
||||
//
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (typeof n !== 'number' || n < 0 || isNaN(n))
|
||||
throw TypeError('n must be a positive number');
|
||||
this._maxListeners = n;
|
||||
if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
|
||||
this._events = {};
|
||||
this._eventsCount = 0;
|
||||
}
|
||||
|
||||
this._maxListeners = this._maxListeners || undefined;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.emit = function(type) {
|
||||
var er, handler, len, args, i, listeners;
|
||||
// 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 setMaxListeners(n) {
|
||||
if (typeof n !== 'number' || n < 0 || isNaN(n))
|
||||
throw new TypeError('n must be a positive number');
|
||||
this._maxListeners = n;
|
||||
return this;
|
||||
};
|
||||
|
||||
if (!this._events)
|
||||
this._events = {};
|
||||
function $getMaxListeners(that) {
|
||||
if (that._maxListeners === undefined)
|
||||
return EventEmitter.defaultMaxListeners;
|
||||
return that._maxListeners;
|
||||
}
|
||||
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events.error ||
|
||||
(typeof this._events.error === 'object' &&
|
||||
!this._events.error.length)) {
|
||||
er = arguments[1];
|
||||
if (this.domain) {
|
||||
if (!er) er = new TypeError('Uncaught, unspecified "error" event.');
|
||||
er.domainEmitter = this;
|
||||
er.domain = this.domain;
|
||||
er.domainThrown = false;
|
||||
this.domain.emit('error', er);
|
||||
} else if (er instanceof Error) {
|
||||
throw er; // Unhandled 'error' event
|
||||
} else {
|
||||
throw TypeError('Uncaught, unspecified "error" event.');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
||||
return $getMaxListeners(this);
|
||||
};
|
||||
|
||||
// These standalone emit* functions are used to optimize calling of event
|
||||
// handlers for fast cases because emit() itself often has a variable number of
|
||||
// arguments and can be deoptimized because of that. These functions always have
|
||||
// the same number of arguments and thus do not get deoptimized, so the code
|
||||
// inside them can execute faster.
|
||||
function emitNone(handler, isFn, self) {
|
||||
if (isFn)
|
||||
handler.call(self);
|
||||
else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
listeners[i].call(self);
|
||||
}
|
||||
}
|
||||
function emitOne(handler, isFn, self, arg1) {
|
||||
if (isFn)
|
||||
handler.call(self, arg1);
|
||||
else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
listeners[i].call(self, arg1);
|
||||
}
|
||||
}
|
||||
function emitTwo(handler, isFn, self, arg1, arg2) {
|
||||
if (isFn)
|
||||
handler.call(self, arg1, arg2);
|
||||
else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
listeners[i].call(self, arg1, arg2);
|
||||
}
|
||||
}
|
||||
function emitThree(handler, isFn, self, arg1, arg2, arg3) {
|
||||
if (isFn)
|
||||
handler.call(self, arg1, arg2, arg3);
|
||||
else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
listeners[i].call(self, arg1, arg2, arg3);
|
||||
}
|
||||
}
|
||||
|
||||
handler = this._events[type];
|
||||
function emitMany(handler, isFn, self, args) {
|
||||
if (isFn)
|
||||
handler.apply(self, args);
|
||||
else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
listeners[i].apply(self, args);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof handler === 'undefined')
|
||||
EventEmitter.prototype.emit = function emit(type) {
|
||||
var er, handler, len, args, i, events, domain;
|
||||
var needDomainExit = false;
|
||||
var doError = (type === 'error');
|
||||
|
||||
events = this._events;
|
||||
if (events)
|
||||
doError = (doError && events.error == null);
|
||||
else if (!doError)
|
||||
return false;
|
||||
|
||||
if (this.domain && this !== process)
|
||||
this.domain.enter();
|
||||
domain = this.domain;
|
||||
|
||||
if (typeof handler === 'function') {
|
||||
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);
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (doError) {
|
||||
er = arguments[1];
|
||||
if (domain) {
|
||||
if (!er)
|
||||
er = new Error('Uncaught, unspecified "error" event.');
|
||||
er.domainEmitter = this;
|
||||
er.domain = domain;
|
||||
er.domainThrown = false;
|
||||
domain.emit('error', er);
|
||||
} else if (er instanceof Error) {
|
||||
throw er; // Unhandled 'error' event
|
||||
} else {
|
||||
// At least give some kind of context to the user
|
||||
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
|
||||
err.context = er;
|
||||
throw err;
|
||||
}
|
||||
} else if (typeof handler === 'object') {
|
||||
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 false;
|
||||
}
|
||||
|
||||
if (this.domain && this !== process)
|
||||
this.domain.exit();
|
||||
handler = events[type];
|
||||
|
||||
if (!handler)
|
||||
return false;
|
||||
|
||||
if (domain && this !== process) {
|
||||
domain.enter();
|
||||
needDomainExit = true;
|
||||
}
|
||||
|
||||
var isFn = typeof handler === 'function';
|
||||
len = arguments.length;
|
||||
switch (len) {
|
||||
// fast cases
|
||||
case 1:
|
||||
emitNone(handler, isFn, this);
|
||||
break;
|
||||
case 2:
|
||||
emitOne(handler, isFn, this, arguments[1]);
|
||||
break;
|
||||
case 3:
|
||||
emitTwo(handler, isFn, this, arguments[1], arguments[2]);
|
||||
break;
|
||||
case 4:
|
||||
emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
|
||||
break;
|
||||
// slower
|
||||
default:
|
||||
args = new Array(len - 1);
|
||||
for (i = 1; i < len; i++)
|
||||
args[i - 1] = arguments[i];
|
||||
emitMany(handler, isFn, this, args);
|
||||
}
|
||||
|
||||
if (needDomainExit)
|
||||
domain.exit();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.addListener = function(type, listener) {
|
||||
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
||||
var m;
|
||||
var events;
|
||||
var existing;
|
||||
|
||||
if (typeof listener !== 'function')
|
||||
throw TypeError('listener must be a function');
|
||||
throw new TypeError('listener must be a function');
|
||||
|
||||
if (!this._events)
|
||||
this._events = {};
|
||||
events = this._events;
|
||||
if (!events) {
|
||||
events = this._events = {};
|
||||
this._eventsCount = 0;
|
||||
} else {
|
||||
// To avoid recursion in the case that type === "newListener"! Before
|
||||
// adding it to the listeners, first emit "newListener".
|
||||
if (events.newListener) {
|
||||
this.emit('newListener', type,
|
||||
listener.listener ? listener.listener : listener);
|
||||
|
||||
// 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, typeof listener.listener === 'function' ?
|
||||
listener.listener : listener);
|
||||
// Re-assign `events` because a newListener handler could have caused the
|
||||
// this._events to be assigned to a new object
|
||||
events = this._events;
|
||||
}
|
||||
existing = events[type];
|
||||
}
|
||||
|
||||
if (!this._events[type])
|
||||
if (!existing) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
this._events[type] = listener;
|
||||
else if (typeof this._events[type] === 'object')
|
||||
// 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];
|
||||
existing = events[type] = listener;
|
||||
++this._eventsCount;
|
||||
} else {
|
||||
if (typeof existing === 'function') {
|
||||
// Adding the second element, need to change to array.
|
||||
existing = events[type] = [existing, listener];
|
||||
} else {
|
||||
// If we've already got an array, just append.
|
||||
existing.push(listener);
|
||||
}
|
||||
|
||||
// Check for listener leak
|
||||
if (typeof this._events[type] === 'object' && !this._events[type].warned) {
|
||||
m = this._maxListeners;
|
||||
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);
|
||||
console.trace();
|
||||
// Check for listener leak
|
||||
if (!existing.warned) {
|
||||
m = $getMaxListeners(this);
|
||||
if (m && m > 0 && existing.length > m) {
|
||||
existing.warned = true;
|
||||
console.error('(node) warning: possible EventEmitter memory ' +
|
||||
'leak detected. %d %s listeners added. ' +
|
||||
'Use emitter.setMaxListeners() to increase limit.',
|
||||
existing.length, type);
|
||||
console.trace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,9 +266,9 @@ EventEmitter.prototype.addListener = function(type, listener) {
|
|||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.once = function(type, listener) {
|
||||
EventEmitter.prototype.once = function once(type, listener) {
|
||||
if (typeof listener !== 'function')
|
||||
throw TypeError('listener must be a function');
|
||||
throw new TypeError('listener must be a function');
|
||||
|
||||
var fired = false;
|
||||
|
||||
|
@ -188,109 +288,167 @@ EventEmitter.prototype.once = function(type, listener) {
|
|||
};
|
||||
|
||||
// emits a 'removeListener' event iff the listener was removed
|
||||
EventEmitter.prototype.removeListener = function(type, listener) {
|
||||
var list, position, length, i;
|
||||
EventEmitter.prototype.removeListener =
|
||||
function removeListener(type, listener) {
|
||||
var list, events, position, i;
|
||||
|
||||
if (typeof listener !== 'function')
|
||||
throw TypeError('listener must be a function');
|
||||
if (typeof listener !== 'function')
|
||||
throw new TypeError('listener must be a function');
|
||||
|
||||
if (!this._events || !this._events[type])
|
||||
return this;
|
||||
events = this._events;
|
||||
if (!events)
|
||||
return this;
|
||||
|
||||
list = this._events[type];
|
||||
length = list.length;
|
||||
position = -1;
|
||||
list = events[type];
|
||||
if (!list)
|
||||
return this;
|
||||
|
||||
if (list === listener ||
|
||||
(typeof list.listener === 'function' && list.listener === listener)) {
|
||||
delete this._events[type];
|
||||
if (this._events.removeListener)
|
||||
this.emit('removeListener', type, listener);
|
||||
if (list === listener || (list.listener && list.listener === listener)) {
|
||||
if (--this._eventsCount === 0)
|
||||
this._events = {};
|
||||
else {
|
||||
delete events[type];
|
||||
if (events.removeListener)
|
||||
this.emit('removeListener', type, listener);
|
||||
}
|
||||
} else if (typeof list !== 'function') {
|
||||
position = -1;
|
||||
|
||||
} else if (typeof list === 'object') {
|
||||
for (i = length; i-- > 0;) {
|
||||
if (list[i] === listener ||
|
||||
(list[i].listener && list[i].listener === listener)) {
|
||||
position = i;
|
||||
break;
|
||||
for (i = list.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[0] = undefined;
|
||||
if (--this._eventsCount === 0) {
|
||||
this._events = {};
|
||||
return this;
|
||||
} else {
|
||||
delete events[type];
|
||||
}
|
||||
} else {
|
||||
spliceOne(list, position);
|
||||
}
|
||||
|
||||
if (events.removeListener)
|
||||
this.emit('removeListener', type, listener);
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0)
|
||||
return this;
|
||||
};
|
||||
|
||||
if (list.length === 1) {
|
||||
list.length = 0;
|
||||
delete this._events[type];
|
||||
} else {
|
||||
list.splice(position, 1);
|
||||
}
|
||||
EventEmitter.prototype.removeAllListeners =
|
||||
function removeAllListeners(type) {
|
||||
var listeners, events;
|
||||
|
||||
if (this._events.removeListener)
|
||||
this.emit('removeListener', type, listener);
|
||||
}
|
||||
events = this._events;
|
||||
if (!events)
|
||||
return this;
|
||||
|
||||
return this;
|
||||
};
|
||||
// not listening for removeListener, no need to emit
|
||||
if (!events.removeListener) {
|
||||
if (arguments.length === 0) {
|
||||
this._events = {};
|
||||
this._eventsCount = 0;
|
||||
} else if (events[type]) {
|
||||
if (--this._eventsCount === 0)
|
||||
this._events = {};
|
||||
else
|
||||
delete events[type];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
EventEmitter.prototype.removeAllListeners = function(type) {
|
||||
var key, listeners;
|
||||
// emit removeListener for all listeners on all events
|
||||
if (arguments.length === 0) {
|
||||
var keys = Object.keys(events);
|
||||
for (var i = 0, key; i < keys.length; ++i) {
|
||||
key = keys[i];
|
||||
if (key === 'removeListener') continue;
|
||||
this.removeAllListeners(key);
|
||||
}
|
||||
this.removeAllListeners('removeListener');
|
||||
this._events = {};
|
||||
this._eventsCount = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!this._events)
|
||||
return this;
|
||||
listeners = events[type];
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (typeof listeners === 'function') {
|
||||
this.removeListener(type, listeners);
|
||||
} else if (listeners) {
|
||||
// LIFO order
|
||||
do {
|
||||
this.removeListener(type, listeners[listeners.length - 1]);
|
||||
} while (listeners[0]);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
listeners = this._events[type];
|
||||
|
||||
if (typeof listeners === 'function') {
|
||||
this.removeListener(type, listeners);
|
||||
} else if (Array.isArray(listeners)) {
|
||||
// LIFO order
|
||||
while (listeners.length)
|
||||
this.removeListener(type, listeners[listeners.length - 1]);
|
||||
}
|
||||
delete this._events[type];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listeners = function(type) {
|
||||
EventEmitter.prototype.listeners = function listeners(type) {
|
||||
var evlistener;
|
||||
var ret;
|
||||
if (!this._events || !this._events[type])
|
||||
var events = this._events;
|
||||
|
||||
if (!events)
|
||||
ret = [];
|
||||
else if (typeof this._events[type] === 'function')
|
||||
ret = [this._events[type]];
|
||||
else
|
||||
ret = this._events[type].slice();
|
||||
else {
|
||||
evlistener = events[type];
|
||||
if (!evlistener)
|
||||
ret = [];
|
||||
else if (typeof evlistener === 'function')
|
||||
ret = [evlistener];
|
||||
else
|
||||
ret = arrayClone(evlistener, evlistener.length);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
EventEmitter.listenerCount = function(emitter, type) {
|
||||
var ret;
|
||||
if (!emitter._events || !emitter._events[type])
|
||||
ret = 0;
|
||||
else if (typeof emitter._events[type] === 'function')
|
||||
ret = 1;
|
||||
else
|
||||
ret = emitter._events[type].length;
|
||||
return ret;
|
||||
if (typeof emitter.listenerCount === 'function') {
|
||||
return emitter.listenerCount(type);
|
||||
} else {
|
||||
return listenerCount.call(emitter, type);
|
||||
}
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listenerCount = listenerCount;
|
||||
function listenerCount(type) {
|
||||
const events = this._events;
|
||||
|
||||
if (events) {
|
||||
const evlistener = events[type];
|
||||
|
||||
if (typeof evlistener === 'function') {
|
||||
return 1;
|
||||
} else if (evlistener) {
|
||||
return evlistener.length;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
// About 1.5x faster than the two-arg version of Array#splice().
|
||||
function spliceOne(list, index) {
|
||||
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
|
||||
list[i] = list[k];
|
||||
list.pop();
|
||||
}
|
||||
|
||||
function arrayClone(arr, i) {
|
||||
var copy = new Array(i);
|
||||
while (i--)
|
||||
copy[i] = arr[i];
|
||||
return copy;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue