1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 16:44:58 +00:00
serenity/Userland/Libraries/LibJS/Runtime/MapIterator.h
Ali Mohammad Pur 4a73ec07c5 LibJS: Make Map iterators independent of the underlying hashmap
This implements ordered maps as a pair of an RBTree for key order, and
an underlying unordered hash map for storage.
Fixes (part of) #11004.
2022-02-09 20:57:41 +00:00

39 lines
942 B
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <LibJS/Runtime/Map.h>
#include <LibJS/Runtime/Object.h>
namespace JS {
class MapIterator final : public Object {
JS_OBJECT(MapIterator, Object);
public:
static MapIterator* create(GlobalObject&, Map& map, Object::PropertyKind iteration_kind);
explicit MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~MapIterator() override;
Map& map() const { return m_map; }
bool done() const { return m_done; }
Object::PropertyKind iteration_kind() const { return m_iteration_kind; }
private:
friend class MapIteratorPrototype;
virtual void visit_edges(Cell::Visitor&) override;
Map& m_map;
bool m_done { false };
Object::PropertyKind m_iteration_kind;
Map::ConstIterator m_iterator;
};
}