mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb/IDB: Implement IDBIndex::open_cursor
This commit is contained in:
parent
8f876e824b
commit
63e1cc7b50
Notes:
github-actions[bot]
2025-05-08 13:14:45 +00:00
Author: https://github.com/stelar7
Commit: 63e1cc7b50
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4650
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 42 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/Bindings/IDBIndexPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/IndexedDB/IDBCursor.h>
|
||||
#include <LibWeb/IndexedDB/IDBIndex.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
@ -101,4 +102,42 @@ JS::Value IDBIndex::key_path() const
|
|||
});
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#dom-idbindex-opencursor
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::open_cursor(JS::Value query, Bindings::IDBCursorDirection direction)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Let transaction be this’s transaction.
|
||||
auto transaction = this->transaction();
|
||||
|
||||
// 2. Let index be this’s index.
|
||||
[[maybe_unused]] 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 opening cursor"_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, query));
|
||||
|
||||
// 6. Let cursor be a new cursor with its source handle set to this, undefined position, direction set to direction, got value flag set to false, undefined key and value, range set to range, and key only flag set to false.
|
||||
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, false, {}, {}, range, false);
|
||||
|
||||
// 7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
|
||||
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return WebIDL::ExceptionOr<JS::Value>(iterate_a_cursor(realm, cursor));
|
||||
});
|
||||
|
||||
// 8. Let request be the result of running asynchronously execute a request with this and operation.
|
||||
auto request = asynchronously_execute_a_request(realm, GC::Ref(*this), operation);
|
||||
|
||||
// 9. Set cursor’s request to request.
|
||||
cursor->set_request(request);
|
||||
|
||||
// 10. Return request.
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
GC::Ref<IDBTransaction> transaction() { return m_object_store_handle->transaction(); }
|
||||
GC::Ref<Index> index() { return m_index; }
|
||||
|
||||
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
||||
|
||||
protected:
|
||||
explicit IDBIndex(JS::Realm&, GC::Ref<Index>, GC::Ref<IDBObjectStore>);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
|
|
@ -12,6 +12,6 @@ interface IDBIndex {
|
|||
[FIXME, NewObject] IDBRequest getAll(optional any query, optional [EnforceRange] unsigned long count);
|
||||
[FIXME, NewObject] IDBRequest getAllKeys(optional any query, optional [EnforceRange] unsigned long count);
|
||||
[FIXME, NewObject] IDBRequest count(optional any query);
|
||||
[FIXME, NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||
[NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||
[FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue