diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 65d840a152..c3d12c3855 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -87,6 +87,10 @@ ThrowCompletionOr> construct_impl(VM&, FunctionObject& func // 7.3.19 LengthOfArrayLike ( obj ), https://tc39.es/ecma262/#sec-lengthofarraylike ThrowCompletionOr 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); } diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 9b8de50445..d92ae61f4a 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -224,6 +224,7 @@ public: static FlatPtr may_interfere_with_indexed_property_access_offset() { return OFFSET_OF(Object, m_may_interfere_with_indexed_property_access); } static FlatPtr indexed_properties_offset() { return OFFSET_OF(Object, m_indexed_properties); } + [[nodiscard]] bool has_magical_length_property() const { return m_has_magical_length_property; } static FlatPtr has_magical_length_property_offset() { return OFFSET_OF(Object, m_has_magical_length_property); } [[nodiscard]] bool is_typed_array() const { return m_is_typed_array; }