Skip to content

Commit

Permalink
events: add initEvent to Event
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and RafaelGSS committed Jan 20, 2023
1 parent 5bdfaae commit f85a8e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
16 changes: 16 additions & 0 deletions doc/api/events.md
Expand Up @@ -2086,6 +2086,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.

#### `event.isTrusted`

<!-- YAML
Expand Down
18 changes: 18 additions & 0 deletions lib/internal/event_target.js
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
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

0 comments on commit f85a8e4

Please sign in to comment.