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);
}
}

View file

@ -21,6 +21,12 @@ struct IDBIndexParameters {
bool multi_entry { false };
};
struct IDBGetAllOptions {
JS::Value query { JS::js_undefined() };
Optional<WebIDL::UnsignedLong> count;
Bindings::IDBCursorDirection direction { Bindings::IDBCursorDirection::Next };
};
// https://w3c.github.io/IndexedDB/#object-store-interface
// https://w3c.github.io/IndexedDB/#object-store-handle-construct
class IDBObjectStore : public Bindings::PlatformObject {
@ -46,6 +52,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(Optional<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

@ -18,6 +18,7 @@ interface IDBObjectStore {
[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");
@ -30,3 +31,9 @@ dictionary IDBIndexParameters {
boolean unique = false;
boolean multiEntry = false;
};
dictionary IDBGetAllOptions {
any query = null;
[EnforceRange] unsigned long count;
IDBCursorDirection direction = "next";
};