From 2c6b424829caf0a4c07839c4daac3a438c0f0c9a Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Fri, 4 Apr 2014 02:11:56 +0400 Subject: [PATCH] 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 --- lib/events.js | 5 ++++- test/simple/test-event-emitter-subclass.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/events.js b/lib/events.js index f854bdec9..996f4f0b1 100644 --- a/lib/events.js +++ b/lib/events.js @@ -49,7 +49,10 @@ EventEmitter.init = function() { this.domain = domain.active; } } - this._events = this._events || {}; + + if (!this._events || this._events === Object.getPrototypeOf(this)._events) + this._events = {}; + this._maxListeners = this._maxListeners || undefined; }; diff --git a/test/simple/test-event-emitter-subclass.js b/test/simple/test-event-emitter-subclass.js index 8a2e9c156..60b4bf387 100644 --- a/test/simple/test-event-emitter-subclass.js +++ b/test/simple/test-event-emitter-subclass.js @@ -53,3 +53,17 @@ process.on('exit', function() { assert.deepEqual(myee._events, {}); 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); -- 2.34.1