diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index cf94bcbe7bf387..e371ee06a1b83b 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 f032b2fedb715a..e47dac6fc2f48c 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -385,6 +385,7 @@ const ev = new Event('foo'); { 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);