events: check if _events is an own property
Without this check it is possible to have the _events object shared amongst instances. Fixes #7157 Signed-off-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
c7f424e44b
commit
2c6b424829
@ -49,7 +49,10 @@ EventEmitter.init = function() {
|
|||||||
this.domain = domain.active;
|
this.domain = domain.active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._events = this._events || {};
|
|
||||||
|
if (!this._events || this._events === Object.getPrototypeOf(this)._events)
|
||||||
|
this._events = {};
|
||||||
|
|
||||||
this._maxListeners = this._maxListeners || undefined;
|
this._maxListeners = this._maxListeners || undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,3 +53,17 @@ process.on('exit', function() {
|
|||||||
assert.deepEqual(myee._events, {});
|
assert.deepEqual(myee._events, {});
|
||||||
console.log('ok');
|
console.log('ok');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function MyEE2() {
|
||||||
|
EventEmitter.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
MyEE2.prototype = new EventEmitter();
|
||||||
|
|
||||||
|
var ee1 = new MyEE2();
|
||||||
|
var ee2 = new MyEE2();
|
||||||
|
|
||||||
|
ee1.on('x', function () {});
|
||||||
|
|
||||||
|
assert.equal(EventEmitter.listenerCount(ee2, 'x'), 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user