mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
events: Handle emit('error') before ctor
The previous commit did not handle the case when the event type is 'error', since that is checked before reading the handler.
This commit is contained in:
@@ -53,6 +53,9 @@ EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
EventEmitter.prototype.emit = function(type) {
|
||||
var er, handler, len, args, i, listeners;
|
||||
|
||||
if (!this._events)
|
||||
this._events = {};
|
||||
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (type === 'error') {
|
||||
if (!this._events.error ||
|
||||
@@ -73,9 +76,6 @@ EventEmitter.prototype.emit = function(type) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._events)
|
||||
this._events = {};
|
||||
|
||||
handler = this._events[type];
|
||||
|
||||
if (typeof handler === 'undefined')
|
||||
|
||||
@@ -38,6 +38,16 @@ var myee = new MyEE(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
|
||||
util.inherits(ErrorEE, EventEmitter);
|
||||
function ErrorEE() {
|
||||
this.emit('error', new Error('blerg'));
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
new ErrorEE();
|
||||
}, /blerg/);
|
||||
|
||||
process.on('exit', function() {
|
||||
assert(called);
|
||||
console.log('ok');
|
||||
|
||||
Reference in New Issue
Block a user