Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0c32920

Browse files
addaleaxcodebytere
authored andcommittedJun 27, 2020
events: fix add-remove-add case in EventTarget
Make sure that listeners are added properly if there has previously been one but currently are none for a given event type. PR-URL: #34056 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 95cbfce commit 0c32920

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎lib/internal/event_target.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class EventTarget {
240240
}
241241

242242
let handler = root.next;
243-
let previous;
243+
let previous = root;
244244

245245
// We have to walk the linked list to see if we have a match
246246
while (handler !== undefined && !handler.same(listener, capture)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Flags: --expose-internals --no-warnings
2+
'use strict';
3+
const common = require('../common');
4+
const {
5+
Event,
6+
EventTarget,
7+
} = require('internal/event_target');
8+
const { once } = require('events');
9+
10+
const et = new EventTarget();
11+
(async function() {
12+
await once(et, 'foo');
13+
await once(et, 'foo');
14+
})().then(common.mustCall());
15+
16+
et.dispatchEvent(new Event('foo'));
17+
setImmediate(() => {
18+
et.dispatchEvent(new Event('foo'));
19+
});

0 commit comments

Comments
 (0)
Please sign in to comment.