mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
LibJS: Convert StringIterator.prototype to be a PrototypeObject
This commit is contained in:
parent
f195cb41a8
commit
be0880fb2c
2 changed files with 10 additions and 13 deletions
|
@ -9,13 +9,12 @@
|
||||||
#include <LibJS/Runtime/Error.h>
|
#include <LibJS/Runtime/Error.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/IteratorOperations.h>
|
#include <LibJS/Runtime/IteratorOperations.h>
|
||||||
#include <LibJS/Runtime/StringIterator.h>
|
|
||||||
#include <LibJS/Runtime/StringIteratorPrototype.h>
|
#include <LibJS/Runtime/StringIteratorPrototype.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
StringIteratorPrototype::StringIteratorPrototype(GlobalObject& global_object)
|
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
|
// 22.1.5.1.1 %StringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto this_value = vm.this_value(global_object);
|
auto* iterator = typed_this_value(global_object);
|
||||||
if (!this_value.is_object() || !is<StringIterator>(this_value.as_object())) {
|
if (vm.exception())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "String Iterator");
|
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
auto& this_object = this_value.as_object();
|
if (iterator->done())
|
||||||
auto& iterator = static_cast<StringIterator&>(this_object);
|
|
||||||
if (iterator.done())
|
|
||||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
|
|
||||||
auto& utf8_iterator = iterator.iterator();
|
auto& utf8_iterator = iterator->iterator();
|
||||||
|
|
||||||
if (utf8_iterator.done()) {
|
if (utf8_iterator.done()) {
|
||||||
iterator.m_done = true;
|
iterator->m_done = true;
|
||||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/Object.h>
|
||||||
|
#include <LibJS/Runtime/PrototypeObject.h>
|
||||||
|
#include <LibJS/Runtime/StringIterator.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
class StringIteratorPrototype final : public Object {
|
class StringIteratorPrototype final : public PrototypeObject<StringIteratorPrototype, StringIterator> {
|
||||||
JS_OBJECT(StringIteratorPrototype, Object)
|
JS_PROTOTYPE_OBJECT(StringIteratorPrototype, StringIterator, StringIterator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StringIteratorPrototype(GlobalObject&);
|
StringIteratorPrototype(GlobalObject&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue