/* * Copyright (c) 2024, stelar7 * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::IndexedDB { // https://w3c.github.io/IndexedDB/#keyrange class IDBKeyRange : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(IDBKeyRange, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(IDBKeyRange); enum class LowerOpen { No, Yes, }; enum class UpperOpen { No, Yes, }; public: virtual ~IDBKeyRange() override; [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open); [[nodiscard]] JS::Value lower() const; [[nodiscard]] JS::Value upper() const; bool lower_open() const { return m_lower_open; } bool upper_open() const { return m_upper_open; } static WebIDL::ExceptionOr> only(JS::VM&, JS::Value); static WebIDL::ExceptionOr> lower_bound(JS::VM&, JS::Value, bool); static WebIDL::ExceptionOr> upper_bound(JS::VM&, JS::Value, bool); static WebIDL::ExceptionOr> bound(JS::VM&, JS::Value, JS::Value, bool, bool); WebIDL::ExceptionOr includes(JS::Value); bool is_unbound() const { return m_lower_bound == nullptr && m_upper_bound == nullptr; } bool is_in_range(GC::Ref) const; GC::Ptr lower_key() const { return m_lower_bound; } GC::Ptr upper_key() const { return m_upper_bound; } protected: explicit IDBKeyRange(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor& visitor) override; private: // A key range has an associated lower bound (null or a key). GC::Ptr m_lower_bound; // A key range has an associated upper bound (null or a key). GC::Ptr m_upper_bound; // A key range has an associated lower open flag. Unless otherwise stated it is false. bool m_lower_open { false }; // A key range has an associated upper open flag. Unless otherwise stated it is false. bool m_upper_open { false }; }; }