<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[195517] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/195517">195517</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-01-24 15:42:11 -0800 (Sun, 24 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Support IDBObjectStore.createIndex in the SQLite backing store.
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:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk1TestExpectations">trunk/LayoutTests/platform/mac-wk1/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorcpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBTransactioncpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBTransactionh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/LayoutTests/ChangeLog        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2016-01-24  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        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:
+
</ins><span class="cx"> 2016-01-24  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Make the dumped display list representation a bit more compact
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/TestExpectations        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -439,7 +439,6 @@
</span><span class="cx"> imported/w3c/indexeddb/value.htm [ Failure ]
</span><span class="cx"> imported/w3c/indexeddb/value_recursive.htm [ Failure ]
</span><span class="cx"> imported/w3c/indexeddb/writer-starvation.htm [ Failure ]
</span><del>-storage/indexeddb/createIndex-after-failure.html [ Failure ]
</del><span class="cx"> storage/indexeddb/cursor-added-bug.html [ Failure ]
</span><span class="cx"> storage/indexeddb/cursor-advance.html [ Failure ]
</span><span class="cx"> storage/indexeddb/cursor-basics.html [ Failure ]
</span><span class="lines">@@ -460,13 +459,10 @@
</span><span class="cx"> storage/indexeddb/cursor-update-value-argument-required.html [ Failure ]
</span><span class="cx"> storage/indexeddb/cursor-update.html [ Failure ]
</span><span class="cx"> storage/indexeddb/cursor-value.html [ Failure ]
</span><del>-storage/indexeddb/database-wrapper.html [ Failure ]
</del><span class="cx"> storage/indexeddb/delete-range.html [ Failure ]
</span><del>-storage/indexeddb/deleteIndex.html [ Failure ]
</del><span class="cx"> storage/indexeddb/deleted-objects.html [ Failure ]
</span><span class="cx"> storage/indexeddb/duplicates.html [ Failure ]
</span><span class="cx"> storage/indexeddb/exceptions.html [ Failure ]
</span><del>-storage/indexeddb/factory-deletedatabase.html [ Failure ]
</del><span class="cx"> storage/indexeddb/get-keyrange.html [ Failure ]
</span><span class="cx"> storage/indexeddb/index-basics.html [ Failure ]
</span><span class="cx"> storage/indexeddb/index-count.html [ Failure ]
</span><span class="lines">@@ -484,12 +480,7 @@
</span><span class="cx"> storage/indexeddb/keypath-intrinsic-properties.html [ Failure ]
</span><span class="cx"> storage/indexeddb/lazy-index-population.html [ Failure ]
</span><span class="cx"> storage/indexeddb/lazy-index-types.html [ Failure ]
</span><del>-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 ]
</del><span class="cx"> storage/indexeddb/modern/autoincrement-abort.html [ Failure ]
</span><del>-storage/indexeddb/modern/create-index-failures.html [ Failure ]
</del><span class="cx"> storage/indexeddb/modern/cursor-1.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/cursor-2.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/cursor-3.html [ Failure ]
</span><span class="lines">@@ -500,9 +491,7 @@
</span><span class="cx"> storage/indexeddb/modern/cursor-8.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/deleteindex-1.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/deleteindex-2.html [ Failure ]
</span><del>-storage/indexeddb/modern/get-index-failures.html [ Failure ]
</del><span class="cx"> storage/indexeddb/modern/get-keyrange.html [ Failure ]
</span><del>-storage/indexeddb/modern/idbindex-properties-basic.html [ Failure ]
</del><span class="cx"> storage/indexeddb/modern/idbobjectstore-clear-1.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/idbobjectstore-clear-2.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/idbobjectstore-count-1.html [ Failure ]
</span><span class="lines">@@ -516,16 +505,11 @@
</span><span class="cx"> storage/indexeddb/modern/index-cursor-3.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/index-get-count-basic.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/index-get-count-failures.html [ Failure ]
</span><del>-storage/indexeddb/modern/memory-index-not-deleted-with-objectstore.html [ Failure ]
-storage/indexeddb/modern/objectstore-attributes.html [ Failure ]
</del><span class="cx"> storage/indexeddb/modern/objectstore-cursor-advance-failures.html [ Failure ]
</span><span class="cx"> storage/indexeddb/modern/objectstore-cursor-continue-failures.html [ Failure ]
</span><del>-storage/indexeddb/modern/opencursor-failures.html [ Failure ]
</del><span class="cx"> storage/indexeddb/modern/request-readystate.html [ Failure ]
</span><del>-storage/indexeddb/modern/transactions-stop-on-navigation.html [ Failure ]
</del><span class="cx"> storage/indexeddb/mozilla/autoincrement-indexes.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/clear.html [ Failure ]
</span><del>-storage/indexeddb/mozilla/create-index-with-integer-keys.html [ Failure ]
</del><span class="cx"> storage/indexeddb/mozilla/cursor-mutation-objectstore-only.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/cursor-mutation.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/cursor-update-updates-indexes.html [ Failure ]
</span><span class="lines">@@ -536,7 +520,6 @@
</span><span class="cx"> storage/indexeddb/mozilla/indexes.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/key-requirements.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/object-cursors.html [ Failure ]
</span><del>-storage/indexeddb/mozilla/object-identity.html [ Failure ]
</del><span class="cx"> storage/indexeddb/mozilla/object-store-inline-autoincrement-key-added-on-put.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/object-store-remove-values.html [ Failure ]
</span><span class="cx"> storage/indexeddb/mozilla/odd-result-order.html [ Failure ]
</span><span class="lines">@@ -549,18 +532,12 @@
</span><span class="cx"> storage/indexeddb/objectstore-clear.html [ Failure ]
</span><span class="cx"> storage/indexeddb/objectstore-count.html [ Failure ]
</span><span class="cx"> storage/indexeddb/objectstore-cursor.html [ Failure ]
</span><del>-storage/indexeddb/objectstore-removeobjectstore.html [ Failure ]
</del><span class="cx"> storage/indexeddb/open-cursor.html [ Failure ]
</span><span class="cx"> storage/indexeddb/opencursor-key.html [ Failure ]
</span><span class="cx"> storage/indexeddb/optional-arguments.html [ Failure ]
</span><span class="cx"> storage/indexeddb/prefetch-bugfix-108071.html [ Failure ]
</span><del>-storage/indexeddb/queued-commands.html [ Failure ]
</del><span class="cx"> storage/indexeddb/readonly.html [ Failure ]
</span><del>-storage/indexeddb/structured-clone.html [ Failure ]
</del><span class="cx"> storage/indexeddb/transaction-active-flag.html [ Failure ]
</span><del>-storage/indexeddb/transaction-and-objectstore-calls.html [ Failure ]
-storage/indexeddb/transaction-basics.html [ Failure ]
-storage/indexeddb/transaction-error.html [ Failure ]
</del><span class="cx"> storage/indexeddb/transaction-rollback.html [ Failure ]
</span><span class="cx"> storage/indexeddb/value-undefined.html [ Failure ]
</span><span class="cx"> storage/indexeddb/values-odd-types.html [ Failure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/ChangeLog        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-01-24  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        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:
+
</ins><span class="cx"> 2016-01-24  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Make the dumped display list representation a bit more compact
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -118,6 +118,11 @@
</span><span class="cx"> {
</span><span class="cx">     if (m_sqliteDB)
</span><span class="cx">         m_sqliteDB-&gt;close();
</span><ins>+
+    if (m_vm) {
+        JSLockHolder locker(m_vm.get());
+        m_vm = nullptr;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool createOrMigrateRecordsTableIfNecessary(SQLiteDatabase&amp; database)
</span><span class="lines">@@ -678,11 +683,171 @@
</span><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-IDBError SQLiteIDBBackingStore::createIndex(const IDBResourceIdentifier&amp;, const IDBIndexInfo&amp;)
</del><ins>+IDBError SQLiteIDBBackingStore::createIndex(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBIndexInfo&amp; info)
</ins><span class="cx"> {
</span><del>-    return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Not implemented&quot;) };
</del><ins>+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
+
+    auto* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction-&gt;inProgress()) {
+        LOG_ERROR(&quot;Attempt to create an index without an in-progress transaction&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Attempt to create an index without an in-progress transaction&quot;) };
+    }
+    if (transaction-&gt;mode() != IndexedDB::TransactionMode::VersionChange) {
+        LOG_ERROR(&quot;Attempt to create an index in a non-version-change transaction&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Attempt to create an index in a non-version-change transaction&quot;) };
+    }
+
+    RefPtr&lt;SharedBuffer&gt; keyPathBlob = serializeIDBKeyPath(info.keyPath());
+    if (!keyPathBlob) {
+        LOG_ERROR(&quot;Unable to serialize IDBKeyPath to save in database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to serialize IDBKeyPath to create index in database&quot;) };
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;INSERT INTO IndexInfo VALUES (?, ?, ?, ?, ?, ?);&quot;));
+    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-&gt;data(), keyPathBlob-&gt;size()) != SQLITE_OK
+        || sql.bindInt(5, info.unique()) != SQLITE_OK
+        || sql.bindInt(6, info.multiEntry()) != SQLITE_OK
+        || sql.step() != SQLITE_DONE) {
+        LOG_ERROR(&quot;Could not add index '%s' to IndexInfo table (%i) - %s&quot;, info.name().utf8().data(), m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to create index in database&quot;) };
+    }
+
+    // Write index records for any records that already exist in this object store.
+
+    auto cursor = transaction-&gt;maybeOpenBackingStoreCursor(info.objectStoreIdentifier());
+
+    if (!cursor) {
+        LOG_ERROR(&quot;Cannot open cursor to populate indexes in database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to populate indexes in database&quot;) };
+    }
+
+    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-&gt;currentKey().isNull()) {
+        auto&amp; key = cursor-&gt;currentKey();
+        auto&amp; valueBuffer = cursor-&gt;currentValueBuffer();
+
+        auto value = deserializeIDBValueBuffer(m_globalObject-&gt;globalExec(), Vector&lt;uint8_t&gt;(valueBuffer), true);
+
+        IndexKey indexKey;
+        generateIndexKeyForValue(*m_globalObject-&gt;globalExec(), info, value.jsValue(), indexKey);
+
+        if (!info.multiEntry()) {
+            IDBError error = uncheckedPutIndexRecord(info.objectStoreIdentifier(), info.identifier(), key, indexKey.asOneKey());
+            if (!error.isNull()) {
+                LOG_ERROR(&quot;Unable to put index record for newly created index&quot;);
+                return error;
+            }
+        }
+
+        Vector&lt;IDBKeyData&gt; indexKeys = indexKey.multiEntry();
+
+        if (info.unique()) {
+            bool hasRecord;
+            IDBError error;
+            for (auto&amp; indexKey : indexKeys) {
+                error = uncheckedHasIndexRecord(info.identifier(), indexKey, hasRecord);
+                if (hasRecord)
+                    return IDBError(IDBDatabaseException::ConstraintError);
+                if (!error.isNull())
+                    return error;
+            }
+        }
+
+        for (auto&amp; indexKey : indexKeys) {
+            IDBError error = uncheckedPutIndexRecord(info.objectStoreIdentifier(), info.identifier(), key, indexKey);
+            if (!error.isNull()) {
+                LOG_ERROR(&quot;Unable to put index record for newly created index&quot;);
+                return error;
+            }
+        }
+
+        if (!cursor-&gt;advance(1)) {
+            LOG_ERROR(&quot;Error advancing cursor while indexing existing records for new index.&quot;);
+            return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Error advancing cursor while indexing existing records for new index&quot;) };
+        }
+    }
+
+    return { };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IDBError SQLiteIDBBackingStore::uncheckedHasIndexRecord(int64_t indexID, const IDBKeyData&amp; indexKey, bool&amp; hasRecord)
+{
+    hasRecord = false;
+
+    RefPtr&lt;SharedBuffer&gt; indexKeyBuffer = serializeIDBKeyData(indexKey);
+    if (!indexKeyBuffer) {
+        LOG_ERROR(&quot;Unable to serialize index key to be stored in the database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to serialize IDBKey to check for index record in database&quot;) };
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT rowid FROM IndexRecords WHERE indexID = ? AND key = CAST(? AS TEXT);&quot;));
+    if (sql.prepare() != SQLITE_OK
+        || sql.bindInt64(1, indexID) != SQLITE_OK
+        || sql.bindBlob(2, indexKeyBuffer-&gt;data(), indexKeyBuffer-&gt;size()) != SQLITE_OK) {
+        LOG_ERROR(&quot;Error checking for index record in database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Error checking for index record in database&quot;) };
+    }
+
+    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(&quot;Could not check if key exists in index (%i) - %s&quot;, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Error checking for existence of IDBKey in index&quot;) };
+    }
+
+    hasRecord = true;
+    return { };
+}
+
+
+IDBError SQLiteIDBBackingStore::uncheckedPutIndexRecord(int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData&amp; keyValue, const WebCore::IDBKeyData&amp; indexKey)
+{
+    RefPtr&lt;SharedBuffer&gt; indexKeyBuffer = serializeIDBKeyData(indexKey);
+    if (!indexKeyBuffer) {
+        LOG_ERROR(&quot;Unable to serialize index key to be stored in the database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to serialize index key to be stored in the database&quot;) };
+    }
+
+    RefPtr&lt;SharedBuffer&gt; valueBuffer = serializeIDBKeyData(keyValue);
+    if (!valueBuffer) {
+        LOG_ERROR(&quot;Unable to serialize the value to be stored in the database&quot;);
+        return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Unable to serialize value to be stored in the database&quot;) };
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;INSERT INTO IndexRecords VALUES (?, ?, CAST(? AS TEXT), CAST(? AS TEXT));&quot;));
+        if (sql.prepare() != SQLITE_OK
+            || sql.bindInt64(1, indexID) != SQLITE_OK
+            || sql.bindInt64(2, objectStoreID) != SQLITE_OK
+            || sql.bindBlob(3, indexKeyBuffer-&gt;data(), indexKeyBuffer-&gt;size()) != SQLITE_OK
+            || sql.bindBlob(4, valueBuffer-&gt;data(), valueBuffer-&gt;size()) != SQLITE_OK
+            || sql.step() != SQLITE_DONE) {
+            LOG_ERROR(&quot;Could not put index record for index %&quot; PRIi64 &quot; in object store %&quot; PRIi64 &quot; in Records table (%i) - %s&quot;, indexID, objectStoreID, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+            return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Error putting index record into database&quot;) };
+        }
+    }
+
+    return { };
+}
+
+
</ins><span class="cx"> IDBError SQLiteIDBBackingStore::deleteIndex(const IDBResourceIdentifier&amp;, uint64_t, const String&amp;)
</span><span class="cx"> {
</span><span class="cx">     return { IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Not implemented&quot;) };
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include &quot;IDBDatabaseInfo.h&quot;
</span><span class="cx"> #include &quot;IDBResourceIdentifier.h&quot;
</span><span class="cx"> #include &quot;SQLiteIDBTransaction.h&quot;
</span><ins>+#include &lt;JavaScriptCore/Strong.h&gt;
</ins><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -86,6 +87,8 @@
</span><span class="cx">     std::unique_ptr&lt;IDBDatabaseInfo&gt; extractExistingDatabaseInfo();
</span><span class="cx"> 
</span><span class="cx">     IDBError deleteRecord(SQLiteIDBTransaction&amp;, int64_t objectStoreID, const IDBKeyData&amp;);
</span><ins>+    IDBError uncheckedPutIndexRecord(int64_t objectStoreID, int64_t indexID, const IDBKeyData&amp; keyValue, const IDBKeyData&amp; indexKey);
+    IDBError uncheckedHasIndexRecord(int64_t indexID, const IDBKeyData&amp;, bool&amp; hasRecord);
</ins><span class="cx"> 
</span><span class="cx">     IDBDatabaseIdentifier m_identifier;
</span><span class="cx">     std::unique_ptr&lt;IDBDatabaseInfo&gt; m_databaseInfo;
</span><span class="lines">@@ -96,6 +99,9 @@
</span><span class="cx">     HashMap&lt;IDBResourceIdentifier, SQLiteIDBCursor*&gt; m_cursors;
</span><span class="cx"> 
</span><span class="cx">     String m_absoluteDatabaseDirectory;
</span><ins>+
+    RefPtr&lt;JSC::VM&gt; m_vm;
+    JSC::Strong&lt;JSC::JSGlobalObject&gt; m_globalObject;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;SQLiteIDBCursor&gt; SQLiteIDBCursor::maybeCreate(SQLiteIDBTransaction&amp; transaction, const IDBCursorInfo&amp; info)
</span><span class="cx"> {
</span><del>-    auto cursor = std::unique_ptr&lt;SQLiteIDBCursor&gt;(new SQLiteIDBCursor(transaction, info));
</del><ins>+    auto cursor = std::make_unique&lt;SQLiteIDBCursor&gt;(transaction, info);
</ins><span class="cx"> 
</span><span class="cx">     if (!cursor-&gt;establishStatement())
</span><span class="cx">         return nullptr;
</span><span class="lines">@@ -51,6 +51,19 @@
</span><span class="cx">     return cursor;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::unique_ptr&lt;SQLiteIDBCursor&gt; SQLiteIDBCursor::maybeCreateBackingStoreCursor(SQLiteIDBTransaction&amp; transaction, const uint64_t objectStoreIdentifier)
+{
+    auto cursor = std::make_unique&lt;SQLiteIDBCursor&gt;(transaction, objectStoreIdentifier);
+
+    if (!cursor-&gt;establishStatement())
+        return nullptr;
+
+    if (!cursor-&gt;advance(1))
+        return nullptr;
+
+    return cursor;
+}
+
</ins><span class="cx"> SQLiteIDBCursor::SQLiteIDBCursor(SQLiteIDBTransaction&amp; transaction, const IDBCursorInfo&amp; info)
</span><span class="cx">     : m_transaction(&amp;transaction)
</span><span class="cx">     , m_cursorIdentifier(info.identifier())
</span><span class="lines">@@ -58,15 +71,19 @@
</span><span class="cx">     , m_indexID(info.sourceIdentifier())
</span><span class="cx">     , m_cursorDirection(info.cursorDirection())
</span><span class="cx">     , m_keyRange(info.range())
</span><del>-    , m_currentRecordID(-1)
-    , m_statementNeedsReset(false)
-    , m_boundID(0)
-    , m_completed(false)
-    , m_errored(false)
</del><span class="cx"> {
</span><span class="cx">     ASSERT(m_objectStoreID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SQLiteIDBCursor::SQLiteIDBCursor(SQLiteIDBTransaction&amp; transaction, uint64_t objectStoreID)
+    : m_transaction(&amp;transaction)
+    , m_cursorIdentifier(transaction.transactionIdentifier())
+    , m_objectStoreID(objectStoreID)
+    , m_cursorDirection(IndexedDB::CursorDirection::Next)
+{
+    ASSERT(m_objectStoreID);
+}
+
</ins><span class="cx"> static String buildIndexStatement(const IDBKeyRangeData&amp; keyRange, IndexedDB::CursorDirection cursorDirection)
</span><span class="cx"> {
</span><span class="cx">     StringBuilder builder;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBCursorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -46,7 +46,11 @@
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(SQLiteIDBCursor);
</span><span class="cx"> public:
</span><span class="cx">     static std::unique_ptr&lt;SQLiteIDBCursor&gt; maybeCreate(SQLiteIDBTransaction&amp;, const IDBCursorInfo&amp;);
</span><ins>+    static std::unique_ptr&lt;SQLiteIDBCursor&gt; maybeCreateBackingStoreCursor(SQLiteIDBTransaction&amp;, const uint64_t objectStoreIdentifier);
</ins><span class="cx"> 
</span><ins>+    SQLiteIDBCursor(SQLiteIDBTransaction&amp;, const IDBCursorInfo&amp;);
+    SQLiteIDBCursor(SQLiteIDBTransaction&amp;, uint64_t objectStoreID);
+
</ins><span class="cx">     const IDBResourceIdentifier&amp; identifier() const { return m_cursorIdentifier; }
</span><span class="cx">     SQLiteIDBTransaction* transaction() const { return m_transaction; }
</span><span class="cx"> 
</span><span class="lines">@@ -64,8 +68,6 @@
</span><span class="cx">     void objectStoreRecordsChanged();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    SQLiteIDBCursor(SQLiteIDBTransaction&amp;, const IDBCursorInfo&amp;);
-
</del><span class="cx">     bool establishStatement();
</span><span class="cx">     bool createSQLiteStatement(const String&amp; sql);
</span><span class="cx">     bool bindArguments();
</span><span class="lines">@@ -85,24 +87,24 @@
</span><span class="cx">     SQLiteIDBTransaction* m_transaction;
</span><span class="cx">     IDBResourceIdentifier m_cursorIdentifier;
</span><span class="cx">     int64_t m_objectStoreID;
</span><del>-    int64_t m_indexID;
-    IndexedDB::CursorDirection m_cursorDirection;
</del><ins>+    int64_t m_indexID { IDBIndexMetadata::InvalidId };
+    IndexedDB::CursorDirection m_cursorDirection { IndexedDB::CursorDirection::Next };
</ins><span class="cx">     IDBKeyRangeData m_keyRange;
</span><span class="cx"> 
</span><span class="cx">     IDBKeyData m_currentLowerKey;
</span><span class="cx">     IDBKeyData m_currentUpperKey;
</span><span class="cx"> 
</span><del>-    int64_t m_currentRecordID;
</del><ins>+    int64_t m_currentRecordID { -1 };
</ins><span class="cx">     IDBKeyData m_currentKey;
</span><span class="cx">     IDBKeyData m_currentPrimaryKey;
</span><span class="cx">     Vector&lt;uint8_t&gt; m_currentValueBuffer;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;SQLiteStatement&gt; m_statement;
</span><del>-    bool m_statementNeedsReset;
-    int64_t m_boundID;
</del><ins>+    bool m_statementNeedsReset { false };
+    int64_t m_boundID { 0 };
</ins><span class="cx"> 
</span><del>-    bool m_completed;
-    bool m_errored;
</del><ins>+    bool m_completed { false };
+    bool m_errored { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBTransactioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -99,6 +99,14 @@
</span><span class="cx">     clearCursors();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::unique_ptr&lt;SQLiteIDBCursor&gt; SQLiteIDBTransaction::maybeOpenBackingStoreCursor(uint64_t objectStoreID)
+{
+    ASSERT(m_sqliteTransaction);
+    ASSERT(m_sqliteTransaction-&gt;inProgress());
+
+    return SQLiteIDBCursor::maybeCreateBackingStoreCursor(*this, objectStoreID);
+}
+
</ins><span class="cx"> SQLiteIDBCursor* SQLiteIDBTransaction::maybeOpenCursor(const IDBCursorInfo&amp; info)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_sqliteTransaction);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBTransactionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.h (195516 => 195517)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.h        2016-01-24 20:39:49 UTC (rev 195516)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.h        2016-01-24 23:42:11 UTC (rev 195517)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     IDBError commit();
</span><span class="cx">     IDBError abort();
</span><span class="cx"> 
</span><ins>+    std::unique_ptr&lt;SQLiteIDBCursor&gt; maybeOpenBackingStoreCursor(uint64_t objectStoreID);
</ins><span class="cx">     SQLiteIDBCursor* maybeOpenCursor(const IDBCursorInfo&amp;);
</span><span class="cx"> 
</span><span class="cx">     void closeCursor(SQLiteIDBCursor&amp;);
</span></span></pre>
</div>
</div>

</body>
</html>