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

events: fix bug listenerCount don't compare wrapped listener #48592

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ function listenerCount(type, listener) {

if (typeof evlistener === 'function') {
if (listener != null) {
return listener === evlistener ? 1 : 0;
return listener === evlistener || listener === evlistener.listener ? 1 : 0;
}

return 1;
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-events-listener-count-with-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
assert.strictEqual(EE.listenerCount('event', handler), 0);
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0);

EE.once('event', handler);

assert.strictEqual(EE.listenerCount('event'), 1);
assert.strictEqual(EE.listenerCount('event', handler), 1);
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0);

EE.removeAllListeners('event')

Check failure on line 21 in test/parallel/test-events-listener-count-with-listener.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

assert.strictEqual(EE.listenerCount('event'), 0);
assert.strictEqual(EE.listenerCount('event', handler), 0);
assert.strictEqual(EE.listenerCount('event', anotherHandler), 0);

EE.on('event', handler);

assert.strictEqual(EE.listenerCount('event'), 1);
Expand Down