lib: predeclare Event.isTrusted prop descriptor

It improves Event creation performance.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Santiago Gimeno
2023-02-08 17:51:49 +01:00
committed by GitHub
parent 8844cc42e7
commit 85c8b78104

View File

@@ -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';
}
@@ -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;
}