summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-03-02 11:58:21 -0800
committerisaacs <i@izs.me>2013-03-02 15:01:20 -0800
commitd345c1173ac9c7ba861039707a142e187651f71d (patch)
tree31319ac92417b7d05f8db59dae08618640c369f9
parent2d51036fb9655d5b775e7f9e5ab362cd91460ca3 (diff)
downloadnode-new-d345c1173ac9c7ba861039707a142e187651f71d.tar.gz
events: Handle emit before constructor call
-rw-r--r--lib/events.js3
-rw-r--r--test/simple/test-event-emitter-subclass.js1
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/events.js b/lib/events.js
index 4cfa740765..dd4fdf64e7 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -73,6 +73,9 @@ EventEmitter.prototype.emit = function(type) {
}
}
+ if (!this._events)
+ this._events = {};
+
handler = this._events[type];
if (typeof handler === 'undefined')
diff --git a/test/simple/test-event-emitter-subclass.js b/test/simple/test-event-emitter-subclass.js
index a71a7c73c4..537b682088 100644
--- a/test/simple/test-event-emitter-subclass.js
+++ b/test/simple/test-event-emitter-subclass.js
@@ -27,6 +27,7 @@ var util = require('util');
util.inherits(MyEE, EventEmitter);
function MyEE(cb) {
+ this.emit('bar');
this.on('foo', cb);
process.nextTick(this.emit.bind(this, 'foo'));
EventEmitter.call(this);