diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp index bb65e5d220a..8f733da06ad 100644 --- a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp @@ -148,4 +148,18 @@ WebIDL::ExceptionOr IDBCursor::continue_(JS::Value key) return {}; } +// https://w3c.github.io/IndexedDB/#cursor-effective-key +[[nodiscard]] GC::Ref IDBCursor::effective_key() const +{ + return m_source_handle.visit( + [&](GC::Ref) -> GC::Ref { + // If the source of a cursor is an object store, the effective key of the cursor is the cursor’s position + return *m_position; + }, + [&](GC::Ref) -> GC::Ref { + // If the source of a cursor is an index, the effective key is the cursor’s object store position. + return *m_object_store_position; + }); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.h b/Libraries/LibWeb/IndexedDB/IDBCursor.h index ba0b09de8e2..712757e21df 100644 --- a/Libraries/LibWeb/IndexedDB/IDBCursor.h +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.h @@ -42,6 +42,7 @@ public: [[nodiscard]] GC::Ref transaction(); [[nodiscard]] CursorSource internal_source(); + [[nodiscard]] GC::Ref effective_key() const; void set_request(GC::Ptr request) { m_request = request; } void set_position(GC::Ptr position) { m_position = position; }