Skip to content

Commit 412d82d

Browse files
committed
fixup! set actual properties
1 parent cb3a9ac commit 412d82d

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/internal/event_target.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ class Event {
3535
#cancelable = false;
3636
#timestamp = perf_hooks.performance.now();
3737

38-
// Neither of these are currently used in the Node.js implementation
38+
// None of these are currently used in the Node.js implementation
3939
// of EventTarget because there is no concept of bubbling or
4040
// composition. We preserve their values in Event but they are
4141
// non-ops and do not carry any semantics in Node.js
4242
#bubbles = false;
4343
#composed = false;
44+
#propagationStopped = false;
4445

4546

4647
constructor(type, options) {
@@ -51,6 +52,7 @@ class Event {
5152
this.#bubbles = !!bubbles;
5253
this.#composed = !!composed;
5354
this.#type = `${type}`;
55+
this.#propagationStopped = false;
5456
// isTrusted is special (LegacyUnforgeable)
5557
Object.defineProperty(this, 'isTrusted', {
5658
get() { return false; },
@@ -109,12 +111,14 @@ class Event {
109111
get eventPhase() {
110112
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
111113
}
112-
get cancelBubble() { return false; }
113-
set cancelBubble() {
114-
// Non-op in Node.js. Alias for stopPropagation
114+
get cancelBubble() { return this.#propagationStopped; }
115+
set cancelBubble(value) {
116+
if (value) {
117+
this.stopPropagation();
118+
}
115119
}
116120
stopPropagation() {
117-
// Non-op in Node.js
121+
this.#propagationStopped = true;
118122
}
119123

120124
get [Symbol.toStringTag]() { return 'Event'; }

test/parallel/test-eventtarget.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ ok(EventTarget);
4141
ev.preventDefault();
4242
strictEqual(ev.defaultPrevented, false);
4343
}
44+
{
45+
const ev = new Event('foo');
46+
strictEqual(ev.cancelBubble, false);
47+
ev.cancelBubble = true;
48+
strictEqual(ev.cancelBubble, true);
49+
}
50+
{
51+
const ev = new Event('foo');
52+
strictEqual(ev.cancelBubble, false);
53+
ev.stopPropagation();
54+
strictEqual(ev.cancelBubble, true);
55+
}
56+
{
57+
const ev = new Event('foo');
58+
strictEqual(ev.cancelBubble, false);
59+
ev.cancelBubble = 'some-truthy-value';
60+
strictEqual(ev.cancelBubble, true);
61+
}
4462

4563
{
4664
const ev = new Event('foo', { cancelable: true });

0 commit comments

Comments
 (0)