From 2a29ced050539438c17bc4011c05cc5c75546d49 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 28 May 2020 18:08:31 +0300 Subject: [PATCH] events: fix event-target enumerable keys PR-URL: https://github.com/nodejs/node/pull/33616 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Anna Henningsen --- lib/internal/event_target.js | 8 +++++++- test/parallel/test-eventtarget.js | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index a898a3c653f36e..763542eb0fc2fa 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -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) { @@ -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 } diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index f27f96803e2a93..99d717abda6e8d 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -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();