Skip to content

Commit

Permalink
lib: predeclare Event.isTrusted prop descriptor
Browse files Browse the repository at this point in the history
It improves Event creation performance.

PR-URL: #46527
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
santigimeno authored and MylesBorins committed Feb 18, 2023
1 parent 35570e9 commit da9ebaf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
}
}, 'isTrusted').get;

const isTrustedDescriptor = {
__proto__: null,
configurable: false,
enumerable: true,
get: isTrusted,
};

function isEvent(value) {
return typeof value?.[kType] === 'string';
}
Expand Down Expand Up @@ -113,12 +120,7 @@ class Event {
}

// isTrusted is special (LegacyUnforgeable)
ObjectDefineProperty(this, 'isTrusted', {
__proto__: null,
get: isTrusted,
enumerable: true,
configurable: false
});
ObjectDefineProperty(this, 'isTrusted', isTrustedDescriptor);
this[kTarget] = null;
this[kIsBeingDispatched] = false;
}
Expand Down

0 comments on commit da9ebaf

Please sign in to comment.