events: expose Event statics

PR-URL: https://github.com/nodejs/node/pull/34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Benjamin Gruenbaum authored and James M Snell committed 2020-06-23 17:08:10 -07:00
1 parent a30babf672
commit 9d324f0441
2 files changed
+19 -2

No files matched your search

+6 -1
View File
@@ -125,7 +125,7 @@ class Event {
get bubbles() { return this.#bubbles; }
get composed() { return this.#composed; }
get eventPhase() {
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
return this[kTarget] ? Event.AT_TARGET : Event.NONE;
}
get cancelBubble() { return this.#propagationStopped; }
set cancelBubble(value) {
@@ -136,6 +136,11 @@ class Event {
stopPropagation() {
this.#propagationStopped = true;
}
static NONE = 0;
static CAPTURING_PHASE = 1;
static AT_TARGET = 2;
static BUBBLING_PHASE = 3;
}
Object.defineProperty(Event.prototype, SymbolToStringTag, {
+13 -1
View File
@@ -432,7 +432,6 @@ ok(EventTarget);
target.removeEventListener('foo', a, { capture: false });
target.dispatchEvent(new Event('foo'));
}
{
const target = new EventTarget();
strictEqual(target.toString(), '[object EventTarget]');
@@ -464,3 +463,16 @@ ok(EventTarget);
});
});
}
{
strictEqual(Event.NONE, 0);
strictEqual(Event.CAPTURING_PHASE, 1);
strictEqual(Event.AT_TARGET, 2);
strictEqual(Event.BUBBLING_PHASE, 3);
strictEqual(new Event('foo').eventPhase, Event.NONE);
const target = new EventTarget();
target.addEventListener('foo', common.mustCall((e) => {
strictEqual(e.eventPhase, Event.AT_TARGET);
}), { once: true });
target.dispatchEvent(new Event('foo'));
}