diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index add4249869..277838e63c 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -9,13 +9,12 @@ #include #include #include -#include #include namespace JS { StringIteratorPrototype::StringIteratorPrototype(GlobalObject& global_object) - : Object(*global_object.iterator_prototype()) + : PrototypeObject(*global_object.iterator_prototype()) { } @@ -36,21 +35,17 @@ StringIteratorPrototype::~StringIteratorPrototype() // 22.1.5.1.1 %StringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::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, "String Iterator"); + auto* iterator = typed_this_value(global_object); + if (vm.exception()) return {}; - } - auto& this_object = this_value.as_object(); - auto& iterator = static_cast(this_object); - if (iterator.done()) + if (iterator->done()) return create_iterator_result_object(global_object, js_undefined(), true); - auto& utf8_iterator = iterator.iterator(); + auto& utf8_iterator = iterator->iterator(); if (utf8_iterator.done()) { - iterator.m_done = true; + iterator->m_done = true; return create_iterator_result_object(global_object, js_undefined(), true); } diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.h b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.h index 1ba336e32d..9fc892c85d 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.h @@ -7,11 +7,13 @@ #pragma once #include +#include +#include namespace JS { -class StringIteratorPrototype final : public Object { - JS_OBJECT(StringIteratorPrototype, Object) +class StringIteratorPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(StringIteratorPrototype, StringIterator, StringIterator); public: StringIteratorPrototype(GlobalObject&);