Skip to content

Commit 45a13d9

Browse files
committed
events: Don't clobber pre-existing _events obj in EE ctor
1 parent d130bb0 commit 45a13d9

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/events.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function EventEmitter() {
3131
this.domain = domain.active;
3232
}
3333
}
34-
this._events = null;
35-
this._maxListeners = defaultMaxListeners;
34+
this._events = this._events || null;
35+
this._maxListeners = this._maxListeners || defaultMaxListeners;
3636
}
3737
exports.EventEmitter = EventEmitter;
3838

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
var assert = require('assert');
24+
var EventEmitter = require('events').EventEmitter;
25+
var util = require('util');
26+
27+
util.inherits(MyEE, EventEmitter);
28+
29+
function MyEE(cb) {
30+
this.on('foo', cb);
31+
process.nextTick(this.emit.bind(this, 'foo'));
32+
EventEmitter.call(this);
33+
}
34+
35+
var called = false;
36+
var myee = new MyEE(function() {
37+
called = true;
38+
});
39+
40+
process.on('exit', function() {
41+
assert(called);
42+
console.log('ok');
43+
});

0 commit comments

Comments
 (0)