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:
parent
d345c1173a
commit
63edde0e01
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user