mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibWeb/IDB: Implement IDBIndex::get
This commit is contained in:
parent
73fa567e7a
commit
e74e571b56
Notes:
github-actions[bot]
2025-05-14 15:19:35 +00:00
Author: https://github.com/stelar7
Commit: e74e571b56
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4727
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/shannonbooth
7 changed files with 62 additions and 3 deletions
|
@ -141,4 +141,35 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::open_cursor(JS::Value query,
|
|||
return request;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#dom-idbindex-get
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::get(JS::Value query)
|
||||
{
|
||||
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, 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"_string);
|
||||
|
||||
// 5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
|
||||
auto range = TRY(convert_a_value_to_a_key_range(realm, query, true));
|
||||
|
||||
// 6. Let operation be an algorithm to run retrieve a referenced value from an index with the current Realm record, index, and range.
|
||||
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, index, range] -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return retrieve_a_referenced_value_from_an_index(realm, index, range);
|
||||
});
|
||||
|
||||
// 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 with uuid {}", result->uuid());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue