1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:38:10 +00:00

LibJS: Add fast path for magical "length" property in LengthOfArrayLike

For Array objects, we can avoid a generic Get here since we know it has
magical "length" behavior anyway.
This commit is contained in:
Andreas Kling 2023-12-08 12:34:42 +01:00
parent 8e5f201e59
commit 73ceb475b9
2 changed files with 5 additions and 0 deletions

View file

@ -87,6 +87,10 @@ ThrowCompletionOr<NonnullGCPtr<Object>> construct_impl(VM&, FunctionObject& func
// 7.3.19 LengthOfArrayLike ( obj ), https://tc39.es/ecma262/#sec-lengthofarraylike
ThrowCompletionOr<size_t> length_of_array_like(VM& vm, Object const& object)
{
// OPTIMIZATION: For Array objects with a magical "length" property, it should always reflect the size of indexed property storage.
if (object.has_magical_length_property())
return object.indexed_properties().array_like_size();
// 1. Return (? ToLength(? Get(obj, "length"))).
return TRY(object.get(vm.names.length)).to_length(vm);
}