Skip to content
Permalink
Browse files
events: expose Event statics
PR-URL: #34015
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
benjamingr authored and codebytere committed Jun 27, 2020
1 parent cd3a142 commit b392fdd4aaedf345090d61194e818c1fad60cd68
Showing with 19 additions and 2 deletions.
  1. +6 −1 lib/internal/event_target.js
  2. +13 −1 test/parallel/test-eventtarget.js
@@ -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, {
@@ -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'));
}

0 comments on commit b392fdd

Please sign in to comment.