2021-06-12 23:58:03 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-04-30 16:29:41 +03:00
|
|
|
#include <LibJS/Runtime/Iterator.h>
|
2021-06-12 23:58:03 +03:00
|
|
|
#include <LibJS/Runtime/Map.h>
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2025-06-28 21:39:13 -07:00
|
|
|
class JS_API MapIterator final : public Object
|
2025-04-30 16:29:41 +03:00
|
|
|
, public BuiltinIterator {
|
2021-06-12 23:58:03 +03:00
|
|
|
JS_OBJECT(MapIterator, Object);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(MapIterator);
|
2021-06-12 23:58:03 +03:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<MapIterator> create(Realm&, Map& map, Object::PropertyKind iteration_kind);
|
2021-06-12 23:58:03 +03:00
|
|
|
|
2022-03-14 10:25:06 -06:00
|
|
|
virtual ~MapIterator() override = default;
|
2021-06-12 23:58:03 +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-12 23:58:03 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class MapIteratorPrototype;
|
|
|
|
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype);
|
|
|
|
|
2021-06-12 23:58:03 +03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Map> m_map;
|
2021-06-12 23:58:03 +03:00
|
|
|
bool m_done { false };
|
|
|
|
Object::PropertyKind m_iteration_kind;
|
2022-02-09 16:34:52 +03:30
|
|
|
Map::ConstIterator m_iterator;
|
2021-06-12 23:58:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|