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 <[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]>
  • 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.