Skip to content
Open
Changes from all commits
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
19 changes: 10 additions & 9 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const {
ObjectDefineProperty,
ObjectDefineProperties,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
Promise,
PromiseReject,
PromiseResolve,
Expand Down Expand Up @@ -508,7 +507,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
return false;

if (typeof handler === 'function') {
const result = handler.apply(this, args);
const result = ReflectApply(handler, this, args);

// We check if result is undefined first because that
// is the most common case so we do not pay any perf
Expand All @@ -520,7 +519,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
const len = handler.length;
const listeners = arrayClone(handler);
for (let i = 0; i < len; ++i) {
const result = listeners[i].apply(this, args);
const result = ReflectApply(listeners[i], this, args);

// We check if result is undefined first because that
// is the most common case so we do not pay any perf
Expand Down Expand Up @@ -623,7 +622,7 @@ function onceWrapper() {
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
return ReflectApply(this.listener, this.target, arguments);
}
}

Expand Down Expand Up @@ -751,9 +750,10 @@ EventEmitter.prototype.removeAllListeners =

// Emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (const key of ReflectOwnKeys(events)) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
const ownKeys = ReflectOwnKeys(events);
for (let i = 0; i < ownKeys.length; i++) {
if (ownKeys[i] === 'removeListener') continue;
this.removeAllListeners(ownKeys[i]);
}
this.removeAllListeners('removeListener');
this._events = { __proto__: null };
Expand Down Expand Up @@ -1059,7 +1059,8 @@ function on(emitter, event, options = kEmptyObject) {
let finished = false;
let size = 0;

const iterator = ObjectSetPrototypeOf({
const iterator = {
__proto__: AsyncIteratorPrototype,
next() {
// First, we consume all unread events
if (size) {
Expand Down Expand Up @@ -1131,7 +1132,7 @@ function on(emitter, event, options = kEmptyObject) {
return paused;
},
},
}, AsyncIteratorPrototype);
};

// Adding event handlers
const { addEventListener, removeAll } = listenersController();
Expand Down