IndexedDB: constants changing to match spec

TL;DR: To match the current IndexedDB specification, we are changing some constants in the WebKit implementation. This affects all the various openCursor()methods, IDBDatabase.transaction(), and IDBRequest.readyState. This is landed yesterday (May 7th) in WebKit and will show up in Chrome 20. We are providing a mostly backwards-compatible API and while most usage of the API will continue to work, some usage may break.

The long version:

In keeping with current Web API trends, the latest revision of the IndexedDB spec (http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html) uses string constants for certain values, where enum-like 'unsigned short' values were used previously. These values were constants defined on the relevant interface.

For instance to iterate through a store or index backwards, the legacy API call looked like:

var request = datastore.openCursor('startingkey', IDBCursor.PREV);

In this case, IDBCursor.PREV is an unsigned short with the value 2.

To use the updated API, pass a string as the second parameter:

var request = datastore.openCursor('startingkey', 'prev');

The IDBCursor.PREV constant is no longer in the specification, but we will attempt to support this pattern. The API will still accept numeric values such as 2, and the constants will still be available. We encourage active migration to the new API and expect removal of the old API in August, 2012: https://bugs.webkit.org/show_bug.cgi?id=85315

The one place that this could cause problems for you is if you also access attributes such as the readyState of a request:

if (request.readyState == IDBRequest.DONE) { // THIS WILL ALWAYS FAIL!

...

}

Here, request.readyState will return "done" or "pending".

Another example: examining the 'direction' attribute of the IDBCursor interface, for example:

In this case, cursor.direction will return the string 'prev' and this test will always fail.

Another example of this this failure is looking at the

As a temporary measure to support both new and legacy APIs, you can define the constants you need:

var NEXT = ('NEXT' in IDBCursor) ? IDBCursor.NEXT : 'next';

The above applies to the following constants:

IDBDatabase.transaction(name, mode) and IDBTransaction.mode: Mode is now a string: 'readonly', 'readwrite' or 'versionchange' though of course 'versionchange' only occurs when the database is being upgraded.