events: allow null/undefined eventInitDict

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Khafra 2024-08-29 13:56:54 -04:00 committed by James M Snell
parent d473606040
commit a9081b5391
2 changed files with 12 additions and 6 deletions

View File

@ -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]) {

View File

@ -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);
}