mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
event: cancelBubble is a property
Event#cancelBubble is property (and not a function). Change Event#cancelBubble to a property and add a test. PR-URL: https://github.com/nodejs/node/pull/33613 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
1 parent
6e8709df5b
commit
3128915c57
2 files changed
+28
-4
No files matched your search
@@ -35,12 +35,13 @@ class Event {
|
||||
#cancelable = false;
|
||||
#timestamp = perf_hooks.performance.now();
|
||||
|
||||
// Neither of these are currently used in the Node.js implementation
|
||||
// None of these are currently used in the Node.js implementation
|
||||
// of EventTarget because there is no concept of bubbling or
|
||||
// composition. We preserve their values in Event but they are
|
||||
// non-ops and do not carry any semantics in Node.js
|
||||
#bubbles = false;
|
||||
#composed = false;
|
||||
#propagationStopped = false;
|
||||
|
||||
|
||||
constructor(type, options) {
|
||||
@@ -51,6 +52,7 @@ class Event {
|
||||
this.#bubbles = !!bubbles;
|
||||
this.#composed = !!composed;
|
||||
this.#type = `${type}`;
|
||||
this.#propagationStopped = false;
|
||||
// isTrusted is special (LegacyUnforgeable)
|
||||
Object.defineProperty(this, 'isTrusted', {
|
||||
get() { return false; },
|
||||
@@ -109,11 +111,14 @@ class Event {
|
||||
get eventPhase() {
|
||||
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
|
||||
}
|
||||
cancelBubble() {
|
||||
// Non-op in Node.js. Alias for stopPropagation
|
||||
get cancelBubble() { return this.#propagationStopped; }
|
||||
set cancelBubble(value) {
|
||||
if (value) {
|
||||
this.stopPropagation();
|
||||
}
|
||||
}
|
||||
stopPropagation() {
|
||||
// Non-op in Node.js
|
||||
this.#propagationStopped = true;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() { return 'Event'; }
|
||||
|
||||
@@ -35,11 +35,30 @@ ok(EventTarget);
|
||||
strictEqual(ev.composed, false);
|
||||
strictEqual(ev.isTrusted, false);
|
||||
strictEqual(ev.eventPhase, 0);
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
|
||||
// Not cancelable
|
||||
ev.preventDefault();
|
||||
strictEqual(ev.defaultPrevented, false);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = true;
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
ev.stopPropagation();
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
{
|
||||
const ev = new Event('foo');
|
||||
strictEqual(ev.cancelBubble, false);
|
||||
ev.cancelBubble = 'some-truthy-value';
|
||||
strictEqual(ev.cancelBubble, true);
|
||||
}
|
||||
|
||||
{
|
||||
const ev = new Event('foo', { cancelable: true });
|
||||
|
||||
Reference in new issue
Block a user