Truly independent web browser
LibWeb: Return undefined from IDBCursor.primaryKey past the range's end
Shannon Bootha9b19d3ec214
diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp b/Libraries/LibWeb/IndexedDB/IDBCursor.cppindex 85b965a89dd..b5cfb0bec4c 100644--- a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp+++ b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp@@ -43,6 +43,10 @@ JS::Value IDBCursor::primary_key(JS::Realm& realm)// is inspected, until the cursor's effective key is changed. This means that if the object is modified,// those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an// object does not modify the contents of the database.+ // AD-HOC: The effective key of a cursor whose key is undefined is undefined too, as in other engines.+ if (!current_key())+ return JS::js_undefined();+auto effective_key = this->effective_key();if (m_cached_primary_key_value.key.ptr() != effective_key.ptr())m_cached_primary_key_value = { effective_key, convert_a_key_to_a_value(realm, effective_key) };diff --git a/Tests/LibWeb/Text/expected/indexeddb-cursor-key-after-end.txt b/Tests/LibWeb/Text/expected/indexeddb-cursor-key-after-end.txtnew file mode 100644index 00000000000..0b35f6297b2--- /dev/null+++ b/Tests/LibWeb/Text/expected/indexeddb-cursor-key-after-end.txt@@ -0,0 +1,2 @@+index cursor after the end: key=undefined primaryKey=undefined+object store cursor after the end: key=undefined primaryKey=undefineddiff --git a/Tests/LibWeb/Text/input/indexeddb-cursor-key-after-end.html b/Tests/LibWeb/Text/input/indexeddb-cursor-key-after-end.htmlnew file mode 100644index 00000000000..f44a2830747--- /dev/null+++ b/Tests/LibWeb/Text/input/indexeddb-cursor-key-after-end.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+asyncTest(done => {+ spoofCurrentURL("https://example.com/indexeddb-cursor-key-after-end.html");++ const dbName = "test-cursor-key-after-end-" + 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: "b" }, 2);+ };++ request.onsuccess = event => {+ const db = event.target.result;+ const store = db.transaction("store", "readonly").objectStore("store");+ const sources = [["index", store.index("byTag")], ["object store", store]];+ let remaining = sources.length;+ for (const [name, source] of sources) {+ const cursorRequest = source.openCursor();+ let cursor = null;+ cursorRequest.onsuccess = () => {+ if (cursorRequest.result) {+ cursor = cursorRequest.result;+ cursor.continue();+ return;+ }+ println(`${name} cursor after the end: key=${cursor.key} primaryKey=${cursor.primaryKey}`);+ if (--remaining === 0) {+ db.close();+ indexedDB.deleteDatabase(dbName);+ done();+ }+ };+ }+ };+});+</script>