LibWeb/IDB: Implement IDBIndex::count

This commit is contained in:
stelar7 2025-05-13 22:54:08 +02:00 committed by Jelle Raaijmakers
parent b8bb8345a9
commit 852323009f
Notes: github-actions[bot] 2025-05-14 15:19:13 +00:00
7 changed files with 54 additions and 4 deletions

View file

@ -1453,10 +1453,16 @@ WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Rea
}
// https://w3c.github.io/IndexedDB/#count-the-records-in-a-range
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore> source, GC::Ref<IDBKeyRange> range)
JS::Value count_the_records_in_a_range(RecordSource source, GC::Ref<IDBKeyRange> range)
{
// 1. Let count be the number of records, if any, in sources list of records with key in range.
auto count = source->count_records_in_range(range);
auto count = source.visit(
[range](GC::Ref<ObjectStore> object_store) {
return object_store->count_records_in_range(range);
},
[range](GC::Ref<Index> index) {
return index->count_records_in_range(range);
});
// 2. Return count.
return JS::Value(count);