Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15.0] NodeEventTarget#removeAllListeners has different return type than EventEmitter#removeAllListeners #35762

Closed
Semigradsky opened this issue Oct 22, 2020 · 0 comments
Labels
events Issues and PRs related to the events subsystem / EventEmitter.

Comments

@Semigradsky
Copy link
Contributor

NodeEventTarget:

removeAllListeners(type) {
if (type !== undefined) {
this[kEvents].delete(String(type));
} else {
this[kEvents].clear();
}
}

Looks like it should return this.

EventEmitter:

node/lib/events.js

Lines 515 to 559 in 3f4ec9c

EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
const events = this._events;
if (events === undefined)
return this;
// Not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = ObjectCreate(null);
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = ObjectCreate(null);
else
delete events[type];
}
return this;
}
// 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);
}
this.removeAllListeners('removeListener');
this._events = ObjectCreate(null);
this._eventsCount = 0;
return this;
}
const listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners !== undefined) {
// LIFO order
for (let i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};

@PoojaDurgad PoojaDurgad added the events Issues and PRs related to the events subsystem / EventEmitter. label Oct 23, 2020
lpinca added a commit to lpinca/node that referenced this issue Oct 26, 2020
@Trott Trott closed this as completed in 81ba3ae Oct 28, 2020
targos pushed a commit that referenced this issue Nov 3, 2020
Fixes: #35762

PR-URL: #35805
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
BethGriggs pushed a commit that referenced this issue Dec 8, 2020
Fixes: #35762

PR-URL: #35805
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
BethGriggs pushed a commit that referenced this issue Dec 10, 2020
Fixes: #35762

PR-URL: #35805
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
BethGriggs pushed a commit that referenced this issue Dec 15, 2020
Fixes: #35762

PR-URL: #35805
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
events Issues and PRs related to the events subsystem / EventEmitter.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants