Skip to content

Commit

Permalink
fixup! set actual properties
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamingr committed Jun 4, 2020
1 parent cb3a9ac commit 412d82d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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; },
Expand Down Expand Up @@ -109,12 +111,14 @@ class Event {
get eventPhase() {
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
}
get cancelBubble() { return false; }
set 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'; }
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ ok(EventTarget);
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 });
Expand Down

0 comments on commit 412d82d

Please sign in to comment.