Skip to content

Commit

Permalink
events: allow null/undefined eventInitDict
Browse files Browse the repository at this point in the history
PR-URL: #54643
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
KhafraDev authored and jasnell committed Sep 21, 2024
1 parent d473606 commit a9081b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,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]) {
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit a9081b5

Please sign in to comment.