LibWeb/IDB: Implement IDBObjectStore::get_all_records

This commit is contained in:
stelar7 2025-07-10 08:55:16 +02:00 committed by Jelle Raaijmakers
commit 559b9dbd83
Notes: github-actions[bot] 2025-08-27 14:15:18 +00:00
3 changed files with 42 additions and 0 deletions

View file

@ -731,4 +731,32 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::get_all_keys(Optional<J
return result;
}
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::get_all_records(IDBGetAllOptions const& options)
{
auto& realm = this->realm();
// 1. Let transaction be thiss transaction.
auto transaction = this->transaction();
// 2. Let store be thiss object store.
auto store = this->store();
// FIXME: 3. If store has been deleted, 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 object store with the current Realm record, store, range, "record", options["direction"], and options["count"] if given.
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, store, range, options] -> WebIDL::ExceptionOr<JS::Value> {
return retrieve_multiple_items_from_an_object_store(realm, store, 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);
}
}