mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb/IDB: Implement IDBIndex::get_all_records
This commit is contained in:
parent
bd25be9ed3
commit
2557e85407
Notes:
github-actions[bot]
2025-08-27 14:14:43 +00:00
Author: https://github.com/stelar7
Commit: 2557e85407
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5385
Reviewed-by: https://github.com/gmta ✅
3 changed files with 30 additions and 0 deletions
|
@ -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 this’s transaction.
|
||||
auto transaction = this->transaction();
|
||||
|
||||
// 2. Let index be this’s index.
|
||||
auto index = this->index();
|
||||
|
||||
// FIXME: 3. If index or index’s object store has been deleted, then throw an "InvalidStateError" DOMException.
|
||||
|
||||
// 4. If transaction’s 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue