diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 47f7b1d592a1c7..df25200f1b09d8 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -64,6 +64,7 @@ class Event { enumerable: true, configurable: false }); + this[kTarget] = null; } [customInspectSymbol](depth, options) { @@ -245,7 +246,7 @@ class EventTarget { } if (this.#emitting.has(event.type) || - event[kTarget] !== undefined) { + event[kTarget] !== null) { throw new ERR_EVENT_RECURSION(event.type); } diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index cf52030aee5a05..8d4be41df55c73 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -379,6 +379,7 @@ ok(EventTarget); { const target = new EventTarget(); const event = new Event('foo'); + strictEqual(event.target, null); target.addEventListener('foo', common.mustCall((event) => { strictEqual(event.target, target); strictEqual(event.currentTarget, target);