<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - IndexedDB openKeyCursor() returns primaryKeys in wrong order"
   href="https://bugs.webkit.org/show_bug.cgi?id=149205">149205</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>IndexedDB openKeyCursor() returns primaryKeys in wrong order
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Nightly Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nolan&#64;nolanlawson.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=261291" name="attach_261291" title="Reproducible test case">attachment 261291</a> <a href="attachment.cgi?id=261291&amp;action=edit" title="Reproducible test case">[details]</a></span>
Reproducible test case

Let's say you create an objectStore with a primary key and a secondary key, and you insert:

{primaryKey: 'a', secondaryKey: 0}
{primaryKey: 'b', secondaryKey: 0}
{primaryKey: 'c', secondaryKey: 0}

If you then call openKeyCursor() on the secondary index, then the cursor's primaryKeys should be returned in order (since the secondary indexes are all the same).

However, in WebKit nightly 10600.8.9, r189569 I am able to get the cursor to return the primaryKeys in the wrong order, although only after a refresh. It seems like the order of the keys is being determined by the length instead of lexicographic order, but I'm not sure.

I have a reproducible test to demonstrate (also attached to this bug): <a href="http://bl.ocks.org/nolanlawson/32daf56e98904562b52d">http://bl.ocks.org/nolanlawson/32daf56e98904562b52d</a>

This bug cannot be reproduced in IE 10, Firefox 40, or Chrome 45. There is a note in the IndexedDB spec explaining this behavior:

<span class="quote">&gt; records is always sorted in ascending key order.
&gt; In the case of source being an index, records is secondarily sorted 
&gt; in ascending value order (where the value in an index is the key of 
&gt; the record in the referenced object store). </span >

Source: <a href="http://w3c.github.io/IndexedDB/#h-cursor-iteration-operation">http://w3c.github.io/IndexedDB/#h-cursor-iteration-operation</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>