Skip to content

Commit

Permalink
events: fix event-target enumerable keys
Browse files Browse the repository at this point in the history
PR-URL: #33616
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
benjamingr authored and codebytere committed Jun 18, 2020
1 parent f3d0d30 commit 2a29ced
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Event {
this.#bubbles = !!bubbles;
this.#composed = !!composed;
this.#type = String(type);
// isTrusted is special (LegacyUnforgeable)
Object.defineProperty(this, 'isTrusted', {
get() { return false; },
set(ignoredValue) { return false; },
enumerable: true,
configurable: false
});
}

[customInspectSymbol](depth, options) {
Expand Down Expand Up @@ -99,7 +106,6 @@ class Event {
get returnValue() { return !this.defaultPrevented; }
get bubbles() { return this.#bubbles; }
get composed() { return this.#composed; }
get isTrusted() { return false; }
get eventPhase() {
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
}
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ ok(EventTarget);
ev.preventDefault();
strictEqual(ev.defaultPrevented, true);
}

{
const ev = new Event('foo');
deepStrictEqual(Object.keys(ev), ['isTrusted']);
}
{
const eventTarget = new EventTarget();

Expand Down

0 comments on commit 2a29ced

Please sign in to comment.