2021-06-09 00:17:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-07-19 13:49:30 -07:00
|
|
|
#include <LibJS/Export.h>
|
2025-04-30 16:29:41 +03:00
|
|
|
#include <LibJS/Runtime/Iterator.h>
|
2021-06-09 00:17:17 +03:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
#include <LibJS/Runtime/Set.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2025-07-19 13:49:30 -07:00
|
|
|
class JS_API SetIterator final : public Object
|
2025-04-30 16:29:41 +03:00
|
|
|
, public BuiltinIterator {
|
2021-06-09 00:17:17 +03:00
|
|
|
JS_OBJECT(SetIterator, Object);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(SetIterator);
|
2021-06-09 00:17:17 +03:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<SetIterator> create(Realm&, Set& set, Object::PropertyKind iteration_kind);
|
2021-06-09 00:17:17 +03:00
|
|
|
|
2022-03-14 10:25:06 -06:00
|
|
|
virtual ~SetIterator() override = default;
|
2021-06-09 00:17:17 +03:00
|
|
|
|
2025-06-01 18:44:18 +02:00
|
|
|
BuiltinIterator* as_builtin_iterator_if_next_is_not_redefined(IteratorRecord const&) override;
|
2025-04-30 16:29:41 +03:00
|
|
|
ThrowCompletionOr<void> next(VM&, bool& done, Value& value) override;
|
2021-06-09 00:17:17 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SetIteratorPrototype;
|
|
|
|
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype);
|
|
|
|
|
2021-06-09 00:17:17 +03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Set> m_set;
|
2021-06-09 00:17:17 +03:00
|
|
|
bool m_done { false };
|
|
|
|
Object::PropertyKind m_iteration_kind;
|
2022-02-09 18:34:16 +03:30
|
|
|
Map::ConstIterator m_iterator;
|
2021-06-09 00:17:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|