diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index cfd3a4922e62ad..70875ec3a142f8 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -115,14 +115,14 @@ class Event { * composed?: boolean, * }} [options] */ - constructor(type, options = kEmptyObject) { + constructor(type, options = undefined) { if (arguments.length === 0) throw new ERR_MISSING_ARGS('type'); - validateObject(options, 'options'); - const { bubbles, cancelable, composed } = options; - this.#cancelable = !!cancelable; - this.#bubbles = !!bubbles; - this.#composed = !!composed; + if (options != null) + validateObject(options, 'options'); + this.#bubbles = !!options?.bubbles; + this.#cancelable = !!options?.cancelable; + this.#composed = !!options?.composed; this[kType] = `${type}`; if (options?.[kTrustEvent]) { diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index 72389a589056e4..cbe7eb3b0e8687 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -747,3 +747,9 @@ let asyncTest = Promise.resolve(); event.cancelBubble = true; strictEqual(event.cancelBubble, true); } + +{ + // A null eventInitDict should not throw an error. + new Event('', null); + new Event('', undefined); +}