Skip to content

Commit 71249a6

Browse files
santigimenodanielleadams
authored andcommitted
lib: predeclare Event.isTrusted prop descriptor
It improves Event creation performance. PR-URL: #46527 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 2b80d19 commit 71249a6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/internal/event_target.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
7878
}
7979
}, 'isTrusted').get;
8080

81+
const isTrustedDescriptor = {
82+
__proto__: null,
83+
configurable: false,
84+
enumerable: true,
85+
get: isTrusted,
86+
};
87+
8188
function isEvent(value) {
8289
return typeof value?.[kType] === 'string';
8390
}
@@ -113,12 +120,7 @@ class Event {
113120
}
114121

115122
// isTrusted is special (LegacyUnforgeable)
116-
ObjectDefineProperty(this, 'isTrusted', {
117-
__proto__: null,
118-
get: isTrusted,
119-
enumerable: true,
120-
configurable: false
121-
});
123+
ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor);
122124
this[kTarget] = null;
123125
this[kIsBeingDispatched] = false;
124126
}

0 commit comments

Comments
 (0)