Skip to content

Commit

Permalink
events: re-use the same isTrusted getter
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
addaleax authored and ruyadorno committed Jul 29, 2020
1 parent 0aa3809 commit d90967b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
Map,
NumberIsInteger,
Object,
ObjectDefineProperty,
Symbol,
SymbolFor,
SymbolToStringTag,
Expand Down Expand Up @@ -57,6 +58,9 @@ const kTimestamp = Symbol('timestamp');
const kBubbles = Symbol('bubbles');
const kComposed = Symbol('composed');
const kPropagationStopped = Symbol('propagationStopped');

const isTrusted = () => false;

class Event {
constructor(type, options) {
if (arguments.length === 0)
Expand All @@ -72,8 +76,8 @@ class Event {
this[kTimestamp] = lazyNow();
this[kPropagationStopped] = false;
// isTrusted is special (LegacyUnforgeable)
Object.defineProperty(this, 'isTrusted', {
get() { return false; },
ObjectDefineProperty(this, 'isTrusted', {
get: isTrusted,
enumerable: true,
configurable: false
});
Expand Down

0 comments on commit d90967b

Please sign in to comment.