Truly independent web browser
LibWeb: Start each prevunique cursor iteration without a found record
Shannon Boothe460e0e55b41
diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cppindex 6ac66c90aa8..28ab5db267c 100644--- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp+++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp@@ -2038,6 +2038,7 @@ WebIDL::ExceptionOr<GC::Ptr<IDBCursor>> iterate_a_cursor(JS::Realm& realm, GC::R});// If temp record is defined, let found record be the first record in records whose key is equal to temp record’s key.+ found_record = Empty {};if (!temp_record.has<Empty>()) {auto temp_record_key = temp_record.visit([](Empty) -> GC::Ref<Key> { VERIFY_NOT_REACHED(); },diff --git a/Tests/LibWeb/Text/expected/indexeddb-cursor-prevunique-advance-past-start.txt b/Tests/LibWeb/Text/expected/indexeddb-cursor-prevunique-advance-past-start.txtnew file mode 100644index 00000000000..cc82c75c259--- /dev/null+++ b/Tests/LibWeb/Text/expected/indexeddb-cursor-prevunique-advance-past-start.txt@@ -0,0 +1,2 @@+first key: c+after advance(3): nulldiff --git a/Tests/LibWeb/Text/input/indexeddb-cursor-prevunique-advance-past-start.html b/Tests/LibWeb/Text/input/indexeddb-cursor-prevunique-advance-past-start.htmlnew file mode 100644index 00000000000..2c938cab36d--- /dev/null+++ b/Tests/LibWeb/Text/input/indexeddb-cursor-prevunique-advance-past-start.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+asyncTest(done => {+ spoofCurrentURL("https://example.com/indexeddb-cursor-prevunique-advance-past-start.html");++ const dbName = "test-prevunique-advance-past-start-" + Date.now() + Math.random();+ const request = indexedDB.open(dbName, 1);++ request.onupgradeneeded = event => {+ const store = event.target.result.createObjectStore("store");+ store.createIndex("byTag", "tag");+ store.put({ tag: "a" }, 1);+ store.put({ tag: "a" }, 2);+ store.put({ tag: "b" }, 3);+ store.put({ tag: "c" }, 4);+ };++ request.onsuccess = event => {+ const db = event.target.result;+ const index = db.transaction("store", "readonly").objectStore("store").index("byTag");+ const cursorRequest = index.openCursor(null, "prevunique");+ let step = 0;+ cursorRequest.onsuccess = () => {+ const cursor = cursorRequest.result;+ if (++step === 1) {+ println(`first key: ${cursor.key}`);+ cursor.advance(3);+ return;+ }+ println(`after advance(3): ${cursor === null ? "null" : "key " + cursor.key}`);+ db.close();+ indexedDB.deleteDatabase(dbName);+ done();+ };+ };+});+</script>