Skip to content

Commit af42bc9

Browse files
addaleaxcjihrig
authored andcommitted
events: re-use the same isTrusted getter
Creating a new function each time the property descriptor is set comes with performance overhead, since these functions have different identities, even if they contain the same code. Refs: https://twitter.com/tverwaes/status/1285496612618473472 PR-URL: #34459 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 38678ef commit af42bc9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/internal/event_target.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
Map,
88
NumberIsInteger,
99
Object,
10+
ObjectDefineProperty,
1011
Symbol,
1112
SymbolFor,
1213
SymbolToStringTag,
@@ -52,6 +53,9 @@ const kTimestamp = Symbol('timestamp');
5253
const kBubbles = Symbol('bubbles');
5354
const kComposed = Symbol('composed');
5455
const kPropagationStopped = Symbol('propagationStopped');
56+
57+
const isTrusted = () => false;
58+
5559
class Event {
5660
constructor(type, options) {
5761
if (arguments.length === 0)
@@ -67,8 +71,8 @@ class Event {
6771
this[kTimestamp] = lazyNow();
6872
this[kPropagationStopped] = false;
6973
// isTrusted is special (LegacyUnforgeable)
70-
Object.defineProperty(this, 'isTrusted', {
71-
get() { return false; },
74+
ObjectDefineProperty(this, 'isTrusted', {
75+
get: isTrusted,
7276
enumerable: true,
7377
configurable: false
7478
});

0 commit comments

Comments
 (0)