Skip to content

Commit

Permalink
events: add initEvent to Event
Browse files Browse the repository at this point in the history
  • Loading branch information
deokjinkim committed Jan 11, 2023
1 parent 384e1b5 commit 7fdc27d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
15 changes: 15 additions & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,21 @@ 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
* `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
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

0 comments on commit 7fdc27d

Please sign in to comment.