Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b392fdd

Browse files
benjamingrcodebytere
authored andcommittedJun 27, 2020
events: expose Event statics
PR-URL: #34015 Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent cd3a142 commit b392fdd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎lib/internal/event_target.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Event {
125125
get bubbles() { return this.#bubbles; }
126126
get composed() { return this.#composed; }
127127
get eventPhase() {
128-
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
128+
return this[kTarget] ? Event.AT_TARGET : Event.NONE;
129129
}
130130
get cancelBubble() { return this.#propagationStopped; }
131131
set cancelBubble(value) {
@@ -136,6 +136,11 @@ class Event {
136136
stopPropagation() {
137137
this.#propagationStopped = true;
138138
}
139+
140+
static NONE = 0;
141+
static CAPTURING_PHASE = 1;
142+
static AT_TARGET = 2;
143+
static BUBBLING_PHASE = 3;
139144
}
140145

141146
Object.defineProperty(Event.prototype, SymbolToStringTag, {

‎test/parallel/test-eventtarget.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ ok(EventTarget);
432432
target.removeEventListener('foo', a, { capture: false });
433433
target.dispatchEvent(new Event('foo'));
434434
}
435-
436435
{
437436
const target = new EventTarget();
438437
strictEqual(target.toString(), '[object EventTarget]');
@@ -464,3 +463,16 @@ ok(EventTarget);
464463
});
465464
});
466465
}
466+
467+
{
468+
strictEqual(Event.NONE, 0);
469+
strictEqual(Event.CAPTURING_PHASE, 1);
470+
strictEqual(Event.AT_TARGET, 2);
471+
strictEqual(Event.BUBBLING_PHASE, 3);
472+
strictEqual(new Event('foo').eventPhase, Event.NONE);
473+
const target = new EventTarget();
474+
target.addEventListener('foo', common.mustCall((e) => {
475+
strictEqual(e.eventPhase, Event.AT_TARGET);
476+
}), { once: true });
477+
target.dispatchEvent(new Event('foo'));
478+
}

0 commit comments

Comments
 (0)
Please sign in to comment.