mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibWeb/IDB: Implement IDBObjectStore::getAll
This commit is contained in:
Notes:
github-actions[bot]
2025-05-12 20:29:30 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/c700bfaaf18 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4662 Reviewed-by: https://github.com/shannonbooth ✅
@@ -537,4 +537,35 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::get_key(JS::Value query
|
||||
return result;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-getall
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::get_all(Optional<JS::Value> value, Optional<WebIDL::UnsignedLong> count)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Let transaction be this’s transaction.
|
||||
auto transaction = this->transaction();
|
||||
|
||||
// 2. Let store be this’s object store.
|
||||
auto store = this->store();
|
||||
|
||||
// FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException.
|
||||
|
||||
// 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
||||
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all"_string);
|
||||
|
||||
// 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
|
||||
auto range = TRY(convert_a_value_to_a_key_range(realm, move(value)));
|
||||
|
||||
// 6. Let operation be an algorithm to run retrieve multiple values from an object store with the current Realm record, store, range, and count if given.
|
||||
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, store, range, count] -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return retrieve_multiple_values_from_an_object_store(realm, store, range, count);
|
||||
});
|
||||
|
||||
// 7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.
|
||||
auto result = asynchronously_execute_a_request(realm, GC::Ref(*this), operation);
|
||||
dbgln_if(IDB_DEBUG, "Executing request for get all with uuid {}", result->uuid());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user