Skip to content

Commit 2a29ced

Browse files
benjamingrcodebytere
authored andcommitted
events: fix event-target enumerable keys
PR-URL: #33616 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f3d0d30 commit 2a29ced

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/internal/event_target.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class Event {
5151
this.#bubbles = !!bubbles;
5252
this.#composed = !!composed;
5353
this.#type = String(type);
54+
// isTrusted is special (LegacyUnforgeable)
55+
Object.defineProperty(this, 'isTrusted', {
56+
get() { return false; },
57+
set(ignoredValue) { return false; },
58+
enumerable: true,
59+
configurable: false
60+
});
5461
}
5562

5663
[customInspectSymbol](depth, options) {
@@ -99,7 +106,6 @@ class Event {
99106
get returnValue() { return !this.defaultPrevented; }
100107
get bubbles() { return this.#bubbles; }
101108
get composed() { return this.#composed; }
102-
get isTrusted() { return false; }
103109
get eventPhase() {
104110
return this[kTarget] ? 2 : 0; // Equivalent to AT_TARGET or NONE
105111
}

test/parallel/test-eventtarget.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ ok(EventTarget);
5050
ev.preventDefault();
5151
strictEqual(ev.defaultPrevented, true);
5252
}
53-
53+
{
54+
const ev = new Event('foo');
55+
deepStrictEqual(Object.keys(ev), ['isTrusted']);
56+
}
5457
{
5558
const eventTarget = new EventTarget();
5659

0 commit comments

Comments
 (0)