mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +00:00
LibWeb/IDB: Implement IDBObjectStore::getAllKeys
This commit is contained in:
parent
927237c736
commit
7250aa0b6b
Notes:
github-actions[bot]
2025-05-12 20:29:01 +00:00
Author: https://github.com/stelar7
Commit: 7250aa0b6b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4662
Reviewed-by: https://github.com/shannonbooth ✅
3 changed files with 33 additions and 1 deletions
|
@ -607,4 +607,35 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::open_key_cursor(JS::Val
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-getallkeys
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::get_all_keys(Optional<JS::Value> query, 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 keys"_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(query)));
|
||||||
|
|
||||||
|
// 6. Let operation be an algorithm to run retrieve multiple keys from an object store with 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_keys_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 keys with uuid {}", result->uuid());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_key(JS::Value);
|
[[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(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>);
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
||||||
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all_keys(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
|
@ -17,7 +17,7 @@ interface IDBObjectStore {
|
||||||
[NewObject] IDBRequest get(any query);
|
[NewObject] IDBRequest get(any query);
|
||||||
[NewObject] IDBRequest getKey(any query);
|
[NewObject] IDBRequest getKey(any query);
|
||||||
[NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
|
[NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
|
||||||
[FIXME, NewObject] IDBRequest getAllKeys(optional any query, optional [EnforceRange] unsigned long count);
|
[NewObject] IDBRequest getAllKeys(optional any query, optional [EnforceRange] unsigned long count);
|
||||||
[NewObject] IDBRequest count(optional any query);
|
[NewObject] IDBRequest count(optional any query);
|
||||||
[NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
[NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||||
[NewObject] IDBRequest openKeyCursor(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