From 7e0185edfed4c44749653c43175c723c8b197419 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Mon, 6 Feb 2023 13:06:22 +0100 Subject: [PATCH] lib: predeclare Event.isTrusted prop descriptor It improves Event creation performance. --- lib/internal/event_target.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index bf51d502b17371..0b7d0dda44396b 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -78,6 +78,13 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({ } }, 'isTrusted').get; +const descriptor = { + __proto__: null, + get: isTrusted, + enumerable: true, + configurable: false +}; + function isEvent(value) { return typeof value?.[kType] === 'string'; } @@ -113,12 +120,7 @@ class Event { } // isTrusted is special (LegacyUnforgeable) - ObjectDefineProperty(this, 'isTrusted', { - __proto__: null, - get: isTrusted, - enumerable: true, - configurable: false - }); + ObjectDefineProperty(this, 'isTrusted', descriptor); this[kTarget] = null; this[kIsBeingDispatched] = false; }