mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
LibWeb/IDB: Implement count_the_records_in_a_range
This commit is contained in:
parent
64d251b36c
commit
694375d3ac
Notes:
github-actions[bot]
2025-04-29 15:07:58 +00:00
Author: https://github.com/stelar7
Commit: 694375d3ac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4505
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
4 changed files with 22 additions and 0 deletions
|
@ -1448,4 +1448,14 @@ WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Rea
|
||||||
return IDBKeyRange::create(realm, key, key, false, false);
|
return IDBKeyRange::create(realm, key, key, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
// 1. Let count be the number of records, if any, in source’s list of records with key in range.
|
||||||
|
auto count = source->count_records_in_range(range);
|
||||||
|
|
||||||
|
// 2. Return count.
|
||||||
|
return JS::Value(count);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,5 +42,6 @@ void inject_a_key_into_a_value_using_a_key_path(JS::Realm&, JS::Value, GC::Ref<K
|
||||||
void delete_records_from_an_object_store(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
void delete_records_from_an_object_store(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||||
WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, JS::Value, GC::Ptr<Key>, bool);
|
WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, JS::Value, GC::Ptr<Key>, bool);
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm&, Optional<JS::Value>, bool = false);
|
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm&, Optional<JS::Value>, bool = false);
|
||||||
|
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,4 +67,14 @@ void ObjectStore::store_a_record(Record const& record)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 ObjectStore::count_records_in_range(GC::Ref<IDBKeyRange> range)
|
||||||
|
{
|
||||||
|
u64 count = 0;
|
||||||
|
for (auto const& record : m_records) {
|
||||||
|
if (range->is_in_range(record.key))
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
void remove_records_in_range(GC::Ref<IDBKeyRange> range);
|
void remove_records_in_range(GC::Ref<IDBKeyRange> range);
|
||||||
bool has_record_with_key(GC::Ref<Key> key);
|
bool has_record_with_key(GC::Ref<Key> key);
|
||||||
void store_a_record(Record const& record);
|
void store_a_record(Record const& record);
|
||||||
|
u64 count_records_in_range(GC::Ref<IDBKeyRange> range);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue