summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-11 16:03:50 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-12 01:40:56 +0200
commit4d1d0f05a9999be63821af1c3535e07fa12f1e54 (patch)
treec2bd4bdff687ba9735ca548070dcd1d727d2da94 /Userland/Libraries
parentbd4c116d081273aaea65166803c44e8f2fe46f50 (diff)
downloadserenity-4d1d0f05a9999be63821af1c3535e07fa12f1e54.zip
LibJS: Convert ArrayIterator.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h7
2 files changed, 13 insertions, 16 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
index 81ffa85a67..2b5af520c9 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
@@ -6,7 +6,6 @@
#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>
@@ -16,7 +15,7 @@
namespace JS {
ArrayIteratorPrototype::ArrayIteratorPrototype(GlobalObject& global_object)
- : Object(*global_object.iterator_prototype())
+ : PrototypeObject(*global_object.iterator_prototype())
{
}
@@ -39,21 +38,18 @@ ArrayIteratorPrototype::~ArrayIteratorPrototype()
// 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);
- if (!this_value.is_object() || !is<ArrayIterator>(this_value.as_object())) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Array Iterator");
+ auto* iterator = typed_this_value(global_object);
+ if (vm.exception())
return {};
- }
- auto& this_object = this_value.as_object();
- auto& iterator = static_cast<ArrayIterator&>(this_object);
- auto target_array = iterator.array();
+
+ auto target_array = iterator->array();
if (target_array.is_undefined())
return create_iterator_result_object(global_object, js_undefined(), true);
VERIFY(target_array.is_object());
auto& array = target_array.as_object();
- auto index = iterator.index();
- auto iteration_kind = iterator.iteration_kind();
+ auto index = iterator->index();
+ auto iteration_kind = iterator->iteration_kind();
size_t length;
@@ -73,11 +69,11 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
}
if (index >= length) {
- iterator.m_array = js_undefined();
+ iterator->m_array = js_undefined();
return create_iterator_result_object(global_object, js_undefined(), true);
}
- iterator.m_index++;
+ iterator->m_index++;
if (iteration_kind == Object::PropertyKind::Key)
return create_iterator_result_object(global_object, Value(static_cast<i32>(index)), false);
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h
index bf786ca96a..852c798c85 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h
@@ -6,12 +6,13 @@
#pragma once
-#include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/ArrayIterator.h>
+#include <LibJS/Runtime/PrototypeObject.h>
namespace JS {
-class ArrayIteratorPrototype final : public Object {
- JS_OBJECT(ArrayIteratorPrototype, Object)
+class ArrayIteratorPrototype final : public PrototypeObject<ArrayIteratorPrototype, ArrayIterator> {
+ JS_PROTOTYPE_OBJECT(ArrayIteratorPrototype, ArrayIterator, ArrayIterator);
public:
ArrayIteratorPrototype(GlobalObject&);