IDB: Some Mozilla cursor mutation tests fail
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 00:30:50 +0000 (00:30 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 00:30:50 +0000 (00:30 +0000)
commitf9cf6dacadeb6297e27ff44f3ddfc14a4db60943
treeabdec68869273569f875cb612ecebd70914422c7
parent4d7f163990b8282a583d975f1cdfcee18776fa36
IDB: Some Mozilla cursor mutation tests fail
<rdar://problem/16011680> and https://bugs.webkit.org/show_bug.cgi?id=128374

Reviewed by Sam Weinig.

Source/WebCore:

Tested by:
storage/indexeddb/mozilla/cursor-mutation-objectstore-only.html
storage/indexeddb/mozilla/cursor-mutation.html

The previous comment about LevelDB was wrong.
Apparently calling onSuccess() with a null SharedBuffer means the cursor reached the end.
Update to distinguish between an error and reaching the end:
* Modules/indexeddb/IDBCursorBackendOperations.cpp:
(WebCore::CursorAdvanceOperation::perform):
(WebCore::CursorIterationOperation::perform):

Add a new IDBKey type - Maximum - To be used in comparisons between keys.
This will allow the DatabaseProcess to operate on the range of all keys:
* Modules/indexeddb/IDBKey.cpp:
(WebCore::IDBKey::compare):
* Modules/indexeddb/IDBKey.h:

* Modules/indexeddb/IDBKeyData.cpp:
(WebCore::IDBKeyData::IDBKeyData):
(WebCore::IDBKeyData::maybeCreateIDBKey):
(WebCore::IDBKeyData::isolatedCopy):
(WebCore::IDBKeyData::encode):
(WebCore::IDBKeyData::decode):
(WebCore::IDBKeyData::compare):
(WebCore::IDBKeyData::loggingString):
* Modules/indexeddb/IDBKeyData.h:
(WebCore::IDBKeyData::minimum):
(WebCore::IDBKeyData::maximum):

* bindings/js/IDBBindingUtilities.cpp:
(WebCore::idbKeyToJSValue):

Remove an unused callback:
* Modules/indexeddb/IDBCallbacks.h:
* Modules/indexeddb/IDBRequest.h:

Source/WebKit2:

After a SQLite statement is prepared, stepping it will not pick up any subsequent changes
to the object store.

By keeping track of the current record we’re looking at in the object store and being told
that the object store changed its contents, we can reset the statement to pick up where it
left off but with the new object store contents.

* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::putRecordInBackingStore): Tell the backing store to notify
  its cursors that the object store changed its records.
(WebKit::UniqueIDBDatabase::deleteRangeInBackingStore): Ditto.

* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::notifyCursorsOfChanges): Tell the transaction
  to notify its cursors that the object store changed its records.
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:

* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp:
(WebKit::SQLiteIDBTransaction::notifyCursorsOfChanges): Tell the relevant cursors that their
  object store changed its records.
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h:

* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
(WebKit::SQLiteIDBCursor::SQLiteIDBCursor):
(WebKit::getIndexStatement): All statements now have a lower and upper range. By default we bind
  IDBKey::Minimum to the lower range and IDBKey::Maximum to the upper range.
(WebKit::getObjectStoreStatement): Ditto.
(WebKit::SQLiteIDBCursor::establishStatement):
(WebKit::SQLiteIDBCursor::createSQLiteStatement):
(WebKit::SQLiteIDBCursor::objectStoreRecordsChanged): Set the flag indicating the statement
  needs to be reset and rebound.
(WebKit::SQLiteIDBCursor::resetAndRebindStatement):
(WebKit::SQLiteIDBCursor::bindArguments): Factored out to be shared between statement prepare()
  and statement reset().
(WebKit::SQLiteIDBCursor::advance):
(WebKit::SQLiteIDBCursor::advanceOnce): If the statement needs to be reset, do so before advancing it.
(WebKit::SQLiteIDBCursor::internalAdvanceOnce): In a few cases, tell advanceOnce that it needs to
  try again because it is on a missing record or is repeating a record.
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h:
(WebKit::SQLiteIDBCursor::objectStoreID):

Make sure Maximum and Minimum keys are never sent across IPC, as that doesn’t make sense:
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<IDBKeyData>::encode):
(IPC::ArgumentCoder<IDBKeyData>::decode):

LayoutTests:

* platform/mac-wk2/TestExpectations: Add two tests that now pass.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163662 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBCallbacks.h
Source/WebCore/Modules/indexeddb/IDBCursorBackendOperations.cpp
Source/WebCore/Modules/indexeddb/IDBKey.cpp
Source/WebCore/Modules/indexeddb/IDBKey.h
Source/WebCore/Modules/indexeddb/IDBKeyData.cpp
Source/WebCore/Modules/indexeddb/IDBKeyData.h
Source/WebCore/Modules/indexeddb/IDBRequest.h
Source/WebCore/bindings/js/IDBBindingUtilities.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBTransaction.h
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp