-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.
Description
Version
22.12.0
Platform
Darwin X.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:45 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8112 arm64
Subsystem
No response
What steps will reproduce the bug?
const EventEmitter = require('node:events');
const myEmitter = new EventEmitter();
try {
myEmitter.listeners()
} catch (error) {
console.error("Error: ", error.message);
//Error: TypeError: Cannot read properties of undefined (reading 'length')
}
How often does it reproduce? Is there a required condition?
The issue reproduces 100% of the time when .listeners() is called without any arguments. There are no special conditions required - it happens consistently on any EventEmitter instance.
This issue could have a widespread impact. Many applications and libraries that extend or use a custom EventEmitter might be affected when they upgrade to the latest Node.js version.
What is the expected behavior? Why is that the expected behavior?
The expected behaviour is to return an empty array.
What do you see instead?
Error: TypeError: Cannot read properties of undefined (reading 'length')
at arrayClone (node:events:894:15)
at unwrapListeners (node:events:905:15)
at _listeners (node:events:803:5)
at EventEmitter.listeners (node:events:813:10)
at Object.<anonymous> (/Users/ori.granot/Git/events-node-22/main.js:6:15)
at Module._compile (node:internal/modules/cjs/loader:1562:14)
at Object..js (node:internal/modules/cjs/loader:1708:10)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)```
Additional information
It looks like it was changed in the latest release:
bdb6d12e7a#diff-330bdd22a188135540523f69deb4f9563e03b00a913cd369e1ee84d899f178a9L785
I created a PR to fix the issue: #56264
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.