LibWeb/IDB: Implement IDBCursor::effective_key

This commit is contained in:
stelar7 2025-05-08 09:42:39 +02:00 committed by Sam Atkins
commit 141093e032
Notes: github-actions[bot] 2025-05-08 13:14:58 +00:00
2 changed files with 15 additions and 0 deletions

View file

@ -148,4 +148,18 @@ WebIDL::ExceptionOr<void> IDBCursor::continue_(JS::Value key)
return {};
}
// https://w3c.github.io/IndexedDB/#cursor-effective-key
[[nodiscard]] GC::Ref<Key> IDBCursor::effective_key() const
{
return m_source_handle.visit(
[&](GC::Ref<IDBObjectStore>) -> GC::Ref<Key> {
// If the source of a cursor is an object store, the effective key of the cursor is the cursors position
return *m_position;
},
[&](GC::Ref<IDBIndex>) -> GC::Ref<Key> {
// If the source of a cursor is an index, the effective key is the cursors object store position.
return *m_object_store_position;
});
}
}