diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index 3dcc9ada4d..470c3033ce 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -70,7 +70,16 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) if (iteration_kind == Object::PropertyKind::Key) return create_iterator_result_object(vm, Value(static_cast(index)), false); - auto value = TRY(array.get(index)); + auto value = TRY([&]() -> ThrowCompletionOr { + // OPTIMIZATION: For objects that don't interfere with indexed property access, we try looking directly at storage. + if (!array.may_interfere_with_indexed_property_access() && array.indexed_properties().has_index(index)) { + auto value = array.indexed_properties().get(index)->value; + if (!value.is_accessor()) { + return value; + } + } + return array.get(index); + }()); if (iteration_kind == Object::PropertyKind::Value) return create_iterator_result_object(vm, value, false);