diff --git a/Libraries/LibWeb/IndexedDB/IDBIndex.cpp b/Libraries/LibWeb/IndexedDB/IDBIndex.cpp index 4392a07a965..1bb2dc009b0 100644 --- a/Libraries/LibWeb/IndexedDB/IDBIndex.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBIndex.cpp @@ -407,4 +407,32 @@ WebIDL::ExceptionOr> IDBIndex::open_key_cursor(JS::Value que return request; } +WebIDL::ExceptionOr> 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()>::create(realm.heap(), [&realm, index, range, options]() -> WebIDL::ExceptionOr { + 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); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBIndex.h b/Libraries/LibWeb/IndexedDB/IDBIndex.h index a063bdd35b5..a60d9c96701 100644 --- a/Libraries/LibWeb/IndexedDB/IDBIndex.h +++ b/Libraries/LibWeb/IndexedDB/IDBIndex.h @@ -33,6 +33,7 @@ public: [[nodiscard]] WebIDL::ExceptionOr> get_key(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> get_all(Optional, Optional); [[nodiscard]] WebIDL::ExceptionOr> get_all_keys(Optional, Optional); + [[nodiscard]] WebIDL::ExceptionOr> get_all_records(IDBGetAllOptions const&); [[nodiscard]] WebIDL::ExceptionOr> count(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); [[nodiscard]] WebIDL::ExceptionOr> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); diff --git a/Libraries/LibWeb/IndexedDB/IDBIndex.idl b/Libraries/LibWeb/IndexedDB/IDBIndex.idl index ea6f0321b15..d84dd78a4af 100644 --- a/Libraries/LibWeb/IndexedDB/IDBIndex.idl +++ b/Libraries/LibWeb/IndexedDB/IDBIndex.idl @@ -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");