Skip to content

Commit

Permalink
events: fix add-remove-add case in EventTarget
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
addaleax authored and codebytere committed Jun 27, 2020
1 parent 95cbfce commit 0c32920
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class EventTarget {
}

let handler = root.next;
let previous;
let previous = root;

// We have to walk the linked list to see if we have a match
while (handler !== undefined && !handler.same(listener, capture)) {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-eventtarget-once-twice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Flags: --expose-internals --no-warnings
'use strict';
const common = require('../common');
const {
Event,
EventTarget,
} = require('internal/event_target');
const { once } = require('events');

const et = new EventTarget();
(async function() {
await once(et, 'foo');
await once(et, 'foo');
})().then(common.mustCall());

et.dispatchEvent(new Event('foo'));
setImmediate(() => {
et.dispatchEvent(new Event('foo'));
});

0 comments on commit 0c32920

Please sign in to comment.