Skip to content

Commit 1ffa8a3

Browse files
addaleaxruyadorno
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 d10fc35 commit 1ffa8a3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/internal/event_target.js

+6-2
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,
@@ -57,6 +58,9 @@ const kTimestamp = Symbol('timestamp');
5758
const kBubbles = Symbol('bubbles');
5859
const kComposed = Symbol('composed');
5960
const kPropagationStopped = Symbol('propagationStopped');
61+
62+
const isTrusted = () => false;
63+
6064
class Event {
6165
constructor(type, options) {
6266
if (arguments.length === 0)
@@ -72,8 +76,8 @@ class Event {
7276
this[kTimestamp] = lazyNow();
7377
this[kPropagationStopped] = false;
7478
// isTrusted is special (LegacyUnforgeable)
75-
Object.defineProperty(this, 'isTrusted', {
76-
get() { return false; },
79+
ObjectDefineProperty(this, 'isTrusted', {
80+
get: isTrusted,
7781
enumerable: true,
7882
configurable: false
7983
});

0 commit comments

Comments
 (0)