From eb01214ab285e7b25008639f75751908e2153057 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sat, 6 Jun 2020 21:41:53 +0300 Subject: [PATCH] events: use property, primordials PR-URL: https://github.com/nodejs/node/pull/33775 Fixes: https://github.com/nodejs/node/issues/33773 Reviewed-By: Denys Otrishko Reviewed-By: Anna Henningsen Reviewed-By: Zeyu Yang Reviewed-By: James M Snell --- lib/internal/event_target.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 3df88cedf58a3d..8c4ea11a14ed8b 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -8,6 +8,7 @@ const { Set, Symbol, NumberIsNaN, + SymbolToStringTag, } = primordials; const { @@ -67,7 +68,6 @@ class Event { // isTrusted is special (LegacyUnforgeable) Object.defineProperty(this, 'isTrusted', { get() { return false; }, - set(ignoredValue) { return false; }, enumerable: true, configurable: false }); @@ -132,10 +132,15 @@ class Event { stopPropagation() { this.#propagationStopped = true; } - - get [Symbol.toStringTag]() { return 'Event'; } } +Object.defineProperty(Event.prototype, SymbolToStringTag, { + writable: false, + enumerable: false, + configurable: true, + value: 'Event', +}); + // The listeners for an EventTarget are maintained as a linked list. // Unfortunately, the way EventTarget is defined, listeners are accounted // using the tuple [handler,capture], and even if we don't actually make @@ -305,7 +310,6 @@ class EventTarget { return `${name} ${inspect({}, opts)}`; } - get [Symbol.toStringTag]() { return 'EventTarget'; } } Object.defineProperties(EventTarget.prototype, { @@ -313,6 +317,12 @@ Object.defineProperties(EventTarget.prototype, { removeEventListener: { enumerable: true }, dispatchEvent: { enumerable: true } }); +Object.defineProperty(EventTarget.prototype, SymbolToStringTag, { + writable: false, + enumerable: false, + configurable: true, + value: 'EventTarget', +}); class NodeEventTarget extends EventTarget { static defaultMaxListeners = 10;