Modern IDB: Support IDBObjectStore.createIndex in the SQLite backing store.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Jan 2016 23:42:11 +0000 (23:42 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 24 Jan 2016 23:42:11 +0000 (23:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153410

Reviewed by Darin Adler.

Source/WebCore:

No new tests (Covered by unskipping many existing tests).

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::~SQLiteIDBBackingStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord):
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:

* Modules/indexeddb/server/SQLiteIDBCursor.cpp:
(WebCore::IDBServer::SQLiteIDBCursor::maybeCreateBackingStoreCursor):
(WebCore::IDBServer::SQLiteIDBCursor::SQLiteIDBCursor):
* Modules/indexeddb/server/SQLiteIDBCursor.h:

* Modules/indexeddb/server/SQLiteIDBTransaction.cpp:
(WebCore::IDBServer::SQLiteIDBTransaction::maybeOpenBackingStoreCursor):
* Modules/indexeddb/server/SQLiteIDBTransaction.h:

LayoutTests:

* platform/mac-wk1/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195517 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/mac-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h
Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.h

index 5062f1d2d21fd42f94bcbbbdd4b7d4b0ca61bc99..dd816eded05095a3dab0bedc76c65d6b5bd5a0f2 100644 (file)
@@ -1,3 +1,12 @@
+2016-01-24  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Support IDBObjectStore.createIndex in the SQLite backing store.
+        https://bugs.webkit.org/show_bug.cgi?id=153410
+
+        Reviewed by Darin Adler.
+
+        * platform/mac-wk1/TestExpectations:
+
 2016-01-24  Simon Fraser  <simon.fraser@apple.com>
 
         Make the dumped display list representation a bit more compact
index 1f38704515bfb1fd42d8953f240b2d8a2b413ad6..a96e6a316325b2a97bdd0dd192ad81c1da18736d 100644 (file)
@@ -439,7 +439,6 @@ imported/w3c/indexeddb/transaction_bubble-and-capture.htm [ Failure ]
 imported/w3c/indexeddb/value.htm [ Failure ]
 imported/w3c/indexeddb/value_recursive.htm [ Failure ]
 imported/w3c/indexeddb/writer-starvation.htm [ Failure ]
-storage/indexeddb/createIndex-after-failure.html [ Failure ]
 storage/indexeddb/cursor-added-bug.html [ Failure ]
 storage/indexeddb/cursor-advance.html [ Failure ]
 storage/indexeddb/cursor-basics.html [ Failure ]
@@ -460,13 +459,10 @@ storage/indexeddb/cursor-skip-deleted.html [ Failure ]
 storage/indexeddb/cursor-update-value-argument-required.html [ Failure ]
 storage/indexeddb/cursor-update.html [ Failure ]
 storage/indexeddb/cursor-value.html [ Failure ]
-storage/indexeddb/database-wrapper.html [ Failure ]
 storage/indexeddb/delete-range.html [ Failure ]
-storage/indexeddb/deleteIndex.html [ Failure ]
 storage/indexeddb/deleted-objects.html [ Failure ]
 storage/indexeddb/duplicates.html [ Failure ]
 storage/indexeddb/exceptions.html [ Failure ]
-storage/indexeddb/factory-deletedatabase.html [ Failure ]
 storage/indexeddb/get-keyrange.html [ Failure ]
 storage/indexeddb/index-basics.html [ Failure ]
 storage/indexeddb/index-count.html [ Failure ]
@@ -484,12 +480,7 @@ storage/indexeddb/keypath-fetch-key.html [ Failure ]
 storage/indexeddb/keypath-intrinsic-properties.html [ Failure ]
 storage/indexeddb/lazy-index-population.html [ Failure ]
 storage/indexeddb/lazy-index-types.html [ Failure ]
-storage/indexeddb/list-ordering.html [ Failure ]
-storage/indexeddb/metadata-race.html [ Failure ]
-storage/indexeddb/metadata.html [ Failure ]
-storage/indexeddb/modern/abort-objectstore-info.html [ Failure ]
 storage/indexeddb/modern/autoincrement-abort.html [ Failure ]
-storage/indexeddb/modern/create-index-failures.html [ Failure ]
 storage/indexeddb/modern/cursor-1.html [ Failure ]
 storage/indexeddb/modern/cursor-2.html [ Failure ]
 storage/indexeddb/modern/cursor-3.html [ Failure ]
@@ -500,9 +491,7 @@ storage/indexeddb/modern/cursor-7.html [ Failure ]
 storage/indexeddb/modern/cursor-8.html [ Failure ]
 storage/indexeddb/modern/deleteindex-1.html [ Failure ]
 storage/indexeddb/modern/deleteindex-2.html [ Failure ]
-storage/indexeddb/modern/get-index-failures.html [ Failure ]
 storage/indexeddb/modern/get-keyrange.html [ Failure ]
-storage/indexeddb/modern/idbindex-properties-basic.html [ Failure ]
 storage/indexeddb/modern/idbobjectstore-clear-1.html [ Failure ]
 storage/indexeddb/modern/idbobjectstore-clear-2.html [ Failure ]
 storage/indexeddb/modern/idbobjectstore-count-1.html [ Failure ]
@@ -516,16 +505,11 @@ storage/indexeddb/modern/index-cursor-2.html [ Failure ]
 storage/indexeddb/modern/index-cursor-3.html [ Failure ]
 storage/indexeddb/modern/index-get-count-basic.html [ Failure ]
 storage/indexeddb/modern/index-get-count-failures.html [ Failure ]
-storage/indexeddb/modern/memory-index-not-deleted-with-objectstore.html [ Failure ]
-storage/indexeddb/modern/objectstore-attributes.html [ Failure ]
 storage/indexeddb/modern/objectstore-cursor-advance-failures.html [ Failure ]
 storage/indexeddb/modern/objectstore-cursor-continue-failures.html [ Failure ]
-storage/indexeddb/modern/opencursor-failures.html [ Failure ]
 storage/indexeddb/modern/request-readystate.html [ Failure ]
-storage/indexeddb/modern/transactions-stop-on-navigation.html [ Failure ]
 storage/indexeddb/mozilla/autoincrement-indexes.html [ Failure ]
 storage/indexeddb/mozilla/clear.html [ Failure ]
-storage/indexeddb/mozilla/create-index-with-integer-keys.html [ Failure ]
 storage/indexeddb/mozilla/cursor-mutation-objectstore-only.html [ Failure ]
 storage/indexeddb/mozilla/cursor-mutation.html [ Failure ]
 storage/indexeddb/mozilla/cursor-update-updates-indexes.html [ Failure ]
@@ -536,7 +520,6 @@ storage/indexeddb/mozilla/index-prev-no-duplicate.html [ Failure ]
 storage/indexeddb/mozilla/indexes.html [ Failure ]
 storage/indexeddb/mozilla/key-requirements.html [ Failure ]
 storage/indexeddb/mozilla/object-cursors.html [ Failure ]
-storage/indexeddb/mozilla/object-identity.html [ Failure ]
 storage/indexeddb/mozilla/object-store-inline-autoincrement-key-added-on-put.html [ Failure ]
 storage/indexeddb/mozilla/object-store-remove-values.html [ Failure ]
 storage/indexeddb/mozilla/odd-result-order.html [ Failure ]
@@ -549,18 +532,12 @@ storage/indexeddb/objectstore-basics.html [ Failure ]
 storage/indexeddb/objectstore-clear.html [ Failure ]
 storage/indexeddb/objectstore-count.html [ Failure ]
 storage/indexeddb/objectstore-cursor.html [ Failure ]
-storage/indexeddb/objectstore-removeobjectstore.html [ Failure ]
 storage/indexeddb/open-cursor.html [ Failure ]
 storage/indexeddb/opencursor-key.html [ Failure ]
 storage/indexeddb/optional-arguments.html [ Failure ]
 storage/indexeddb/prefetch-bugfix-108071.html [ Failure ]
-storage/indexeddb/queued-commands.html [ Failure ]
 storage/indexeddb/readonly.html [ Failure ]
-storage/indexeddb/structured-clone.html [ Failure ]
 storage/indexeddb/transaction-active-flag.html [ Failure ]
-storage/indexeddb/transaction-and-objectstore-calls.html [ Failure ]
-storage/indexeddb/transaction-basics.html [ Failure ]
-storage/indexeddb/transaction-error.html [ Failure ]
 storage/indexeddb/transaction-rollback.html [ Failure ]
 storage/indexeddb/value-undefined.html [ Failure ]
 storage/indexeddb/values-odd-types.html [ Failure ]
index 856b2af4101d3938be6543ea8028750550d29bac..44b193dffdecf0ee681591f3c6723beb8df76a3f 100644 (file)
@@ -1,3 +1,28 @@
+2016-01-24  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Support IDBObjectStore.createIndex in the SQLite backing store.
+        https://bugs.webkit.org/show_bug.cgi?id=153410
+
+        Reviewed by Darin Adler.
+
+        No new tests (Covered by unskipping many existing tests).
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::~SQLiteIDBBackingStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::createIndex):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedHasIndexRecord):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::uncheckedPutIndexRecord):
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+
+        * Modules/indexeddb/server/SQLiteIDBCursor.cpp:
+        (WebCore::IDBServer::SQLiteIDBCursor::maybeCreateBackingStoreCursor):
+        (WebCore::IDBServer::SQLiteIDBCursor::SQLiteIDBCursor):
+        * Modules/indexeddb/server/SQLiteIDBCursor.h:
+
+        * Modules/indexeddb/server/SQLiteIDBTransaction.cpp:
+        (WebCore::IDBServer::SQLiteIDBTransaction::maybeOpenBackingStoreCursor):
+        * Modules/indexeddb/server/SQLiteIDBTransaction.h:
+
 2016-01-24  Simon Fraser  <simon.fraser@apple.com>
 
         Make the dumped display list representation a bit more compact
index b482af1da5714df24cb5dbf0bce510aea4ec657e..17f266d71a5fc2b5d9b1fe147b7bf1e670c962c0 100644 (file)
@@ -118,6 +118,11 @@ SQLiteIDBBackingStore::~SQLiteIDBBackingStore()
 {
     if (m_sqliteDB)
         m_sqliteDB->close();
+
+    if (m_vm) {
+        JSLockHolder locker(m_vm.get());
+        m_vm = nullptr;
+    }
 }
 
 static bool createOrMigrateRecordsTableIfNecessary(SQLiteDatabase& database)
@@ -678,11 +683,171 @@ IDBError SQLiteIDBBackingStore::clearObjectStore(const IDBResourceIdentifier& tr
     return { };
 }
 
-IDBError SQLiteIDBBackingStore::createIndex(const IDBResourceIdentifier&, const IDBIndexInfo&)
+IDBError SQLiteIDBBackingStore::createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo& info)
 {
-    return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    auto* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction->inProgress()) {
+        LOG_ERROR("Attempt to create an index without an in-progress transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to create an index without an in-progress transaction") };
+    }
+    if (transaction->mode() != IndexedDB::TransactionMode::VersionChange) {
+        LOG_ERROR("Attempt to create an index in a non-version-change transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to create an index in a non-version-change transaction") };
+    }
+
+    RefPtr<SharedBuffer> keyPathBlob = serializeIDBKeyPath(info.keyPath());
+    if (!keyPathBlob) {
+        LOG_ERROR("Unable to serialize IDBKeyPath to save in database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to serialize IDBKeyPath to create index in database") };
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO IndexInfo VALUES (?, ?, ?, ?, ?, ?);"));
+    if (sql.prepare() != SQLITE_OK
+        || sql.bindInt64(1, info.identifier()) != SQLITE_OK
+        || sql.bindText(2, info.name()) != SQLITE_OK
+        || sql.bindInt64(3, info.objectStoreIdentifier()) != SQLITE_OK
+        || sql.bindBlob(4, keyPathBlob->data(), keyPathBlob->size()) != SQLITE_OK
+        || sql.bindInt(5, info.unique()) != SQLITE_OK
+        || sql.bindInt(6, info.multiEntry()) != SQLITE_OK
+        || sql.step() != SQLITE_DONE) {
+        LOG_ERROR("Could not add index '%s' to IndexInfo table (%i) - %s", info.name().utf8().data(), m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to create index in database") };
+    }
+
+    // Write index records for any records that already exist in this object store.
+
+    auto cursor = transaction->maybeOpenBackingStoreCursor(info.objectStoreIdentifier());
+
+    if (!cursor) {
+        LOG_ERROR("Cannot open cursor to populate indexes in database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to populate indexes in database") };
+    }
+
+    if (!m_vm) {
+        ASSERT(!m_globalObject);
+        m_vm = VM::create();
+    }
+
+    JSLockHolder locker(m_vm.get());
+
+    if (!m_globalObject)
+        m_globalObject.set(*m_vm, JSGlobalObject::create(*m_vm, JSGlobalObject::createStructure(*m_vm, jsNull())));
+
+    while (!cursor->currentKey().isNull()) {
+        auto& key = cursor->currentKey();
+        auto& valueBuffer = cursor->currentValueBuffer();
+
+        auto value = deserializeIDBValueBuffer(m_globalObject->globalExec(), Vector<uint8_t>(valueBuffer), true);
+
+        IndexKey indexKey;
+        generateIndexKeyForValue(*m_globalObject->globalExec(), info, value.jsValue(), indexKey);
+
+        if (!info.multiEntry()) {
+            IDBError error = uncheckedPutIndexRecord(info.objectStoreIdentifier(), info.identifier(), key, indexKey.asOneKey());
+            if (!error.isNull()) {
+                LOG_ERROR("Unable to put index record for newly created index");
+                return error;
+            }
+        }
+
+        Vector<IDBKeyData> indexKeys = indexKey.multiEntry();
+
+        if (info.unique()) {
+            bool hasRecord;
+            IDBError error;
+            for (auto& indexKey : indexKeys) {
+                error = uncheckedHasIndexRecord(info.identifier(), indexKey, hasRecord);
+                if (hasRecord)
+                    return IDBError(IDBDatabaseException::ConstraintError);
+                if (!error.isNull())
+                    return error;
+            }
+        }
+
+        for (auto& indexKey : indexKeys) {
+            IDBError error = uncheckedPutIndexRecord(info.objectStoreIdentifier(), info.identifier(), key, indexKey);
+            if (!error.isNull()) {
+                LOG_ERROR("Unable to put index record for newly created index");
+                return error;
+            }
+        }
+
+        if (!cursor->advance(1)) {
+            LOG_ERROR("Error advancing cursor while indexing existing records for new index.");
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Error advancing cursor while indexing existing records for new index") };
+        }
+    }
+
+    return { };
 }
 
+IDBError SQLiteIDBBackingStore::uncheckedHasIndexRecord(int64_t indexID, const IDBKeyData& indexKey, bool& hasRecord)
+{
+    hasRecord = false;
+
+    RefPtr<SharedBuffer> indexKeyBuffer = serializeIDBKeyData(indexKey);
+    if (!indexKeyBuffer) {
+        LOG_ERROR("Unable to serialize index key to be stored in the database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to serialize IDBKey to check for index record in database") };
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("SELECT rowid FROM IndexRecords WHERE indexID = ? AND key = CAST(? AS TEXT);"));
+    if (sql.prepare() != SQLITE_OK
+        || sql.bindInt64(1, indexID) != SQLITE_OK
+        || sql.bindBlob(2, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK) {
+        LOG_ERROR("Error checking for index record in database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Error checking for index record in database") };
+    }
+
+    int sqlResult = sql.step();
+    if (sqlResult == SQLITE_OK || sqlResult == SQLITE_DONE)
+        return { };
+
+    if (sqlResult != SQLITE_ROW) {
+        // There was an error fetching the record from the database.
+        LOG_ERROR("Could not check if key exists in index (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Error checking for existence of IDBKey in index") };
+    }
+
+    hasRecord = true;
+    return { };
+}
+
+
+IDBError SQLiteIDBBackingStore::uncheckedPutIndexRecord(int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData& keyValue, const WebCore::IDBKeyData& indexKey)
+{
+    RefPtr<SharedBuffer> indexKeyBuffer = serializeIDBKeyData(indexKey);
+    if (!indexKeyBuffer) {
+        LOG_ERROR("Unable to serialize index key to be stored in the database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to serialize index key to be stored in the database") };
+    }
+
+    RefPtr<SharedBuffer> valueBuffer = serializeIDBKeyData(keyValue);
+    if (!valueBuffer) {
+        LOG_ERROR("Unable to serialize the value to be stored in the database");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to serialize value to be stored in the database") };
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO IndexRecords VALUES (?, ?, CAST(? AS TEXT), CAST(? AS TEXT));"));
+        if (sql.prepare() != SQLITE_OK
+            || sql.bindInt64(1, indexID) != SQLITE_OK
+            || sql.bindInt64(2, objectStoreID) != SQLITE_OK
+            || sql.bindBlob(3, indexKeyBuffer->data(), indexKeyBuffer->size()) != SQLITE_OK
+            || sql.bindBlob(4, valueBuffer->data(), valueBuffer->size()) != SQLITE_OK
+            || sql.step() != SQLITE_DONE) {
+            LOG_ERROR("Could not put index record for index %" PRIi64 " in object store %" PRIi64 " in Records table (%i) - %s", indexID, objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Error putting index record into database") };
+        }
+    }
+
+    return { };
+}
+
+
 IDBError SQLiteIDBBackingStore::deleteIndex(const IDBResourceIdentifier&, uint64_t, const String&)
 {
     return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
index 47df22f1888a698cd7d87f5897fc57c3439b2395..5d770c0c8475fc83f3dbf8137747f841222a9b3a 100644 (file)
@@ -33,6 +33,7 @@
 #include "IDBDatabaseInfo.h"
 #include "IDBResourceIdentifier.h"
 #include "SQLiteIDBTransaction.h"
+#include <JavaScriptCore/Strong.h>
 #include <wtf/HashMap.h>
 
 namespace WebCore {
@@ -86,6 +87,8 @@ private:
     std::unique_ptr<IDBDatabaseInfo> extractExistingDatabaseInfo();
 
     IDBError deleteRecord(SQLiteIDBTransaction&, int64_t objectStoreID, const IDBKeyData&);
+    IDBError uncheckedPutIndexRecord(int64_t objectStoreID, int64_t indexID, const IDBKeyData& keyValue, const IDBKeyData& indexKey);
+    IDBError uncheckedHasIndexRecord(int64_t indexID, const IDBKeyData&, bool& hasRecord);
 
     IDBDatabaseIdentifier m_identifier;
     std::unique_ptr<IDBDatabaseInfo> m_databaseInfo;
@@ -96,6 +99,9 @@ private:
     HashMap<IDBResourceIdentifier, SQLiteIDBCursor*> m_cursors;
 
     String m_absoluteDatabaseDirectory;
+
+    RefPtr<JSC::VM> m_vm;
+    JSC::Strong<JSC::JSGlobalObject> m_globalObject;
 };
 
 } // namespace IDBServer
index 30eb259a802d0f975b28b5e575f6db027698f5cd..8d49f4fe455f79b1a34e544499b44badd853a839 100644 (file)
@@ -40,7 +40,20 @@ namespace IDBServer {
 
 std::unique_ptr<SQLiteIDBCursor> SQLiteIDBCursor::maybeCreate(SQLiteIDBTransaction& transaction, const IDBCursorInfo& info)
 {
-    auto cursor = std::unique_ptr<SQLiteIDBCursor>(new SQLiteIDBCursor(transaction, info));
+    auto cursor = std::make_unique<SQLiteIDBCursor>(transaction, info);
+
+    if (!cursor->establishStatement())
+        return nullptr;
+
+    if (!cursor->advance(1))
+        return nullptr;
+
+    return cursor;
+}
+
+std::unique_ptr<SQLiteIDBCursor> SQLiteIDBCursor::maybeCreateBackingStoreCursor(SQLiteIDBTransaction& transaction, const uint64_t objectStoreIdentifier)
+{
+    auto cursor = std::make_unique<SQLiteIDBCursor>(transaction, objectStoreIdentifier);
 
     if (!cursor->establishStatement())
         return nullptr;
@@ -58,11 +71,15 @@ SQLiteIDBCursor::SQLiteIDBCursor(SQLiteIDBTransaction& transaction, const IDBCur
     , m_indexID(info.sourceIdentifier())
     , m_cursorDirection(info.cursorDirection())
     , m_keyRange(info.range())
-    , m_currentRecordID(-1)
-    , m_statementNeedsReset(false)
-    , m_boundID(0)
-    , m_completed(false)
-    , m_errored(false)
+{
+    ASSERT(m_objectStoreID);
+}
+
+SQLiteIDBCursor::SQLiteIDBCursor(SQLiteIDBTransaction& transaction, uint64_t objectStoreID)
+    : m_transaction(&transaction)
+    , m_cursorIdentifier(transaction.transactionIdentifier())
+    , m_objectStoreID(objectStoreID)
+    , m_cursorDirection(IndexedDB::CursorDirection::Next)
 {
     ASSERT(m_objectStoreID);
 }
index 4a671e1a9a4318a6fb8bff37c9f22f1d1538e090..c56a5af6781f1f8d71c3bf9711dafe8140c37bec 100644 (file)
@@ -46,6 +46,10 @@ class SQLiteIDBCursor {
     WTF_MAKE_NONCOPYABLE(SQLiteIDBCursor);
 public:
     static std::unique_ptr<SQLiteIDBCursor> maybeCreate(SQLiteIDBTransaction&, const IDBCursorInfo&);
+    static std::unique_ptr<SQLiteIDBCursor> maybeCreateBackingStoreCursor(SQLiteIDBTransaction&, const uint64_t objectStoreIdentifier);
+
+    SQLiteIDBCursor(SQLiteIDBTransaction&, const IDBCursorInfo&);
+    SQLiteIDBCursor(SQLiteIDBTransaction&, uint64_t objectStoreID);
 
     const IDBResourceIdentifier& identifier() const { return m_cursorIdentifier; }
     SQLiteIDBTransaction* transaction() const { return m_transaction; }
@@ -64,8 +68,6 @@ public:
     void objectStoreRecordsChanged();
 
 private:
-    SQLiteIDBCursor(SQLiteIDBTransaction&, const IDBCursorInfo&);
-
     bool establishStatement();
     bool createSQLiteStatement(const String& sql);
     bool bindArguments();
@@ -85,24 +87,24 @@ private:
     SQLiteIDBTransaction* m_transaction;
     IDBResourceIdentifier m_cursorIdentifier;
     int64_t m_objectStoreID;
-    int64_t m_indexID;
-    IndexedDB::CursorDirection m_cursorDirection;
+    int64_t m_indexID { IDBIndexMetadata::InvalidId };
+    IndexedDB::CursorDirection m_cursorDirection { IndexedDB::CursorDirection::Next };
     IDBKeyRangeData m_keyRange;
 
     IDBKeyData m_currentLowerKey;
     IDBKeyData m_currentUpperKey;
 
-    int64_t m_currentRecordID;
+    int64_t m_currentRecordID { -1 };
     IDBKeyData m_currentKey;
     IDBKeyData m_currentPrimaryKey;
     Vector<uint8_t> m_currentValueBuffer;
 
     std::unique_ptr<SQLiteStatement> m_statement;
-    bool m_statementNeedsReset;
-    int64_t m_boundID;
+    bool m_statementNeedsReset { false };
+    int64_t m_boundID { 0 };
 
-    bool m_completed;
-    bool m_errored;
+    bool m_completed { false };
+    bool m_errored { false };
 };
 
 
index 1484fce858de2abd66afe0b58444547c7568a6ba..69e5d543de2e0d0e357fb49584881f6b655f20b0 100644 (file)
@@ -99,6 +99,14 @@ void SQLiteIDBTransaction::reset()
     clearCursors();
 }
 
+std::unique_ptr<SQLiteIDBCursor> SQLiteIDBTransaction::maybeOpenBackingStoreCursor(uint64_t objectStoreID)
+{
+    ASSERT(m_sqliteTransaction);
+    ASSERT(m_sqliteTransaction->inProgress());
+
+    return SQLiteIDBCursor::maybeCreateBackingStoreCursor(*this, objectStoreID);
+}
+
 SQLiteIDBCursor* SQLiteIDBTransaction::maybeOpenCursor(const IDBCursorInfo& info)
 {
     ASSERT(m_sqliteTransaction);
index efb84a97ded560bd015e0ae5c1d25f5e51a3dab5..47492499e38b4091a621ad02c19e8bab28542730 100644 (file)
@@ -59,6 +59,7 @@ public:
     IDBError commit();
     IDBError abort();
 
+    std::unique_ptr<SQLiteIDBCursor> maybeOpenBackingStoreCursor(uint64_t objectStoreID);
     SQLiteIDBCursor* maybeOpenCursor(const IDBCursorInfo&);
 
     void closeCursor(SQLiteIDBCursor&);