Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! events: refactor to use more primordials
This reverts commit 940bd12.
  • Loading branch information
aduh95 committed Dec 18, 2020
commit 9863b295d9746122aefcc921be11b48211f2a77b
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