diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp index 455429a414..46623408ef 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp @@ -9,13 +9,12 @@ #include #include #include -#include #include namespace JS { MapIteratorPrototype::MapIteratorPrototype(GlobalObject& global_object) - : Object(*global_object.iterator_prototype()) + : PrototypeObject(*global_object.iterator_prototype()) { } @@ -35,26 +34,23 @@ MapIteratorPrototype::~MapIteratorPrototype() // 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::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, "Map Iterator"); + auto* map_iterator = typed_this_value(global_object); + if (vm.exception()) return {}; - } - auto& map_iterator = static_cast(this_value.as_object()); - if (map_iterator.done()) + if (map_iterator->done()) return create_iterator_result_object(global_object, js_undefined(), true); - auto& map = map_iterator.map(); - if (map_iterator.m_iterator == map.entries().end()) { - map_iterator.m_done = true; + auto& map = map_iterator->map(); + if (map_iterator->m_iterator == map.entries().end()) { + map_iterator->m_done = true; return create_iterator_result_object(global_object, js_undefined(), true); } - auto iteration_kind = map_iterator.iteration_kind(); + auto iteration_kind = map_iterator->iteration_kind(); - auto entry = *map_iterator.m_iterator; - ++map_iterator.m_iterator; + auto entry = *map_iterator->m_iterator; + ++map_iterator->m_iterator; if (iteration_kind == Object::PropertyKind::Key) return create_iterator_result_object(global_object, entry.key, false); else if (iteration_kind == Object::PropertyKind::Value) diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.h b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.h index f35ffb374b..730e3334aa 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.h @@ -6,12 +6,13 @@ #pragma once -#include +#include +#include namespace JS { -class MapIteratorPrototype final : public Object { - JS_OBJECT(MapIteratorPrototype, Object) +class MapIteratorPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(MapIteratorPrototype, MapIterator, MapIterator); public: MapIteratorPrototype(GlobalObject&);