diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index 848d5374efa..64e05ddc884 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -1308,4 +1308,15 @@ void inject_a_key_into_a_value_using_a_key_path(JS::Realm& realm, JS::Value valu VERIFY(status); } +// https://w3c.github.io/IndexedDB/#delete-records-from-an-object-store +void delete_records_from_an_object_store(GC::Ref store, GC::Ref range) +{ + // 1. Remove all records, if any, from store’s list of records with key in range. + store->remove_records_in_range(range); + + // FIXME: 2. For each index which references store, remove every record from index’s list of records whose value is in range, if any such records exist. + + // 3. Return undefined. +} + } diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h index 736a2f81c73..29ae317ae31 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h @@ -39,5 +39,6 @@ GC::Ref asynchronously_execute_a_request(JS::Realm&, IDBRequestSourc ErrorOr generate_a_key(GC::Ref); void possibly_update_the_key_generator(GC::Ref, GC::Ref); void inject_a_key_into_a_value_using_a_key_path(JS::Realm&, JS::Value, GC::Ref, KeyPath const&); +void delete_records_from_an_object_store(GC::Ref, GC::Ref); } diff --git a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp index 3fe00e26cd2..e79c1217da0 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include namespace Web::IndexedDB { @@ -33,6 +34,17 @@ void ObjectStore::visit_edges(Visitor& visitor) Base::visit_edges(visitor); visitor.visit(m_database); visitor.visit(m_indexes); + + for (auto& record : m_records) { + visitor.visit(record.key); + } +} + +void ObjectStore::remove_records_in_range(GC::Ref range) +{ + m_records.remove_all_matching([&](auto const& record) { + return range->is_in_range(record.key); + }); } } diff --git a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h index 810c33eb8fb..bda33d6a098 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h +++ b/Libraries/LibWeb/IndexedDB/Internal/ObjectStore.h @@ -23,6 +23,12 @@ namespace Web::IndexedDB { using KeyPath = Variant>; +// https://w3c.github.io/IndexedDB/#object-store-record +struct Record { + GC::Ref key; + HTML::SerializationRecord value; +}; + // https://w3c.github.io/IndexedDB/#object-store-construct class ObjectStore : public JS::Cell { GC_CELL(ObjectStore, JS::Cell); @@ -42,6 +48,8 @@ public: GC::Ref database() const { return m_database; } + void remove_records_in_range(GC::Ref range); + protected: virtual void visit_edges(Visitor&) override; @@ -62,6 +70,9 @@ private: // An object store optionally has a key generator. Optional m_key_generator; + + // An object store has a list of records + Vector m_records; }; }