summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-11 15:40:26 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-12 01:40:56 +0200
commitf195cb41a8fd7d7e6947f22f589da7199f3b1d6f (patch)
tree45cd215572febb076d934f1f4db55db88b584fe3 /Userland/Libraries
parent75d5c17aec7ae74c001d8ae8f36201717c408855 (diff)
downloadserenity-f195cb41a8fd7d7e6947f22f589da7199f3b1d6f.zip
LibJS: Convert SetIterator.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp24
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.h7
2 files changed, 14 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
index 0d8c26b430..1e4d20db8f 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp
@@ -9,13 +9,12 @@
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
-#include <LibJS/Runtime/SetIterator.h>
#include <LibJS/Runtime/SetIteratorPrototype.h>
namespace JS {
SetIteratorPrototype::SetIteratorPrototype(GlobalObject& global_object)
- : Object(*global_object.iterator_prototype())
+ : PrototypeObject(*global_object.iterator_prototype())
{
}
@@ -37,27 +36,24 @@ SetIteratorPrototype::~SetIteratorPrototype()
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
{
- auto this_value = vm.this_value(global_object);
- if (!this_value.is_object() || !is<SetIterator>(this_value.as_object())) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Set Iterator");
+ auto* set_iterator = typed_this_value(global_object);
+ if (vm.exception())
return {};
- }
- auto& set_iterator = static_cast<SetIterator&>(this_value.as_object());
- if (set_iterator.done())
+ if (set_iterator->done())
return create_iterator_result_object(global_object, js_undefined(), true);
- auto& set = set_iterator.set();
- if (set_iterator.m_iterator == set.values().end()) {
- set_iterator.m_done = true;
+ auto& set = set_iterator->set();
+ if (set_iterator->m_iterator == set.values().end()) {
+ set_iterator->m_done = true;
return create_iterator_result_object(global_object, js_undefined(), true);
}
- auto iteration_kind = set_iterator.iteration_kind();
+ auto iteration_kind = set_iterator->iteration_kind();
VERIFY(iteration_kind != Object::PropertyKind::Key);
- auto value = *set_iterator.m_iterator;
- ++set_iterator.m_iterator;
+ auto value = *set_iterator->m_iterator;
+ ++set_iterator->m_iterator;
if (iteration_kind == Object::PropertyKind::Value)
return create_iterator_result_object(global_object, value, false);
diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.h b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.h
index 29744c130c..43aff39f04 100644
--- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.h
@@ -6,12 +6,13 @@
#pragma once
-#include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/PrototypeObject.h>
+#include <LibJS/Runtime/SetIterator.h>
namespace JS {
-class SetIteratorPrototype final : public Object {
- JS_OBJECT(SetIteratorPrototype, Object)
+class SetIteratorPrototype final : public PrototypeObject<SetIteratorPrototype, SetIterator> {
+ JS_PROTOTYPE_OBJECT(SetIteratorPrototype, SetIterator, SetIterator);
public:
SetIteratorPrototype(GlobalObject&);