Skip to content

Commit 9f8eddb

Browse files
author
Dave
committed
initialize console in defaultMaxListeners setter
1 parent 362d832 commit 9f8eddb

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/events.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ EventEmitter.prototype._maxListeners = undefined;
1919

2020
// By default EventEmitters will print a warning if more than 10 listeners are
2121
// added to it. This is a useful default which helps finding memory leaks.
22-
EventEmitter.defaultMaxListeners = 10;
22+
var defaultMaxListeners = 10;
23+
24+
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
25+
enumerable: true,
26+
get: function() {
27+
return defaultMaxListeners;
28+
},
29+
set: function(arg) {
30+
// force global console to be compiled.
31+
// see https://github.com/nodejs/node/issues/4467
32+
console;
33+
defaultMaxListeners = arg;
34+
}
35+
});
2336

2437
EventEmitter.init = function() {
2538
this.domain = null;
@@ -240,8 +253,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
240253
'leak detected. %d %s listeners added. ' +
241254
'Use emitter.setMaxListeners() to increase limit.',
242255
existing.length, type);
243-
if (console.trace)
244-
console.trace();
256+
console.trace();
245257
}
246258
}
247259
}

lib/internal/util.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ exports.error = function(msg) {
2525
args[0] = fmt;
2626
for (let i = 1; i < arguments.length; ++i)
2727
args[i] = arguments[i];
28-
if (console.error)
29-
console.error.apply(console, args);
28+
console.error.apply(console, args);
3029
} else {
3130
console.error(fmt);
3231
}

0 commit comments

Comments
 (0)