More instanceof Array fixes
This commit is contained in:
parent
bd05d83ae7
commit
6961bc568f
@ -1,11 +1,12 @@
|
|||||||
exports.EventEmitter = process.EventEmitter;
|
exports.EventEmitter = process.EventEmitter;
|
||||||
|
|
||||||
|
var isArray = Array.isArray;
|
||||||
|
|
||||||
process.EventEmitter.prototype.emit = function (type) {
|
process.EventEmitter.prototype.emit = function (type) {
|
||||||
// If there is no 'error' event listener then throw.
|
// If there is no 'error' event listener then throw.
|
||||||
if (type === 'error') {
|
if (type === 'error') {
|
||||||
if (!this._events || !this._events.error ||
|
if (!this._events || !this._events.error ||
|
||||||
(this._events.error instanceof Array && !this._events.error.length))
|
(isArray(this._events.error) && !this._events.error.length))
|
||||||
{
|
{
|
||||||
if (arguments[1] instanceof Error) {
|
if (arguments[1] instanceof Error) {
|
||||||
throw arguments[1];
|
throw arguments[1];
|
||||||
@ -33,7 +34,7 @@ process.EventEmitter.prototype.emit = function (type) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (this._events[type] instanceof Array) {
|
} else if (isArray(this._events[type])) {
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ process.EventEmitter.prototype.addListener = function (type, listener) {
|
|||||||
if (!this._events[type]) {
|
if (!this._events[type]) {
|
||||||
// Optimize the case of one listener. Don't need the extra array object.
|
// Optimize the case of one listener. Don't need the extra array object.
|
||||||
this._events[type] = listener;
|
this._events[type] = listener;
|
||||||
} else if (this._events[type] instanceof Array) {
|
} else if (isArray(this._events[type])) {
|
||||||
// If we've already got an array, just append.
|
// If we've already got an array, just append.
|
||||||
this._events[type].push(listener);
|
this._events[type].push(listener);
|
||||||
} else {
|
} else {
|
||||||
@ -87,7 +88,7 @@ process.EventEmitter.prototype.removeListener = function (type, listener) {
|
|||||||
|
|
||||||
var list = this._events[type];
|
var list = this._events[type];
|
||||||
|
|
||||||
if (list instanceof Array) {
|
if (isArray(list)) {
|
||||||
var i = list.indexOf(listener);
|
var i = list.indexOf(listener);
|
||||||
if (i < 0) return this;
|
if (i < 0) return this;
|
||||||
list.splice(i, 1);
|
list.splice(i, 1);
|
||||||
@ -109,7 +110,7 @@ process.EventEmitter.prototype.removeAllListeners = function (type) {
|
|||||||
process.EventEmitter.prototype.listeners = function (type) {
|
process.EventEmitter.prototype.listeners = function (type) {
|
||||||
if (!this._events) this._events = {};
|
if (!this._events) this._events = {};
|
||||||
if (!this._events[type]) this._events[type] = [];
|
if (!this._events[type]) this._events[type] = [];
|
||||||
if (!(this._events[type] instanceof Array)) {
|
if (!isArray(this._events[type])) {
|
||||||
this._events[type] = [this._events[type]];
|
this._events[type] = [this._events[type]];
|
||||||
}
|
}
|
||||||
return this._events[type];
|
return this._events[type];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user