Skip to content

Commit

Permalink
fixup! events: refactor to use more primordials
Browse files Browse the repository at this point in the history
This reverts commit 940bd12.
  • Loading branch information
aduh95 committed Dec 18, 2020
1 parent 7a158a2 commit 9863b29
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ const {
Boolean,
Error,
ErrorCaptureStackTrace,
Function,
FunctionPrototypeBind,
FunctionPrototypeCall,
FunctionPrototypeToString,
MathMin,
NumberIsNaN,
ObjectCreate,
Expand All @@ -51,7 +49,6 @@ const {
ReflectOwnKeys,
String,
StringPrototypeSplit,
StringPrototypeReplace,
Symbol,
SymbolFor,
SymbolAsyncIterator
Expand Down Expand Up @@ -93,6 +90,9 @@ const lazyDOMException = hideStackFrames((message, name) => {
});


function EventEmitter(opts) {
FunctionPrototypeCall(EventEmitter.init, this, opts);
}
module.exports = EventEmitter;
module.exports.once = once;
module.exports.on = on;
Expand Down Expand Up @@ -199,9 +199,7 @@ EventEmitter.setMaxListeners =
}
};

let customInit;
function EventEmitter(opts) {
if (customInit) return FunctionPrototypeCall(customInit, this, opts);
EventEmitter.init = function(opts) {

if (this._events === undefined ||
this._events === ObjectGetPrototypeOf(this)._events) {
Expand All @@ -223,16 +221,7 @@ function EventEmitter(opts) {
// prototype lookup in a very sensitive hot path.
this[kCapture] = EventEmitter.prototype[kCapture];
}
}
ObjectDefineProperty(EventEmitter, 'init', {
enumerable: true,
get: () =>
new Function(StringPrototypeReplace(FunctionPrototypeToString(EventEmitter),
/^\s*if\s*\(customInit\)/, '')),
set: (init) => {
customInit = init;
}
});
};

function addCatch(that, promise, type, args) {
if (!that[kCapture]) {
Expand Down

0 comments on commit 9863b29

Please sign in to comment.