[Webkit-unassigned] [Bug 178995] New: IndexedDB cursors fail to iterate on non-unique indexes with updates

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Oct 29 22:04:41 PDT 2017


https://bugs.webkit.org/show_bug.cgi?id=178995

            Bug ID: 178995
           Summary: IndexedDB cursors fail to iterate on non-unique
                    indexes with updates
           Product: WebKit
           Version: Safari 11
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: New Bugs
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: philip at philipwalton.com

Created attachment 325323

  --> https://bugs.webkit.org/attachment.cgi?id=325323&action=review

The code in the description as a runnable HTML file

When using an IndexedDB object store with an index set to `unique:false`, I noticed that cursors fail to iterate fully when there's an update call involved.

STR:

1. Run the following code and notice that there are 4 items logged to the console.

```html
<script>
const createDb = () => {
  const openRequest = indexedDB.open('db', 1);
  openRequest.onupgradeneeded = (evt) => {
    const db = evt.target.result;
    const itemsStore = db.createObjectStore('items', {autoIncrement: true});
    itemsStore.createIndex('name', 'name', {unique: false});
  }
  openRequest.onsuccess = (evt) => {
    populateDb(evt.target.result);
  }
}

const populateDb = (db) => {
  const txn = db.transaction(['items'], 'readwrite');
  const itemsStore = txn.objectStore('items');

  itemsStore.add({name: 'foo', id: Math.random()});
  itemsStore.add({name: 'bar', id: Math.random()});
  itemsStore.add({name: 'foo', id: Math.random()});
  itemsStore.add({name: 'bar', id: Math.random()});

  txn.oncomplete = () => iterateOverItems(db);
}

const iterateOverItems = (db) => {
  const txn = db.transaction('items', 'readwrite');
  const itemsStore = txn.objectStore('items');
  const itemsIndex = itemsStore.index('name');

  itemsIndex.openCursor().onsuccess = (evt) => {
    const cursor = evt.target.result;
    if (cursor) {
      const {value} = cursor;
      console.log(value);

      // Uncomment this line to see that calling `.update()` causes the cursor
      // to ignore non-unique values for this index.
      // cursor.update(value);

      cursor.continue();
    } else {
      db.close();
      indexedDB.deleteDatabase('db');
    }
  }
}

createDb();
</script>
```

2. Then uncomment the line `cursor.update(value)` and run it again. Notice how only 2 values are logged to the console.

This works as expected in Chrome and Firefox, and it works when there's no update call. From my perspective it appears the presence of the update call makes the cursor behave as if the indexes are unique (which they're not).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20171030/e277aabe/attachment.html>


More information about the webkit-unassigned mailing list