Truly independent web browser
LibWeb: Stop at the end of an empty range in unique-direction getAll
Shannon Boothf8077de9944d
diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cppindex 28ab5db267c..3b2ee0583af 100644--- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp+++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp@@ -2359,7 +2359,7 @@ WebIDL::ExceptionOr<GC::Ref<JS::Array>> retrieve_multiple_items_from_an_index(JSrecords.append(range_records[0]);// 4. While i is less than rangeRecordsLength, then:- while (i < range_records_length - 1) {+ while (i + 1 < range_records_length) {// 1. Increase i by 1.i++;@@ -2400,7 +2400,7 @@ WebIDL::ExceptionOr<GC::Ref<JS::Array>> retrieve_multiple_items_from_an_index(JSrecords.append(range_records[0]);// 4. While i is less than rangeRecordsLength, then:- while (i < range_records_length - 1) {+ while (i + 1 < range_records_length) {// 1. Increase i by 1.i++;diff --git a/Tests/LibWeb/Text/expected/indexeddb-index-getall-unique-empty-range.txt b/Tests/LibWeb/Text/expected/indexeddb-index-getall-unique-empty-range.txtnew file mode 100644index 00000000000..5a3cd7eac19--- /dev/null+++ b/Tests/LibWeb/Text/expected/indexeddb-index-getall-unique-empty-range.txt@@ -0,0 +1,3 @@+nextunique, empty range: 0 records+prevunique, empty range: 0 records+nextunique, all: 2 recordsdiff --git a/Tests/LibWeb/Text/input/indexeddb-index-getall-unique-empty-range.html b/Tests/LibWeb/Text/input/indexeddb-index-getall-unique-empty-range.htmlnew file mode 100644index 00000000000..d038d2cee10--- /dev/null+++ b/Tests/LibWeb/Text/input/indexeddb-index-getall-unique-empty-range.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+asyncTest(done => {+ spoofCurrentURL("https://example.com/indexeddb-index-getall-unique-empty-range.html");++ const dbName = "test-getall-unique-empty-range-" + 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);+ };++ request.onsuccess = event => {+ const db = event.target.result;+ const index = db.transaction("store", "readonly").objectStore("store").index("byTag");+ const queries = [+ ["nextunique, empty range", { query: IDBKeyRange.only("z"), direction: "nextunique" }],+ ["prevunique, empty range", { query: IDBKeyRange.only("z"), direction: "prevunique" }],+ ["nextunique, all", { direction: "nextunique" }],+ ];+ let remaining = queries.length;+ for (const [name, options] of queries) {+ const getAll = index.getAll(options);+ getAll.onsuccess = () => {+ println(`${name}: ${getAll.result.length} records`);+ if (--remaining === 0) {+ db.close();+ indexedDB.deleteDatabase(dbName);+ done();+ }+ };+ }+ };+});+</script>