diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index fdec91b0a4..656e892914 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -4,12 +4,14 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include #include +#include namespace JS { @@ -34,6 +36,7 @@ ArrayIteratorPrototype::~ArrayIteratorPrototype() } // 23.1.5.2.1 %ArrayIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next +// FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next. JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) { auto this_value = vm.this_value(global_object); @@ -51,8 +54,23 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) auto index = iterator.index(); auto iteration_kind = iterator.iteration_kind(); - // FIXME: Typed array check - auto length = array.indexed_properties().array_like_size(); + + size_t length; + + if (array.is_typed_array()) { + auto& typed_array = static_cast(array); + + if (typed_array.viewed_array_buffer()->is_detached()) { + vm.throw_exception(global_object, ErrorType::DetachedArrayBuffer); + return {}; + } + + length = typed_array.array_length(); + } else { + length = length_of_array_like(global_object, array); + if (vm.exception()) + return {}; + } if (index >= length) { iterator.m_array = js_undefined();