diff options
author | Deokjin Kim <deokjin81.kim@gmail.com> | 2023-01-19 17:59:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 08:59:00 +0000 |
commit | 2ff8c5090eb55d3bd3e00331b73c624c4a67581c (patch) | |
tree | 722edd57378706d59cb8bf5f4022ed2fffbdb035 /lib | |
parent | 65f8a2716e6ec129f57090686a781b4ec24b08f9 (diff) | |
download | node-new-2ff8c5090eb55d3bd3e00331b73c624c4a67581c.tar.gz |
events: add `initEvent` to Event
Refs: https://dom.spec.whatwg.org/#dom-event-initevent
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/event_target.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 66d7a0db87..dbe30d739c 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -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'); @@ -307,6 +324,7 @@ ObjectDefineProperties( configurable: true, value: 'Event', }, + initEvent: kEnumerableProperty, stopImmediatePropagation: kEnumerableProperty, preventDefault: kEnumerableProperty, target: kEnumerableProperty, |