/* * Copyright (c) 2020, Matthew Olsson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace JS { struct ValueAndAttributes { Value value; PropertyAttributes attributes { default_attributes }; Optional property_offset {}; void visit_edges(Cell::Visitor& visitor) { visitor.visit(value); } }; class GenericIndexedPropertyStorage { public: explicit GenericIndexedPropertyStorage() { } bool has_index(u32 index) const; Optional get(u32 index) const; void put(u32 index, Value value, PropertyAttributes attributes = default_attributes); void remove(u32 index); ValueAndAttributes take_first(); ValueAndAttributes take_last(); size_t size() const { return m_sparse_elements.size(); } size_t array_like_size() const { return m_array_size; } bool set_array_like_size(size_t new_size); void visit_edges(Cell::Visitor& visitor) { for (auto& element : m_sparse_elements) element.value.visit_edges(visitor); } HashMap const& sparse_elements() const { return m_sparse_elements; } private: size_t m_array_size { 0 }; HashMap m_sparse_elements; }; }