IDB: Index cursor complete advance() and iterate() support
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Feb 2014 19:04:02 +0000 (19:04 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Feb 2014 19:04:02 +0000 (19:04 +0000)
<rdar://problem/15941916> and https://bugs.webkit.org/show_bug.cgi?id=127870

Reviewed by Dan Bernstein.

Source/WebCore:

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::onSuccess): Always use the value buffer for the script object.

Source/WebKit2:

* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
(WebKit::SQLiteIDBCursor::advanceOnce): Look up the found record value from the
  object store records based on the key we found from the index.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp

index cae8cfd..6f68ff7 100644 (file)
@@ -1,3 +1,13 @@
+2014-02-01  Brady Eidson  <beidson@apple.com>
+
+        IDB: Index cursor complete advance() and iterate() support
+        <rdar://problem/15941916> and https://bugs.webkit.org/show_bug.cgi?id=127870
+
+        Reviewed by Dan Bernstein.
+
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::onSuccess): Always use the value buffer for the script object.
+
 2014-02-01  Alexey Proskuryakov  <ap@apple.com>
 
         Update WebCrypto JWK mapping to use key_ops
 2014-02-01  Alexey Proskuryakov  <ap@apple.com>
 
         Update WebCrypto JWK mapping to use key_ops
index 41a44f9..8da84cb 100644 (file)
@@ -287,12 +287,7 @@ void IDBRequest::onSuccess(PassRefPtr<IDBCursorBackend> prpBackend)
     RefPtr<IDBKey> key = backend->key();
     RefPtr<IDBKey> primaryKey = backend->primaryKey();
 
     RefPtr<IDBKey> key = backend->key();
     RefPtr<IDBKey> primaryKey = backend->primaryKey();
 
-    Deprecated::ScriptValue value;
-
-    if (backend->valueKey())
-        value = idbKeyToScriptValue(requestState(), backend->valueKey());
-    else
-        value = deserializeIDBValueBuffer(requestState(), backend->valueBuffer());
+    Deprecated::ScriptValue value = deserializeIDBValueBuffer(requestState(), backend->valueBuffer());
 
     ASSERT(!m_pendingCursor);
     RefPtr<IDBCursor> cursor;
 
     ASSERT(!m_pendingCursor);
     RefPtr<IDBCursor> cursor;
@@ -409,7 +404,7 @@ void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey
     onSuccess(key, primaryKey, buffer, nullptr);
 }
 
     onSuccess(key, primaryKey, buffer, nullptr);
 }
 
-void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey> valueKey)
+void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer> buffer, PassRefPtr<IDBKey>)
 {
     LOG(StorageAPI, "IDBRequest::onSuccess(key, primaryKey, valueBuffer, valueKey)");
     if (!shouldEnqueueEvent())
 {
     LOG(StorageAPI, "IDBRequest::onSuccess(key, primaryKey, valueBuffer, valueKey)");
     if (!shouldEnqueueEvent())
@@ -417,11 +412,7 @@ void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey
 
     DOMRequestState::Scope scope(m_requestState);
 
 
     DOMRequestState::Scope scope(m_requestState);
 
-    Deprecated::ScriptValue value;
-    if (valueKey)
-        value = idbKeyToScriptValue(requestState(), valueKey);
-    else
-        value = deserializeIDBValueBuffer(requestState(), buffer);
+    Deprecated::ScriptValue value = deserializeIDBValueBuffer(requestState(), buffer);
 
     ASSERT(m_pendingCursor);
     setResultCursor(m_pendingCursor.release(), key, primaryKey, value);
 
     ASSERT(m_pendingCursor);
     setResultCursor(m_pendingCursor.release(), key, primaryKey, value);
index c3d06e4..9f426e1 100644 (file)
@@ -1,3 +1,14 @@
+2014-02-01  Brady Eidson  <beidson@apple.com>
+
+        IDB: Index cursor complete advance() and iterate() support
+        <rdar://problem/15941916> and https://bugs.webkit.org/show_bug.cgi?id=127870
+
+        Reviewed by Dan Bernstein.
+
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
+        (WebKit::SQLiteIDBCursor::advanceOnce): Look up the found record value from the
+          object store records based on the key we found from the index.
+
 2014-01-31  Anders Carlsson  <andersca@apple.com>
 
         Add webView:didFailNavigation:withError: delegate method
 2014-01-31  Anders Carlsson  <andersca@apple.com>
 
         Add webView:didFailNavigation:withError: delegate method
index a15250e..c6a6c49 100644 (file)
@@ -283,13 +283,22 @@ bool SQLiteIDBCursor::advanceOnce()
 
     if (m_indexID != IDBIndexMetadata::InvalidId) {
         if (!deserializeIDBKeyData(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.size(), m_currentValueKey)) {
 
     if (m_indexID != IDBIndexMetadata::InvalidId) {
         if (!deserializeIDBKeyData(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.size(), m_currentValueKey)) {
-            LOG_ERROR("Unable to deserialize value data from database while advancing cursor");
+            LOG_ERROR("Unable to deserialize value data from database while advancing index cursor");
             m_completed = true;
             return false;
         }
 
             m_completed = true;
             return false;
         }
 
-        // Index cursors should only have a m_currentValueKey, and not m_currentValueBuffer
-        m_currentValueBuffer.clear();
+        SQLiteStatement objectStoreStatement(*m_statement->database(), "SELECT value FROM Records WHERE key = CAST(? AS TEXT) and objectStoreID = ?;");
+
+        if (objectStoreStatement.prepare() != SQLResultOk
+            || objectStoreStatement.bindBlob(1, m_currentValueBuffer.data(), m_currentValueBuffer.size()) != SQLResultOk
+            || objectStoreStatement.bindInt64(2, m_objectStoreID) != SQLResultOk
+            || objectStoreStatement.step() != SQLResultRow) {
+            LOG_ERROR("Could not create index cursor statement into object store records");
+            return false;
+        }
+
+        objectStoreStatement.getColumnBlobAsVector(0, m_currentValueBuffer);
     }
 
     return true;
     }
 
     return true;