LibWeb/IDB: Implement IDBIndex::get_all_records

This commit is contained in:
stelar7 2025-07-10 11:48:49 +02:00 committed by Jelle Raaijmakers
commit 2557e85407
Notes: github-actions[bot] 2025-08-27 14:14:43 +00:00
3 changed files with 30 additions and 0 deletions

View file

@ -407,4 +407,32 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::open_key_cursor(JS::Value que
return request;
}
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::get_all_records(IDBGetAllOptions const& options)
{
auto& realm = this->realm();
// 1. Let transaction be thiss transaction.
auto transaction = this->transaction();
// 2. Let index be thiss index.
auto index = this->index();
// FIXME: 3. If index or indexs object store has been deleted, then throw an "InvalidStateError" DOMException.
// 4. If transactions state is not active, then throw a "TransactionInactiveError" DOMException.
if (!transaction->is_active())
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all records"_utf16);
// 5. Let range be the result of converting a value to a key range with options["query"]. Rethrow any exceptions.
auto range = TRY(convert_a_value_to_a_key_range(realm, options.query));
// 6. Let operation be an algorithm to run retrieve multiple items from an index with the current Realm record, index, range, "record", options["direction"], and options["count"] if given.
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, index, range, options]() -> WebIDL::ExceptionOr<JS::Value> {
return retrieve_multiple_items_from_an_index(realm, index, GC::Ref(*range), RecordKind::Record, options.direction, options.count);
});
// 7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.
return asynchronously_execute_a_request(realm, GC::Ref(*this), operation);
}
}

View file

@ -33,6 +33,7 @@ public:
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_key(JS::Value);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all_keys(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all_records(IDBGetAllOptions const&);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(JS::Value);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);

View file

@ -11,6 +11,7 @@ interface IDBIndex {
[NewObject] IDBRequest getKey(any query);
[NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllKeys(optional any query, optional [EnforceRange] unsigned long count);
[NewObject] IDBRequest getAllRecords(optional IDBGetAllOptions options = {});
[NewObject] IDBRequest count(optional any query);
[NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
[NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");