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 <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
KhafraDev authored and marco-ippolito committed Nov 17, 2024
1 parent 93a098c commit 0c1666a
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 @@ -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]) {
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 0c1666a

Please sign in to comment.