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

Commit

Permalink
fix(node): crash when calling listeners() for event with no listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
alxhub authored and mhevery committed Oct 14, 2016
1 parent abaac6f commit 431f6f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ export function makeZoneAwareListeners(fnName: string) {
return function zoneAwareEventListeners(self: any, args: any[]) {
const eventName: string = args[0];
const target = self || _global;
if (!target[EVENT_TASKS]) {
return [];
}
return target[EVENT_TASKS]
.filter(task => task.data.eventName === eventName)
.map(task => task.data.handler);
Expand Down
5 changes: 5 additions & 0 deletions test/node/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ describe('nodejs EventEmitter', () => {
});
expect(emitter.listeners('test')).toEqual([expectZoneA, shouldNotRun]);
});
it('should return empty array when an event has no listeners', () => {
zoneA.run(() => {
expect(emitter.listeners('test')).toEqual([]);
});
})
});

0 comments on commit 431f6f0

Please sign in to comment.