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: add initEvent to Event #46069

Merged
merged 5 commits into from
Jan 19, 2023
Merged
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
16 changes: 16 additions & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,22 @@ added: v14.5.0

This is not used in Node.js and is provided purely for completeness.

#### `event.initEvent(type[, bubbles[, cancelable]])`

<!-- YAML
added: REPLACEME
-->

> Stability: 3 - Legacy: The WHATWG spec considers it deprecated and users
> shouldn't use it at all.

* `type` {string}
* `bubbles` {boolean}
* `cancelable` {boolean}

Redundant with event constructors and incapable of setting `composed`.
This is not used in Node.js and is provided purely for completeness.
anonrig marked this conversation as resolved.
Show resolved Hide resolved

#### `event.isTrusted`

<!-- YAML
Expand Down
18 changes: 18 additions & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ class Event {
this[kIsBeingDispatched] = false;
}

/**
* @param {string} type
* @param {boolean} [bubbles]
* @param {boolean} [cancelable]
*/
initEvent(type, bubbles = false, cancelable = false) {
if (arguments.length === 0)
throw new ERR_MISSING_ARGS('type');

if (this[kIsBeingDispatched]) {
return;
}
this[kType] = `${type}`;
this.#bubbles = !!bubbles;
this.#cancelable = !!cancelable;
}

[customInspectSymbol](depth, options) {
if (!isEvent(this))
throw new ERR_INVALID_THIS('Event');
Expand Down Expand Up @@ -307,6 +324,7 @@ ObjectDefineProperties(
configurable: true,
value: 'Event',
},
initEvent: kEnumerableProperty,
stopImmediatePropagation: kEnumerableProperty,
preventDefault: kEnumerableProperty,
target: kEnumerableProperty,
Expand Down
8 changes: 0 additions & 8 deletions test/wpt/status/dom/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
]
}
},
"Event-constructors.any.js": {
"fail": {
"expected": [
"Untitled 3",
"Untitled 4"
]
}
},
"Event-dispatch-listener-order.window.js": {
"skip": "document is not defined"
},
Expand Down