indexeddb: Implement openCursor and openKeyCursor for object store (#39080)

Continue on implementing indexeddb's cursor.

This patch focuses on implementing the `openCursor` [1] and
`openKeyCursor` [2] methods of the `IDBObjectStore` interface, which
create and initialize cursors by running the iterate-a-cursor algorithm
[3].

It also adds struct `IndexedDBRecord` to
`components/shared/net/indexeddb_thread.rs`. This struct can later be
used to implement the new `IDBRecord` interface [4].

[1] https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-opencursor
[2] https://www.w3.org/TR/IndexedDB-2/#dom-idbobjectstore-openkeycursor
[3] https://www.w3.org/TR/IndexedDB-2/#iterate-a-cursor
[4] https://w3c.github.io/IndexedDB/#record-interface

Testing: Pass WPT tests that were expected to fail.
Fixes: Part of #38111

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
Kingsley Yung 2025-09-13 00:54:07 +08:00 committed by GitHub
parent 1f63116bdd
commit 250c4cda00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 580 additions and 279 deletions

View file

@ -233,6 +233,14 @@ impl IndexedDBKeyRange {
}
}
/// <https://w3c.github.io/IndexedDB/#record-snapshot>
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct IndexedDBRecord {
pub key: IndexedDBKeyType,
pub primary_key: IndexedDBKeyType,
pub value: Vec<u8>,
}
#[test]
fn test_as_singleton() {
let key = IndexedDBKeyType::Number(1.0);
@ -281,6 +289,10 @@ pub enum AsyncReadOnlyOperation {
sender: IpcSender<BackendResult<u64>>,
key_range: IndexedDBKeyRange,
},
Iterate {
sender: IpcSender<BackendResult<Vec<IndexedDBRecord>>>,
key_range: IndexedDBKeyRange,
},
}
#[derive(Debug, Deserialize, Serialize)]