<!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>[192618] 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/192618">192618</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2015-11-19 00:19:56 -0800 (Thu, 19 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Populate indexes created in object stores that already have records.
https://bugs.webkit.org/show_bug.cgi?id=151421

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/index-4.html
      storage/indexeddb/modern/index-5.html

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::createIndex):
(WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords):
* Modules/indexeddb/server/MemoryObjectStore.h:

LayoutTests:

* storage/indexeddb/modern/index-4-expected.txt: Added.
* storage/indexeddb/modern/index-4.html: Added.
* storage/indexeddb/modern/index-5-expected.txt: Added.
* storage/indexeddb/modern/index-5.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplh">trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryObjectStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernindex4expectedtxt">trunk/LayoutTests/storage/indexeddb/modern/index-4-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernindex4html">trunk/LayoutTests/storage/indexeddb/modern/index-4.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernindex5expectedtxt">trunk/LayoutTests/storage/indexeddb/modern/index-5-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernindex5html">trunk/LayoutTests/storage/indexeddb/modern/index-5.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/LayoutTests/ChangeLog        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-11-19  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Populate indexes created in object stores that already have records.
+        https://bugs.webkit.org/show_bug.cgi?id=151421
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/index-4-expected.txt: Added.
+        * storage/indexeddb/modern/index-4.html: Added.
+        * storage/indexeddb/modern/index-5-expected.txt: Added.
+        * storage/indexeddb/modern/index-5.html: Added.
+
</ins><span class="cx"> 2015-11-18  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Storage tab shouldn't hide cookies for .example.com when inspected page is foo.bar.example.com
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernindex4expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/index-4-expected.txt (0 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/index-4-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/index-4-expected.txt        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+This tests that indexes added to an object store with existing records are populated upon their creation.
+Initial upgrade needed: Old version - 0 New version - 1
+Count is: 18
+Cursor at record: A / 1
+Cursor at record: A / 2
+Cursor at record: B / 3
+Cursor at record: B / 4
+Cursor at record: C / 5
+Cursor at record: C / 6
+Cursor at record: D / 7
+Cursor at record: D / 8
+Cursor at record: E / 9
+Cursor at record: E / 10
+Cursor at record: F / 11
+Cursor at record: F / 12
+Cursor at record: G / 13
+Cursor at record: G / 14
+Cursor at record: H / 15
+Cursor at record: H / 16
+Cursor at record: I / 17
+Cursor at record: I / 18
+Cursor at record: undefined / undefined
+Done
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernindex4html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/index-4.html (0 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/index-4.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/index-4.html        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -0,0 +1,96 @@
</span><ins>+This tests that indexes added to an object store with existing records are populated upon their creation.&lt;br&gt;
+&lt;div id=&quot;logger&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    log(&quot;Done&quot;);
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function log(message)
+{
+    document.getElementById(&quot;logger&quot;).innerHTML += message + &quot;&lt;br&gt;&quot;;
+}
+
+var index;
+var objectStore;
+
+function checkIndexValues()
+{
+    var countRequest = index.count();
+    countRequest.onsuccess = function() {
+        log(&quot;Count is: &quot; + countRequest.result);
+    }
+
+    var cursorRequest = index.openCursor();
+    cursorRequest.onsuccess = function() {
+        var cursor = cursorRequest.result;
+        log(&quot;Cursor at record: &quot; + cursor.key + &quot; / &quot; + cursor.primaryKey);
+        
+        if (cursor.key != undefined)
+            cursor.continue();
+        else
+            done();
+    }
+    cursorRequest.onerror = function(e) {
+        log(&quot;Unexpected error opening or iterating cursor&quot;);
+        logCursor(cursorRequest.result);
+        done();
+    } 
+}
+
+var createRequest = window.indexedDB.open(&quot;Index4Database&quot;, 1);
+createRequest.onupgradeneeded = function(event) {
+    log(&quot;Initial upgrade needed: Old version - &quot; + event.oldVersion + &quot; New version - &quot; + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    var database = event.target.result;
+    objectStore = database.createObjectStore(&quot;TestObjectStore&quot;);
+    objectStore.put({ bar: &quot;A&quot; }, 1);
+    objectStore.put({ bar: &quot;A&quot; }, 2);
+    objectStore.put({ bar: &quot;B&quot; }, 3);
+    objectStore.put({ bar: &quot;B&quot; }, 4);
+    objectStore.put({ bar: &quot;C&quot; }, 5);
+    objectStore.put({ bar: &quot;C&quot; }, 6);
+    objectStore.put({ bar: &quot;D&quot; }, 7);
+    objectStore.put({ bar: &quot;D&quot; }, 8);
+    objectStore.put({ bar: &quot;E&quot; }, 9);
+    objectStore.put({ bar: &quot;E&quot; }, 10);
+    objectStore.put({ bar: &quot;F&quot; }, 11);
+    objectStore.put({ bar: &quot;F&quot; }, 12);
+    objectStore.put({ bar: &quot;G&quot; }, 13);
+    objectStore.put({ bar: &quot;G&quot; }, 14);    
+    objectStore.put({ bar: &quot;H&quot; }, 15);
+    objectStore.put({ bar: &quot;H&quot; }, 16);  
+    objectStore.put({ bar: &quot;I&quot; }, 17);
+    objectStore.put({ bar: &quot;I&quot; }, 18);  
+
+    // This index should be populated with the above values upon its creation.
+    index = objectStore.createIndex(&quot;TestIndex1&quot;, &quot;bar&quot;);
+    
+    checkIndexValues();
+    
+    versionTransaction.onabort = function(event) {
+        log(&quot;Initial upgrade versionchange transaction unexpected aborted&quot;);
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        log(&quot;Initial upgrade versionchange transaction complete&quot;);
+        done();
+    }
+
+    versionTransaction.onerror = function(event) {
+        log(&quot;Initial upgrade versionchange transaction unexpected error&quot; + event);
+        done();
+    }
+}
+
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernindex5expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/index-5-expected.txt (0 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/index-5-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/index-5-expected.txt        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+This tests creating an index on an object store that already has records, and those records would violate the unique constraint of the index.
+(The index creation should fail).
+Initial upgrade needed: Old version - 0 New version - 1
+Initial upgrade versionchange transaction aborted (expected because index creation failed, and that should've caused transaction abort)
+Done
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernindex5html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/index-5.html (0 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/index-5.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/index-5.html        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -0,0 +1,82 @@
</span><ins>+This tests creating an index on an object store that already has records, and those records would violate the unique constraint of the index.&lt;br&gt;
+(The index creation should fail).&lt;br&gt;
+&lt;div id=&quot;logger&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    log(&quot;Done&quot;);
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function log(message)
+{
+    document.getElementById(&quot;logger&quot;).innerHTML += message + &quot;&lt;br&gt;&quot;;
+}
+
+var index;
+var objectStore;
+
+function checkIndexValues()
+{
+    var countRequest = index.count();
+    countRequest.onsuccess = function() {
+        log(&quot;Count is: &quot; + countRequest.result);
+    }
+
+    var cursorRequest = index.openCursor();
+    cursorRequest.onsuccess = function() {
+        var cursor = cursorRequest.result;
+        log(&quot;Cursor at record: &quot; + cursor.key + &quot; / &quot; + cursor.primaryKey);
+        
+        if (cursor.key != undefined)
+            cursor.continue();
+        else
+            done();
+    }
+    cursorRequest.onerror = function(e) {
+        log(&quot;Unexpected error opening or iterating cursor&quot;);
+        logCursor(cursorRequest.result);
+        done();
+    } 
+}
+
+var createRequest = window.indexedDB.open(&quot;Index5Database&quot;, 1);
+createRequest.onupgradeneeded = function(event) {
+    log(&quot;Initial upgrade needed: Old version - &quot; + event.oldVersion + &quot; New version - &quot; + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    var database = event.target.result;
+    objectStore = database.createObjectStore(&quot;TestObjectStore&quot;);
+    objectStore.put({ bar: &quot;A&quot; }, 1);
+    objectStore.put({ bar: &quot;A&quot; }, 2);
+
+    // This index should be populated with the above values upon its creation, but that should fail because
+    // of constraint violations.
+    index = objectStore.createIndex(&quot;TestIndex1&quot;, &quot;bar&quot;, { unique: true });
+    
+    checkIndexValues();
+    
+    versionTransaction.onabort = function(event) {
+        log(&quot;Initial upgrade versionchange transaction aborted (expected because index creation failed, and that should've caused transaction abort)&quot;);
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        log(&quot;Initial upgrade versionchange transaction unexpected complete&quot;);
+        done();
+    }
+
+    versionTransaction.onerror = function(event) {
+        log(&quot;Initial upgrade versionchange transaction unexpected error&quot; + event);
+        done();
+    }
+}
+
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/ChangeLog        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-11-19  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Populate indexes created in object stores that already have records.
+        https://bugs.webkit.org/show_bug.cgi?id=151421
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/index-4.html
+              storage/indexeddb/modern/index-5.html
+
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::createIndex):
+        (WebCore::IDBServer::MemoryObjectStore::populateIndexWithExistingRecords):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+
</ins><span class="cx"> 2015-11-18  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Modern IDB:Make in-memory Index cursors work.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -157,6 +157,20 @@
</span><span class="cx">     return adoptRef(&amp;objectStore.leakRef());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBTransaction::immediateAbort()
+{
+    LOG(IndexedDB, &quot;IDBTransaction::immediateAbort&quot;);
+
+    if (isFinishedOrFinishing())
+        return;
+
+    m_state = IndexedDB::TransactionState::Aborting;
+    m_database-&gt;willAbortTransaction(*this);
+
+    auto operation = createTransactionOperation(*this, nullptr, &amp;IDBTransaction::abortOnServer);
+    abortOnServer(*operation);
+}
+
</ins><span class="cx"> void IDBTransaction::abort(ExceptionCode&amp; ec)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBTransaction::abort&quot;);
</span><span class="lines">@@ -429,7 +443,11 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBTransaction::didCreateIndexOnServer&quot;);
</span><span class="cx"> 
</span><del>-    ASSERT_UNUSED(resultData, resultData.type() == IDBResultType::CreateIndexSuccess);
</del><ins>+    if (resultData.type() == IDBResultType::CreateIndexSuccess)
+        return;
+
+    // If index creation failed, the transaction is aborted.
+    immediateAbort();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Ref&lt;IDBRequest&gt; IDBTransaction::requestOpenCursor(ScriptExecutionContext&amp; context, IDBObjectStore&amp; objectStore, const IDBCursorInfo&amp; info)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -176,6 +176,8 @@
</span><span class="cx"> 
</span><span class="cx">     void scheduleOperationTimer();
</span><span class="cx"> 
</span><ins>+    void immediateAbort();
+
</ins><span class="cx">     Ref&lt;IDBDatabase&gt; m_database;
</span><span class="cx">     IDBTransactionInfo m_info;
</span><span class="cx">     std::unique_ptr&lt;IDBDatabaseInfo&gt; m_originalDatabaseInfo;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -90,8 +90,12 @@
</span><span class="cx">     ASSERT(!m_indexesByIdentifier.contains(info.identifier()));
</span><span class="cx">     auto index = MemoryIndex::create(info, *this);
</span><span class="cx"> 
</span><ins>+    // If there was an error populating the new index, then the current records in the object store violate its contraints
+    auto error = populateIndexWithExistingRecords(*index);
+    if (!error.isNull())
+        return error;
+
</ins><span class="cx">     m_info.addExistingIndex(info);
</span><del>-
</del><span class="cx">     transaction.addNewIndex(*index);
</span><span class="cx">     registerIndex(WTF::move(index));
</span><span class="cx"> 
</span><span class="lines">@@ -283,6 +287,33 @@
</span><span class="cx">     return error;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+
+IDBError MemoryObjectStore::populateIndexWithExistingRecords(MemoryIndex&amp; index)
+{
+    if (!m_keyValueStore)
+        return { };
+
+    JSLockHolder locker(indexVM());
+
+    for (auto iterator : *m_keyValueStore) {
+        auto jsValue = idbValueDataToJSValue(indexGlobalExec(), iterator.value);
+        if (jsValue.isUndefinedOrNull())
+            return { };
+
+        IndexKey indexKey;
+        generateIndexKeyForValue(indexGlobalExec(), index.info(), jsValue, indexKey);
+
+        if (indexKey.isNull())
+            continue;
+
+        IDBError error = index.putIndexKey(iterator.key, indexKey);
+        if (!error.isNull())
+            return error;
+    }
+
+    return { };
+}
+
</ins><span class="cx"> uint64_t MemoryObjectStore::countForKeyRange(uint64_t indexIdentifier, const IDBKeyRangeData&amp; inRange) const
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;MemoryObjectStore::countForKeyRange&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -97,6 +97,7 @@
</span><span class="cx">     IDBKeyData lowestKeyWithRecordInRange(const IDBKeyRangeData&amp;) const;
</span><span class="cx">     std::set&lt;IDBKeyData&gt;::iterator lowestIteratorInRange(const IDBKeyRangeData&amp;, bool reverse) const;
</span><span class="cx"> 
</span><ins>+    IDBError populateIndexWithExistingRecords(MemoryIndex&amp;);
</ins><span class="cx">     IDBError updateIndexesForPutRecord(const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; value);
</span><span class="cx">     void updateIndexesForDeleteRecord(const IDBKeyData&amp; value);
</span><span class="cx">     void updateCursorsForPutRecord(std::set&lt;IDBKeyData&gt;::iterator);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (192617 => 192618)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-19 08:17:44 UTC (rev 192617)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-19 08:19:56 UTC (rev 192618)
</span><span class="lines">@@ -353,9 +353,8 @@
</span><span class="cx">     LOG(IndexedDB, &quot;(db) UniqueIDBDatabase::performCreateIndex&quot;);
</span><span class="cx"> 
</span><span class="cx">     ASSERT(m_backingStore);
</span><del>-    m_backingStore-&gt;createIndex(transactionIdentifier, info);
</del><ins>+    IDBError error = m_backingStore-&gt;createIndex(transactionIdentifier, info);
</ins><span class="cx"> 
</span><del>-    IDBError error;
</del><span class="cx">     m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformCreateIndex, callbackIdentifier, error, info));
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>