From f195cb41a8fd7d7e6947f22f589da7199f3b1d6f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 11 Sep 2021 15:40:26 -0400 Subject: LibJS: Convert SetIterator.prototype to be a PrototypeObject --- .../LibJS/Runtime/SetIteratorPrototype.cpp | 24 +++++++++------------- .../Libraries/LibJS/Runtime/SetIteratorPrototype.h | 7 ++++--- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'Userland/Libraries') 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 #include #include -#include #include 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(this_value.as_object())) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Set Iterator"); + auto* set_iterator = typed_this_value(global_object); + if (vm.exception()) return {}; - } - auto& set_iterator = static_cast(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 +#include +#include namespace JS { -class SetIteratorPrototype final : public Object { - JS_OBJECT(SetIteratorPrototype, Object) +class SetIteratorPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(SetIteratorPrototype, SetIterator, SetIterator); public: SetIteratorPrototype(GlobalObject&); -- cgit v1.2.3