Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: allow dispatch many times without listener #39772

Closed
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
5 changes: 4 additions & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,11 @@ class EventTarget {
}

const root = this[kEvents].get(type);
if (root === undefined || root.next === undefined)
if (root === undefined || root.next === undefined) {
if (event !== undefined)
event[kIsBeingDispatched] = false;
return true;
}

let handler = root.next;
let next;
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ let asyncTest = Promise.resolve();
deepStrictEqual(event.composedPath(), []);


eventTarget2.dispatchEvent(event);
strictEqual(event.eventPhase, Event.NONE);
strictEqual(event.target, eventTarget2);
deepStrictEqual(event.composedPath(), []);
}
{
// Same event dispatched multiple times, without listeners added.
const event = new Event('foo');
const eventTarget1 = new EventTarget();
const eventTarget2 = new EventTarget();

eventTarget1.dispatchEvent(event);
strictEqual(event.eventPhase, Event.NONE);
strictEqual(event.target, eventTarget1);
deepStrictEqual(event.composedPath(), []);

eventTarget2.dispatchEvent(event);
strictEqual(event.eventPhase, Event.NONE);
strictEqual(event.target, eventTarget2);
Expand Down