Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: allow null/undefined eventInitDict #54643

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also update jsdoc?

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