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 <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
benjamingr authored and BridgeAR committed May 30, 2020
1 parent 56e4460 commit 2d071e7
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
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
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 2d071e7

Please sign in to comment.