LibWeb/IDB: Implement clear_an_object_store

This commit is contained in:
stelar7 2025-05-08 10:04:43 +02:00 committed by Sam Atkins
commit 637f35c0eb
Notes: github-actions[bot] 2025-05-08 13:14:26 +00:00
6 changed files with 28 additions and 0 deletions

View file

@ -1840,4 +1840,19 @@ GC::Ptr<IDBCursor> iterate_a_cursor(JS::Realm& realm, GC::Ref<IDBCursor> cursor,
return cursor; return cursor;
} }
// https://w3c.github.io/IndexedDB/#clear-an-object-store
JS::Value clear_an_object_store(GC::Ref<ObjectStore> store)
{
// 1. Remove all records from store.
store->clear_records();
// 2. In all indexes which reference store, remove all records.
for (auto const& [name, index] : store->index_set()) {
index->clear_records();
}
// 3. Return undefined.
return JS::js_undefined();
}
} }

View file

@ -45,5 +45,6 @@ WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Rea
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>); JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
WebIDL::ExceptionOr<JS::Value> retrieve_a_value_from_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>); WebIDL::ExceptionOr<JS::Value> retrieve_a_value_from_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
GC::Ptr<IDBCursor> iterate_a_cursor(JS::Realm&, GC::Ref<IDBCursor>, GC::Ptr<Key> = nullptr, GC::Ptr<Key> = nullptr, u64 = 1); GC::Ptr<IDBCursor> iterate_a_cursor(JS::Realm&, GC::Ref<IDBCursor>, GC::Ptr<Key> = nullptr, GC::Ptr<Key> = nullptr, u64 = 1);
JS::Value clear_an_object_store(GC::Ref<ObjectStore>);
} }

View file

@ -71,4 +71,9 @@ HTML::SerializationRecord Index::referenced_value(IndexRecord const& index_recor
.value; .value;
} }
void Index::clear_records()
{
m_records.clear();
}
} }

View file

@ -40,6 +40,7 @@ public:
[[nodiscard]] KeyPath const& key_path() const { return m_key_path; } [[nodiscard]] KeyPath const& key_path() const { return m_key_path; }
[[nodiscard]] bool has_record_with_key(GC::Ref<Key> key); [[nodiscard]] bool has_record_with_key(GC::Ref<Key> key);
void clear_records();
HTML::SerializationRecord referenced_value(IndexRecord const& index_record) const; HTML::SerializationRecord referenced_value(IndexRecord const& index_record) const;

View file

@ -84,4 +84,9 @@ Optional<Record&> ObjectStore::first_in_range(GC::Ref<IDBKeyRange> range)
}); });
} }
void ObjectStore::clear_records()
{
m_records.clear();
}
} }

View file

@ -55,6 +55,7 @@ public:
void store_a_record(Record const& record); void store_a_record(Record const& record);
u64 count_records_in_range(GC::Ref<IDBKeyRange> range); u64 count_records_in_range(GC::Ref<IDBKeyRange> range);
Optional<Record&> first_in_range(GC::Ref<IDBKeyRange> range); Optional<Record&> first_in_range(GC::Ref<IDBKeyRange> range);
void clear_records();
protected: protected:
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;