From 6cf3af695b61e3f75584b082afee56cc942e4c6e Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Wed, 1 Mar 2023 19:06:08 +0100 Subject: [PATCH] lib: define Event.isTrusted in the prototype Don't conform to the spec with isTrusted. The spec defines it as `LegacyUnforgeable` but defining it in the constructor has a big performance impact and the property doesn't seem to be useful outside of browsers. Refs: https://github.com/nodejs/performance/issues/32 --- lib/internal/event_target.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 60c5eb80ceabd3..fa689ef38cee01 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -119,8 +119,6 @@ class Event { isTrustedSet.add(this); } - // isTrusted is special (LegacyUnforgeable) - ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor); this[kTarget] = null; this[kIsBeingDispatched] = false; } @@ -343,6 +341,11 @@ ObjectDefineProperties( eventPhase: kEnumerableProperty, cancelBubble: kEnumerableProperty, stopPropagation: kEnumerableProperty, + // Don't conform to the spec with isTrusted. The spec defines it as + // LegacyUnforgeable but defining it in the constructor has a big + // performance impact and the property doesn't seem to be useful outside of + // browsers. + isTrusted: isTrustedDescriptor, }); function isCustomEvent(value) {