Bug 192987 - IndexedDB: cursor.update breaks cursor.continue functionality for indexes
Summary: IndexedDB: cursor.update breaks cursor.continue functionality for indexes
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Safari 11
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-21 10:55 PST by jdscheff
Modified: 2022-02-01 11:20 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jdscheff 2018-12-21 10:55:01 PST
I'm mostly copying this bug report from https://stackoverflow.com/questions/53840474/indexeddb-cursor-does-not-get-next-record-after-update-on-ios

I ran this code in Firefox 64, Chrome 71, and Safari 11.1:

    var errorHandler = function(event) {
      console.error(event.target.error);
    };

    console.log("Deleting database...");
    var deleteRequest = indexedDB.deleteDatabase("myDatabase");
    deleteRequest.onerror = deleteRequest.onblocked = deleteRequest.onsuccess = function() {
      console.log("Opening database...");
      var openRequest = indexedDB.open("myDatabase", 1);
      openRequest.onupgradeneeded = function(event) {
        var objStore = event.target.result.createObjectStore("customers", {
          keyPath: "ID",
          autoIncrement: true
        });
        objStore.createIndex("fName", "fName", { unique: false });
        objStore.add({ fName: "James", lName: "Smith", reviewStatus: "pending" });
        objStore.add({ fName: "Tim", lName: "Jones", reviewStatus: "pending" });
        objStore.add({ fName: "James", lName: "Miller", reviewStatus: "pending" });
      };
      openRequest.onsuccess = function(event) {
        var db = event.target.result;
        var tx = db.transaction("customers", "readwrite");
        var objStore = tx.objectStore("customers");
        var index = objStore.index("fName");
        var cursorRequest = index.openCursor(IDBKeyRange.only("James"));
        cursorRequest.onsuccess = function(event2) {
          var cursor = event2.target.result;
          if (cursor) {
            var record = cursor.value;
            record.reviewStatus = "reviewed";
            console.log("Updating record...");
            cursor.update(record);
            cursor.continue();
          }
        };
        cursorRequest.onerror = errorHandler;

        tx.oncomplete = function() {
          console.log("Done!");
        };
        tx.onerror = errorHandler;
      };
      openRequest.onerror = errorHandler;
    };

In Firefox and Chrome, I get this output:

    Deleting database...
    Opening database...
    Updating record...
    Updating record...
    Done!

But in Safari I get this output:

    Deleting database...
    Opening database...
    Updating record...
    Done!

Based on my understanding of the IndexedDB spec, Safari is the one in the wrong here. Updating an object should not affect cursor.continue, especially since the update does not affect the indexed property.

Commenting out `cursor.update(record);` results in Safari producing the same output as Firefox and Chrome.
Comment 1 Radar WebKit Bug Importer 2022-02-01 11:20:31 PST
<rdar://problem/88339095>