Skip to content

Commit f85a8e4

Browse files
deokjinkimRafaelGSS
authored andcommitted
events: add initEvent to Event
Refs: https://dom.spec.whatwg.org/#dom-event-initevent PR-URL: #46069 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5bdfaae commit f85a8e4

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

doc/api/events.md

+16
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,22 @@ added: v14.5.0
20862086

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

2089+
#### `event.initEvent(type[, bubbles[, cancelable]])`
2090+
2091+
<!-- YAML
2092+
added: REPLACEME
2093+
-->
2094+
2095+
> Stability: 3 - Legacy: The WHATWG spec considers it deprecated and users
2096+
> shouldn't use it at all.
2097+
2098+
* `type` {string}
2099+
* `bubbles` {boolean}
2100+
* `cancelable` {boolean}
2101+
2102+
Redundant with event constructors and incapable of setting `composed`.
2103+
This is not used in Node.js and is provided purely for completeness.
2104+
20892105
#### `event.isTrusted`
20902106

20912107
<!-- YAML

lib/internal/event_target.js

+18
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ class Event {
123123
this[kIsBeingDispatched] = false;
124124
}
125125

126+
/**
127+
* @param {string} type
128+
* @param {boolean} [bubbles]
129+
* @param {boolean} [cancelable]
130+
*/
131+
initEvent(type, bubbles = false, cancelable = false) {
132+
if (arguments.length === 0)
133+
throw new ERR_MISSING_ARGS('type');
134+
135+
if (this[kIsBeingDispatched]) {
136+
return;
137+
}
138+
this[kType] = `${type}`;
139+
this.#bubbles = !!bubbles;
140+
this.#cancelable = !!cancelable;
141+
}
142+
126143
[customInspectSymbol](depth, options) {
127144
if (!isEvent(this))
128145
throw new ERR_INVALID_THIS('Event');
@@ -307,6 +324,7 @@ ObjectDefineProperties(
307324
configurable: true,
308325
value: 'Event',
309326
},
327+
initEvent: kEnumerableProperty,
310328
stopImmediatePropagation: kEnumerableProperty,
311329
preventDefault: kEnumerableProperty,
312330
target: kEnumerableProperty,

test/wpt/status/dom/events.json

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88
]
99
}
1010
},
11-
"Event-constructors.any.js": {
12-
"fail": {
13-
"expected": [
14-
"Untitled 3",
15-
"Untitled 4"
16-
]
17-
}
18-
},
1911
"Event-dispatch-listener-order.window.js": {
2012
"skip": "document is not defined"
2113
},

0 commit comments

Comments
 (0)