Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 431f6f0

Browse files
alxhubmhevery
authored andcommitted
fix(node): crash when calling listeners() for event with no listeners
1 parent abaac6f commit 431f6f0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: lib/common/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ export function makeZoneAwareListeners(fnName: string) {
253253
return function zoneAwareEventListeners(self: any, args: any[]) {
254254
const eventName: string = args[0];
255255
const target = self || _global;
256+
if (!target[EVENT_TASKS]) {
257+
return [];
258+
}
256259
return target[EVENT_TASKS]
257260
.filter(task => task.data.eventName === eventName)
258261
.map(task => task.data.handler);

Diff for: test/node/events.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ describe('nodejs EventEmitter', () => {
5858
});
5959
expect(emitter.listeners('test')).toEqual([expectZoneA, shouldNotRun]);
6060
});
61+
it('should return empty array when an event has no listeners', () => {
62+
zoneA.run(() => {
63+
expect(emitter.listeners('test')).toEqual([]);
64+
});
65+
})
6166
});

0 commit comments

Comments
 (0)