mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
LibJS: Convert SetIterator.prototype to be a PrototypeObject
This commit is contained in:
parent
75d5c17aec
commit
f195cb41a8
2 changed files with 14 additions and 17 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/SetIterator.h>
|
|
||||||
#include <LibJS/Runtime/SetIteratorPrototype.h>
|
#include <LibJS/Runtime/SetIteratorPrototype.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
SetIteratorPrototype::SetIteratorPrototype(GlobalObject& global_object)
|
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
|
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next
|
||||||
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
auto this_value = vm.this_value(global_object);
|
auto* set_iterator = typed_this_value(global_object);
|
||||||
if (!this_value.is_object() || !is<SetIterator>(this_value.as_object())) {
|
if (vm.exception())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Set Iterator");
|
|
||||||
return {};
|
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);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
|
|
||||||
auto& set = set_iterator.set();
|
auto& set = set_iterator->set();
|
||||||
if (set_iterator.m_iterator == set.values().end()) {
|
if (set_iterator->m_iterator == set.values().end()) {
|
||||||
set_iterator.m_done = true;
|
set_iterator->m_done = true;
|
||||||
return create_iterator_result_object(global_object, js_undefined(), 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);
|
VERIFY(iteration_kind != Object::PropertyKind::Key);
|
||||||
|
|
||||||
auto value = *set_iterator.m_iterator;
|
auto value = *set_iterator->m_iterator;
|
||||||
++set_iterator.m_iterator;
|
++set_iterator->m_iterator;
|
||||||
if (iteration_kind == Object::PropertyKind::Value)
|
if (iteration_kind == Object::PropertyKind::Value)
|
||||||
return create_iterator_result_object(global_object, value, false);
|
return create_iterator_result_object(global_object, value, false);
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/PrototypeObject.h>
|
||||||
|
#include <LibJS/Runtime/SetIterator.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
class SetIteratorPrototype final : public Object {
|
class SetIteratorPrototype final : public PrototypeObject<SetIteratorPrototype, SetIterator> {
|
||||||
JS_OBJECT(SetIteratorPrototype, Object)
|
JS_PROTOTYPE_OBJECT(SetIteratorPrototype, SetIterator, SetIterator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SetIteratorPrototype(GlobalObject&);
|
SetIteratorPrototype(GlobalObject&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue