summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLuke <luke.wilde@live.co.uk>2021-06-26 00:58:33 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-26 13:32:53 +0100
commit293974c1cbc094d63e6a036cdbd55b212f0420a1 (patch)
tree4c8585761986e62089cf1f704a561f528f3d364d /Userland/Libraries/LibJS/Runtime
parent787f80d11402ba6ef2f53b6fc7e5d78ad652e12b (diff)
downloadserenity-293974c1cbc094d63e6a036cdbd55b212f0420a1.zip
LibJS: Add TypedArray support to ArrayIterator
ArrayIteratorPrototype::next seems to implement CreateArrayIterator, which is an issue for a separate PR.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp22
1 files changed, 20 insertions, 2 deletions
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 <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayIterator.h>
#include <LibJS/Runtime/ArrayIteratorPrototype.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
+#include <LibJS/Runtime/TypedArray.h>
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<TypedArrayBase&>(array);
+
+ if (typed_array.viewed_array_buffer()->is_detached()) {
+ vm.throw_exception<TypeError>(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();