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.
  • Loading branch information
santigimeno committed Feb 6, 2023
1 parent 1e9ca45 commit 7e0185e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/internal/event_target.js
Expand Up @@ -78,6 +78,13 @@ const isTrusted = ObjectGetOwnPropertyDescriptor({
}
}, 'isTrusted').get;

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

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', descriptor);
this[kTarget] = null;
this[kIsBeingDispatched] = false;
}
Expand Down

0 comments on commit 7e0185e

Please sign in to comment.