Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
addaleax committed Jun 25, 2020
commit 67a66b0dfda5a415727100edba399b82662c70f8
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'));
});