<!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>[191877] 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/191877">191877</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2015-11-01 22:52:50 -0800 (Sun, 01 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: IBDObjectStore.count() support.
https://bugs.webkit.org/show_bug.cgi?id=150785

Reviewed by Darin Adler.

Source/WebCore:

Tests: storage/indexeddb/modern/idbobjectstore-count-1.html
       storage/indexeddb/modern/idbobjectstore-count-failures.html

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::getCount):
(WebCore::IDBClient::IDBConnectionToServer::didGetCount):
* Modules/indexeddb/client/IDBConnectionToServer.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:

* Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
(WebCore::IDBClient::IDBObjectStore::count):
(WebCore::IDBClient::IDBObjectStore::doCount):
* Modules/indexeddb/client/IDBObjectStoreImpl.h:

* Modules/indexeddb/client/IDBRequestImpl.cpp:
(WebCore::IDBClient::IDBRequest::setResult):
* Modules/indexeddb/client/IDBRequestImpl.h:

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::requestCount):
(WebCore::IDBClient::IDBTransaction::getCountOnServer):
(WebCore::IDBClient::IDBTransaction::didGetCountOnServer):
* Modules/indexeddb/client/IDBTransactionImpl.h:

* Modules/indexeddb/server/IDBBackingStore.h:

* Modules/indexeddb/server/IDBConnectionToClient.cpp:
(WebCore::IDBServer::IDBConnectionToClient::didGetCount):
* Modules/indexeddb/server/IDBConnectionToClient.h:
* Modules/indexeddb/server/IDBConnectionToClientDelegate.h:

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

* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::getCount):
* Modules/indexeddb/server/MemoryIDBBackingStore.h:

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::countForKeyRange):
(WebCore::IDBServer::MemoryObjectStore::valueForKeyRange):
(WebCore::IDBServer::MemoryObjectStore::lowestKeyWithRecordInRange):
* Modules/indexeddb/server/MemoryObjectStore.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::storeCallback):
(WebCore::IDBServer::UniqueIDBDatabase::getCount):
(WebCore::IDBServer::UniqueIDBDatabase::performGetCount):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformGetCount):
(WebCore::IDBServer::UniqueIDBDatabase::performCountCallback):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

* Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getCount):
* Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:

* Modules/indexeddb/shared/IDBResultData.cpp:
(WebCore::IDBResultData::IDBResultData):
(WebCore::IDBResultData::getCountSuccess):
* Modules/indexeddb/shared/IDBResultData.h:
(WebCore::IDBResultData::resultInteger):

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::didGetCount):
(WebCore::InProcessIDBServer::getCount):
* Modules/indexeddb/shared/InProcessIDBServer.h:

LayoutTests:

* storage/indexeddb/modern/idbobjectstore-count-1-expected.txt: Added.
* storage/indexeddb/modern/idbobjectstore-count-1.html: Added.
* storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt: Added.
* storage/indexeddb/modern/idbobjectstore-count-failures.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="#trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServercpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerh">trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerDelegateh">trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBObjectStoreImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBObjectStoreImplh">trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBRequestImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBRequestImplh">trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h</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="#trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientcpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClienth">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientDelegateh">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServerh">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.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>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseTransactioncpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseTransactionh">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedIDBResultDatacpp">trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedIDBResultDatah">trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernidbobjectstorecount1expectedtxt">trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernidbobjectstorecount1html">trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernidbobjectstorecountfailuresexpectedtxt">trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernidbobjectstorecountfailureshtml">trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/LayoutTests/ChangeLog        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2015-11-01  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: IBDObjectStore.count() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150785
+
+        Reviewed by Darin Adler.
+
+        * storage/indexeddb/modern/idbobjectstore-count-1-expected.txt: Added.
+        * storage/indexeddb/modern/idbobjectstore-count-1.html: Added.
+        * storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt: Added.
+        * storage/indexeddb/modern/idbobjectstore-count-failures.html: Added.
+
+
</ins><span class="cx"> 2015-11-01  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [ES6] Support Generator Syntax
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernidbobjectstorecount1expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1-expected.txt (0 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1-expected.txt        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Count is: 1
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 2
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 0
+ALERT: Count is: 3
+ALERT: Count is: 1
+ALERT: Count is: 0
+ALERT: Count is: 1
+ALERT: Count is: 0
+ALERT: Count is: 4
+ALERT: Count is: 2
+ALERT: Count is: 1
+ALERT: Count is: 2
+ALERT: Count is: 0
+ALERT: Count is: 5
+ALERT: Count is: 3
+ALERT: Count is: 2
+ALERT: Count is: 3
+ALERT: Count is: 0
+ALERT: Count is: 6
+ALERT: Count is: 4
+ALERT: Count is: 3
+ALERT: Count is: 3
+ALERT: Count is: 0
+ALERT: Count is: 7
+ALERT: Count is: 4
+ALERT: Count is: 3
+ALERT: Count is: 3
+ALERT: Count is: 1
+ALERT: Count is: 8
+ALERT: Count is: 4
+ALERT: Count is: 3
+ALERT: Count is: 3
+ALERT: Count is: 1
+ALERT: Count is: 9
+ALERT: Count is: 4
+ALERT: Count is: 3
+ALERT: Count is: 3
+ALERT: Count is: 1
+ALERT: Count is: 10
+ALERT: Count is: 4
+ALERT: Count is: 3
+ALERT: Count is: 3
+ALERT: Count is: 1
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Done
+This test exercises various uses of IDBObjectStore.count()
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernidbobjectstorecount1html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1.html (0 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-1.html        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -0,0 +1,92 @@
</span><ins>+This test exercises various uses of IDBObjectStore.count()
+&lt;script&gt;
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert(&quot;Done&quot;);
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open(&quot;IDBObjectStoreCount1Database&quot;, 1);
+var database;
+var objectStore;
+
+function getCount(arg)
+{
+    var request;
+    if (arg == undefined)
+        request = objectStore.count();
+    else
+        request = objectStore.count(arg);
+    
+    request.onsuccess = function() {
+        alert(&quot;Count is: &quot; + request.result);
+    }
+    request.onerror = function(error) {
+        alert(&quot;Unexpected error getting count: &quot; + error);
+        done();
+    }
+}
+
+function getCounts()
+{
+    getCount();
+    getCount(IDBKeyRange.bound(3, 6));    
+    getCount(IDBKeyRange.bound(3, 6, true, false));    
+    getCount(IDBKeyRange.bound(3, 6, false, true));
+    getCount(7);    
+}
+
+createRequest.onupgradeneeded = function(event) {
+    alert(&quot;Initial upgrade needed: Old version - &quot; + event.oldVersion + &quot; New version - &quot; + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    database = event.target.result;
+    objectStore = database.createObjectStore(&quot;TestObjectStore&quot;);
+    
+    objectStore.put(1, 1);
+    getCounts();
+    objectStore.put(2, 2);
+    getCounts();
+    objectStore.put(3, 3);
+    getCounts();
+    objectStore.put(4, 4);
+    getCounts();
+    objectStore.put(5, 5);
+    getCounts();
+    objectStore.put(6, 6);
+    getCounts();
+    objectStore.put(7, 7);
+    getCounts();
+    objectStore.put(8, 8);
+    getCounts();
+    objectStore.put(9, 9);
+    getCounts();
+    objectStore.put(10, 10);
+    getCounts();
+
+    // FIXME: Once objectStore.delete() is implemented, also test counts after deleting previous records.
+    
+    versionTransaction.onabort = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction unexpected abort&quot;);
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction complete&quot;);
+        done();
+    }
+
+    versionTransaction.onerror = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction unexpected error&quot; + event);
+        done();
+    }
+}
+
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernidbobjectstorecountfailuresexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt (0 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures-expected.txt        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Failed to count records in object store with an invalid key
+ALERT: Failed to count records in object store that's been deleted
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Failed to count records in object store while transaction is inactive
+ALERT: readonly transaction complete
+ALERT: Done
+This tests some obvious failures that can happen while calling IDBObjectStore.count().
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernidbobjectstorecountfailureshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures.html (0 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/idbobjectstore-count-failures.html        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -0,0 +1,98 @@
</span><ins>+This tests some obvious failures that can happen while calling IDBObjectStore.count().
+&lt;script&gt;
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert(&quot;Done&quot;);
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open(&quot;IDBObjectStoreCountFailuresDatabase&quot;, 1);
+var database;
+
+createRequest.onupgradeneeded = function(event) {
+    alert(&quot;Initial upgrade needed: Old version - &quot; + event.oldVersion + &quot; New version - &quot; + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    database = event.target.result;
+    var objectStore = database.createObjectStore(&quot;TestObjectStore&quot;);
+    var request = objectStore.put(&quot;bar&quot;, &quot;foo&quot;);
+
+    request.onsuccess = function() {
+        try {
+            objectStore.count(NaN);
+        } catch(e) {
+            alert(&quot;Failed to count records in object store with an invalid key&quot;);
+        }
+        
+        database.deleteObjectStore(&quot;TestObjectStore&quot;);
+        
+        try {
+            objectStore.count();
+        } catch(e) {
+            alert(&quot;Failed to count records in object store that's been deleted&quot;);
+        } 
+
+        // Recreate the objectstore because we'll need it in phase 2.
+        var objectStore = database.createObjectStore(&quot;TestObjectStore&quot;);
+        objectStore.put(&quot;bar&quot;, &quot;foo&quot;);    
+    }
+    
+    versionTransaction.onabort = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction unexpected aborted&quot;);
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction complete&quot;);
+        continueTest1();
+    }
+
+    versionTransaction.onerror = function(event) {
+        alert(&quot;Initial upgrade versionchange transaction unexpected error&quot; + event);
+        done();
+    }
+}
+
+function continueTest1()
+{
+    var transaction = database.transaction(&quot;TestObjectStore&quot;, &quot;readonly&quot;);
+    var objectStore = transaction.objectStore(&quot;TestObjectStore&quot;);
+
+    // Queue up a whole bunch of gets to keep the transaction alive for awhile
+    for (var i = 0; i &lt; 10; ++i)
+        objectStore.get(&quot;foo&quot;);
+
+    var getWhileInactive = function() {
+        try {
+            objectStore.count();
+        } catch(e) {
+            alert(&quot;Failed to count records in object store while transaction is inactive&quot;);
+        } 
+    }
+    
+    setTimeout(getWhileInactive, 0);
+    
+    transaction.onabort = function(event) {
+        alert(&quot;readonly transaction unexpected abort&quot; + event);
+        done();
+    }
+
+    transaction.oncomplete = function(event) {
+        alert(&quot;readonly transaction complete&quot;);
+        done();
+    }
+
+    transaction.onerror = function(event) {
+        alert(&quot;readonly 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 (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/ChangeLog        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -1,3 +1,79 @@
</span><ins>+2015-11-01  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: IBDObjectStore.count() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150785
+
+        Reviewed by Darin Adler.
+
+        Tests: storage/indexeddb/modern/idbobjectstore-count-1.html
+               storage/indexeddb/modern/idbobjectstore-count-failures.html
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::getCount):
+        (WebCore::IDBClient::IDBConnectionToServer::didGetCount):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+        
+        * Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
+        (WebCore::IDBClient::IDBObjectStore::count):
+        (WebCore::IDBClient::IDBObjectStore::doCount):
+        * Modules/indexeddb/client/IDBObjectStoreImpl.h:
+        
+        * Modules/indexeddb/client/IDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBRequest::setResult):
+        * Modules/indexeddb/client/IDBRequestImpl.h:
+        
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::requestCount):
+        (WebCore::IDBClient::IDBTransaction::getCountOnServer):
+        (WebCore::IDBClient::IDBTransaction::didGetCountOnServer):
+        * Modules/indexeddb/client/IDBTransactionImpl.h:
+        
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        
+        * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+        (WebCore::IDBServer::IDBConnectionToClient::didGetCount):
+        * Modules/indexeddb/server/IDBConnectionToClient.h:
+        * Modules/indexeddb/server/IDBConnectionToClientDelegate.h:
+        
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::getCount):
+        * Modules/indexeddb/server/IDBServer.h:
+        
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::getCount):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::countForKeyRange):
+        (WebCore::IDBServer::MemoryObjectStore::valueForKeyRange):
+        (WebCore::IDBServer::MemoryObjectStore::lowestKeyWithRecordInRange):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::storeCallback):
+        (WebCore::IDBServer::UniqueIDBDatabase::getCount):
+        (WebCore::IDBServer::UniqueIDBDatabase::performGetCount):
+        (WebCore::IDBServer::UniqueIDBDatabase::didPerformGetCount):
+        (WebCore::IDBServer::UniqueIDBDatabase::performCountCallback):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):
+        (WebCore::IDBServer::UniqueIDBDatabaseTransaction::getCount):
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
+        
+        * Modules/indexeddb/shared/IDBResultData.cpp:
+        (WebCore::IDBResultData::IDBResultData):
+        (WebCore::IDBResultData::getCountSuccess):
+        * Modules/indexeddb/shared/IDBResultData.h:
+        (WebCore::IDBResultData::resultInteger):
+        
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::didGetCount):
+        (WebCore::InProcessIDBServer::getCount):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
</ins><span class="cx"> 2015-11-01  Darin Adler  &lt;darin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Tidy handling of type=color in HTMLInputElement a bit
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -170,6 +170,22 @@
</span><span class="cx">     completeOperation(resultData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBConnectionToServer::getCount(TransactionOperation&amp; operation, const IDBKeyRangeData&amp; keyRangeData)
+{
+    LOG(IndexedDB, &quot;IDBConnectionToServer::getCount&quot;);
+
+    ASSERT(!keyRangeData.isNull);
+
+    saveOperation(operation);
+    m_delegate-&gt;getCount(IDBRequestData(operation), keyRangeData);
+}
+
+void IDBConnectionToServer::didGetCount(const IDBResultData&amp; resultData)
+{
+    LOG(IndexedDB, &quot;IDBConnectionToServer::didGetCount&quot;);
+    completeOperation(resultData);
+}
+
</ins><span class="cx"> void IDBConnectionToServer::establishTransaction(IDBTransaction&amp; transaction)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBConnectionToServer::establishTransaction&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -76,6 +76,9 @@
</span><span class="cx">     void getRecord(TransactionOperation&amp;, const IDBKeyRangeData&amp;);
</span><span class="cx">     void didGetRecord(const IDBResultData&amp;);
</span><span class="cx"> 
</span><ins>+    void getCount(TransactionOperation&amp;, const IDBKeyRangeData&amp;);
+    void didGetCount(const IDBResultData&amp;);
+
</ins><span class="cx">     void commitTransaction(IDBTransaction&amp;);
</span><span class="cx">     void didCommitTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -61,6 +61,7 @@
</span><span class="cx">     virtual void clearObjectStore(const IDBRequestData&amp;, uint64_t objectStoreIdentifier) = 0;
</span><span class="cx">     virtual void putOrAdd(const IDBRequestData&amp;, IDBKey*, SerializedScriptValue&amp;, const IndexedDB::ObjectStoreOverwriteMode) = 0;
</span><span class="cx">     virtual void getRecord(const IDBRequestData&amp;, const IDBKeyRangeData&amp;) = 0;
</span><ins>+    virtual void getCount(const IDBRequestData&amp;, const IDBKeyRangeData&amp;) = 0;
</ins><span class="cx">     virtual void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&amp;) = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBObjectStoreImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -325,21 +325,71 @@
</span><span class="cx">     RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext*, ExceptionCode&amp;)
</del><ins>+RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext* context, ExceptionCode&amp; ec)
</ins><span class="cx"> {
</span><del>-    RELEASE_ASSERT_NOT_REACHED();
</del><ins>+    LOG(IndexedDB, &quot;IDBObjectStore::count&quot;);
+
+    if (!context) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    IDBKeyRangeData range;
+    range.isNull = false;
+    return doCount(*context, range, ec);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext*, IDBKeyRange*, ExceptionCode&amp;)
</del><ins>+RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext* context, const Deprecated::ScriptValue&amp; key, ExceptionCode&amp; ec)
</ins><span class="cx"> {
</span><del>-    RELEASE_ASSERT_NOT_REACHED();
</del><ins>+    LOG(IndexedDB, &quot;IDBObjectStore::count&quot;);
+
+    if (!context) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    DOMRequestState requestState(context);
+    RefPtr&lt;IDBKey&gt; idbKey = scriptValueToIDBKey(&amp;requestState, key);
+    if (!idbKey || idbKey-&gt;type() == KeyType::Invalid) {
+        ec = static_cast&lt;ExceptionCode&gt;(IDBExceptionCode::DataError);
+        return nullptr;
+    }
+
+    return doCount(*context, IDBKeyRangeData(idbKey.get()), ec);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext*, const Deprecated::ScriptValue&amp;, ExceptionCode&amp;)
</del><ins>+RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::count(ScriptExecutionContext* context, IDBKeyRange* range, ExceptionCode&amp; ec)
</ins><span class="cx"> {
</span><del>-    RELEASE_ASSERT_NOT_REACHED();
</del><ins>+    LOG(IndexedDB, &quot;IDBObjectStore::count&quot;);
+
+    if (!context) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    return doCount(*context, IDBKeyRangeData(range), ec);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr&lt;WebCore::IDBRequest&gt; IDBObjectStore::doCount(ScriptExecutionContext&amp; context, const IDBKeyRangeData&amp; range, ExceptionCode&amp; ec)
+{
+    if (!m_transaction-&gt;isActive()) {
+        ec = static_cast&lt;ExceptionCode&gt;(IDBExceptionCode::TransactionInactiveError);
+        return nullptr;
+    }
+
+    if (m_deleted) {
+        ec = INVALID_STATE_ERR;
+        return nullptr;
+    }
+
+    if (range.isNull) {
+        ec = static_cast&lt;ExceptionCode&gt;(IDBExceptionCode::DataError);
+        return nullptr;
+    }
+
+    return m_transaction-&gt;requestCount(context, *this, range);
+}
+
</ins><span class="cx"> void IDBObjectStore::markAsDeleted()
</span><span class="cx"> {
</span><span class="cx">     m_deleted = true;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBObjectStoreImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -36,6 +36,8 @@
</span><span class="cx"> 
</span><span class="cx"> class IDBKey;
</span><span class="cx"> 
</span><ins>+struct IDBKeyRangeData;
+
</ins><span class="cx"> namespace IDBClient {
</span><span class="cx"> 
</span><span class="cx"> class IDBTransaction;
</span><span class="lines">@@ -83,6 +85,7 @@
</span><span class="cx">     IDBObjectStore(const IDBObjectStoreInfo&amp;, IDBTransaction&amp;);
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebCore::IDBRequest&gt; putOrAdd(JSC::ExecState&amp;, JSC::JSValue, RefPtr&lt;IDBKey&gt;, IndexedDB::ObjectStoreOverwriteMode, ExceptionCode&amp;);
</span><ins>+    RefPtr&lt;WebCore::IDBRequest&gt; doCount(ScriptExecutionContext&amp;, const IDBKeyRangeData&amp;, ExceptionCode&amp;);
</ins><span class="cx"> 
</span><span class="cx">     IDBObjectStoreInfo m_info;
</span><span class="cx">     Ref&lt;IDBTransaction&gt; m_transaction;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBRequestImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -184,6 +184,12 @@
</span><span class="cx">     m_result = IDBAny::create(WTF::move(value));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBRequest::setResult(uint64_t number)
+{
+    ASSERT(scriptExecutionContext());
+    m_result = IDBAny::create(Deprecated::ScriptValue(scriptExecutionContext()-&gt;vm(), JSC::JSValue(number)));
+}
+
</ins><span class="cx"> void IDBRequest::setResultToStructuredClone(const ThreadSafeDataBuffer&amp; valueData)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBRequest::setResultToStructuredClone&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBRequestImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -78,6 +78,7 @@
</span><span class="cx">     void requestCompleted(const IDBResultData&amp;);
</span><span class="cx"> 
</span><span class="cx">     void setResult(const IDBKeyData*);
</span><ins>+    void setResult(uint64_t);
</ins><span class="cx">     void setResultToStructuredClone(const ThreadSafeDataBuffer&amp;);
</span><span class="cx">     void setResultToUndefined();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -431,6 +431,35 @@
</span><span class="cx">     request.requestCompleted(resultData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Ref&lt;IDBRequest&gt; IDBTransaction::requestCount(ScriptExecutionContext&amp; context, IDBObjectStore&amp; objectStore, const IDBKeyRangeData&amp; range)
+{
+    LOG(IndexedDB, &quot;IDBTransaction::requestCount&quot;);
+    ASSERT(isActive());
+    ASSERT(!range.isNull);
+
+    Ref&lt;IDBRequest&gt; request = IDBRequest::create(context, objectStore, *this);
+    addRequest(request.get());
+
+    scheduleOperation(createTransactionOperation(*this, request.get(), &amp;IDBTransaction::didGetCountOnServer, &amp;IDBTransaction::getCountOnServer, range));
+
+    return request;
+}
+
+void IDBTransaction::getCountOnServer(TransactionOperation&amp; operation, const IDBKeyRangeData&amp; keyRange)
+{
+    LOG(IndexedDB, &quot;IDBTransaction::getCountOnServer&quot;);
+
+    serverConnection().getCount(operation, keyRange);
+}
+
+void IDBTransaction::didGetCountOnServer(IDBRequest&amp; request, const IDBResultData&amp; resultData)
+{
+    LOG(IndexedDB, &quot;IDBTransaction::didGetCountOnServer&quot;);
+
+    request.setResult(resultData.resultInteger());
+    request.requestCompleted(resultData);
+}
+
</ins><span class="cx"> Ref&lt;IDBRequest&gt; IDBTransaction::requestClearObjectStore(ScriptExecutionContext&amp; context, IDBObjectStore&amp; objectStore)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBTransaction::requestClearObjectStore&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBTransactionImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -92,6 +92,7 @@
</span><span class="cx">     Ref&lt;IDBRequest&gt; requestPutOrAdd(ScriptExecutionContext&amp;, IDBObjectStore&amp;, IDBKey*, SerializedScriptValue&amp;, IndexedDB::ObjectStoreOverwriteMode);
</span><span class="cx">     Ref&lt;IDBRequest&gt; requestGetRecord(ScriptExecutionContext&amp;, IDBObjectStore&amp;, const IDBKeyRangeData&amp;);
</span><span class="cx">     Ref&lt;IDBRequest&gt; requestClearObjectStore(ScriptExecutionContext&amp;, IDBObjectStore&amp;);
</span><ins>+    Ref&lt;IDBRequest&gt; requestCount(ScriptExecutionContext&amp;, IDBObjectStore&amp;, const IDBKeyRangeData&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void deleteObjectStore(const String&amp; objectStoreName);
</span><span class="cx"> 
</span><span class="lines">@@ -136,6 +137,9 @@
</span><span class="cx">     void getRecordOnServer(TransactionOperation&amp;, const IDBKeyRangeData&amp;);
</span><span class="cx">     void didGetRecordOnServer(IDBRequest&amp;, const IDBResultData&amp;);
</span><span class="cx"> 
</span><ins>+    void getCountOnServer(TransactionOperation&amp;, const IDBKeyRangeData&amp;);
+    void didGetCountOnServer(IDBRequest&amp;, const IDBResultData&amp;);
+
</ins><span class="cx">     void deleteObjectStoreOnServer(TransactionOperation&amp;, const String&amp; objectStoreName);
</span><span class="cx">     void didDeleteObjectStoreOnServer(const IDBResultData&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx">     virtual IDBError deleteRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp;) = 0;
</span><span class="cx">     virtual IDBError putRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; value) = 0;
</span><span class="cx">     virtual IDBError getRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;, ThreadSafeDataBuffer&amp; outValue) = 0;
</span><ins>+    virtual IDBError getCount(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;, uint64_t&amp; outCount) = 0;
</ins><span class="cx">     virtual IDBError generateKeyNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t&amp; keyNumber) = 0;
</span><span class="cx"> 
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -88,6 +88,11 @@
</span><span class="cx">     m_delegate-&gt;didGetRecord(result);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBConnectionToClient::didGetCount(const IDBResultData&amp; result)
+{
+    m_delegate-&gt;didGetCount(result);
+}
+
</ins><span class="cx"> void IDBConnectionToClient::didCommitTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp; error)
</span><span class="cx"> {
</span><span class="cx">     m_delegate-&gt;didCommitTransaction(transactionIdentifier, error);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx">     void didClearObjectStore(const IDBResultData&amp;);
</span><span class="cx">     void didPutOrAdd(const IDBResultData&amp;);
</span><span class="cx">     void didGetRecord(const IDBResultData&amp;);
</span><ins>+    void didGetCount(const IDBResultData&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void fireVersionChangeEvent(UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion);
</span><span class="cx">     void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx">     virtual void didClearObjectStore(const IDBResultData&amp;) = 0;
</span><span class="cx">     virtual void didPutOrAdd(const IDBResultData&amp;) = 0;
</span><span class="cx">     virtual void didGetRecord(const IDBResultData&amp;) = 0;
</span><ins>+    virtual void didGetCount(const IDBResultData&amp;) = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual void fireVersionChangeEvent(UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion) = 0;
</span><span class="cx">     virtual void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;) = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -213,6 +213,17 @@
</span><span class="cx">     transaction-&gt;getRecord(requestData, keyRangeData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBServer::getCount(const IDBRequestData&amp; requestData, const IDBKeyRangeData&amp; keyRangeData)
+{
+    LOG(IndexedDB, &quot;IDBServer::getCount&quot;);
+
+    auto transaction = m_transactions.get(requestData.transactionIdentifier());
+    if (!transaction)
+        return;
+
+    transaction-&gt;getCount(requestData, keyRangeData);
+}
+
</ins><span class="cx"> void IDBServer::establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&amp; info)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBServer::establishTransaction&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx">     void clearObjectStore(const IDBRequestData&amp;, uint64_t objectStoreIdentifier);
</span><span class="cx">     void putOrAdd(const IDBRequestData&amp;, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; valueData, IndexedDB::ObjectStoreOverwriteMode);
</span><span class="cx">     void getRecord(const IDBRequestData&amp;, const IDBKeyRangeData&amp;);
</span><ins>+    void getCount(const IDBRequestData&amp;, const IDBKeyRangeData&amp;);
</ins><span class="cx">     void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&amp;);
</span><span class="cx">     void databaseConnectionClosed(uint64_t databaseConnectionIdentifier);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -259,6 +259,23 @@
</span><span class="cx">     return IDBError();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IDBError MemoryIDBBackingStore::getCount(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp; range, uint64_t&amp; outCount)
+{
+    LOG(IndexedDB, &quot;MemoryIDBBackingStore::getCount&quot;);
+
+    ASSERT(objectStoreIdentifier);
+
+    if (!m_transactions.contains(transactionIdentifier))
+        return IDBError(IDBExceptionCode::Unknown, WTF::ASCIILiteral(&quot;No backing store transaction found to get count&quot;));
+
+    MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier);
+    if (!objectStore)
+        return IDBError(IDBExceptionCode::Unknown, WTF::ASCIILiteral(&quot;No backing store object store found&quot;));
+
+    outCount = objectStore-&gt;countForKeyRange(range);
+    return IDBError();
+}
+
</ins><span class="cx"> IDBError MemoryIDBBackingStore::generateKeyNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t&amp; keyNumber)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;MemoryIDBBackingStore::generateKeyNumber&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     virtual IDBError deleteRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp;) override final;
</span><span class="cx">     virtual IDBError putRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; value) override final;
</span><span class="cx">     virtual IDBError getRecord(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;, ThreadSafeDataBuffer&amp; outValue) override final;
</span><ins>+    virtual IDBError getCount(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;, uint64_t&amp; outCount) override final;
</ins><span class="cx">     virtual IDBError generateKeyNumber(const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t&amp; keyNumber) override final;
</span><span class="cx"> 
</span><span class="cx">     void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -131,37 +131,69 @@
</span><span class="cx">         m_orderedKeys-&gt;insert(keyData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+uint64_t MemoryObjectStore::countForKeyRange(const IDBKeyRangeData&amp; inRange) const
+{
+    LOG(IndexedDB, &quot;MemoryObjectStore::countForKeyRange&quot;);
+
+    if (!m_keyValueStore)
+        return 0;
+
+    uint64_t count = 0;
+    IDBKeyRangeData range = inRange;
+    while (true) {
+        auto key = lowestKeyWithRecordInRange(range);
+        if (key.isNull())
+            break;
+
+        ++count;
+        range.lowerKey = key;
+        range.lowerOpen = true;
+    }
+
+    return count;
+}
+
</ins><span class="cx"> ThreadSafeDataBuffer MemoryObjectStore::valueForKeyRange(const IDBKeyRangeData&amp; keyRangeData) const
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;MemoryObjectStore::valueForKey&quot;);
</span><span class="cx"> 
</span><del>-    if (!m_keyValueStore)
</del><ins>+    IDBKeyData key = lowestKeyWithRecordInRange(keyRangeData);
+    if (key.isNull())
</ins><span class="cx">         return ThreadSafeDataBuffer();
</span><span class="cx"> 
</span><del>-    if (keyRangeData.isExactlyOneKey())
-        return m_keyValueStore-&gt;get(keyRangeData.lowerKey);
</del><ins>+    ASSERT(m_keyValueStore);
+    return m_keyValueStore-&gt;get(key);
+}
</ins><span class="cx"> 
</span><ins>+IDBKeyData MemoryObjectStore::lowestKeyWithRecordInRange(const IDBKeyRangeData&amp; keyRangeData) const
+{
+    if (!m_keyValueStore)
+        return { };
+
+    if (keyRangeData.isExactlyOneKey() &amp;&amp; m_keyValueStore-&gt;contains(keyRangeData.lowerKey))
+        return keyRangeData.lowerKey;
+
</ins><span class="cx">     ASSERT(m_orderedKeys);
</span><span class="cx"> 
</span><span class="cx">     auto lowestInRange = m_orderedKeys-&gt;lower_bound(keyRangeData.lowerKey);
</span><span class="cx"> 
</span><span class="cx">     if (lowestInRange == m_orderedKeys-&gt;end())
</span><del>-        return ThreadSafeDataBuffer();
</del><ins>+        return { };
</ins><span class="cx"> 
</span><span class="cx">     if (keyRangeData.lowerOpen &amp;&amp; *lowestInRange == keyRangeData.lowerKey)
</span><span class="cx">         ++lowestInRange;
</span><span class="cx"> 
</span><span class="cx">     if (lowestInRange == m_orderedKeys-&gt;end())
</span><del>-        return ThreadSafeDataBuffer();
</del><ins>+        return { };
</ins><span class="cx"> 
</span><span class="cx">     if (!keyRangeData.upperKey.isNull()) {
</span><span class="cx">         if (lowestInRange-&gt;compare(keyRangeData.upperKey) &gt; 0)
</span><del>-            return ThreadSafeDataBuffer();
</del><ins>+            return { };
</ins><span class="cx">         if (keyRangeData.upperOpen &amp;&amp; *lowestInRange == keyRangeData.upperKey)
</span><del>-            return ThreadSafeDataBuffer();
</del><ins>+            return { };
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return m_keyValueStore-&gt;get(*lowestInRange);
</del><ins>+    return *lowestInRange;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverMemoryObjectStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -69,12 +69,15 @@
</span><span class="cx">     void replaceKeyValueStore(std::unique_ptr&lt;KeyValueMap&gt;&amp;&amp;);
</span><span class="cx"> 
</span><span class="cx">     ThreadSafeDataBuffer valueForKeyRange(const IDBKeyRangeData&amp;) const;
</span><ins>+    uint64_t countForKeyRange(const IDBKeyRangeData&amp;) const;
</ins><span class="cx"> 
</span><span class="cx">     const IDBObjectStoreInfo&amp; info() const { return m_info; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     MemoryObjectStore(const IDBObjectStoreInfo&amp;);
</span><span class="cx"> 
</span><ins>+    IDBKeyData lowestKeyWithRecordInRange(const IDBKeyRangeData&amp;) const;
+
</ins><span class="cx">     IDBObjectStoreInfo m_info;
</span><span class="cx"> 
</span><span class="cx">     MemoryBackingStoreTransaction* m_writeTransaction { nullptr };
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -136,24 +136,35 @@
</span><span class="cx"> uint64_t UniqueIDBDatabase::storeCallback(ErrorCallback callback)
</span><span class="cx"> {
</span><span class="cx">     uint64_t identifier = generateUniqueCallbackIdentifier();
</span><del>-    m_errorCallbacks.set(identifier, callback);
</del><ins>+    ASSERT(!m_errorCallbacks.contains(identifier));
+    m_errorCallbacks.add(identifier, callback);
</ins><span class="cx">     return identifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> uint64_t UniqueIDBDatabase::storeCallback(KeyDataCallback callback)
</span><span class="cx"> {
</span><span class="cx">     uint64_t identifier = generateUniqueCallbackIdentifier();
</span><del>-    m_keyDataCallbacks.set(identifier, callback);
</del><ins>+    ASSERT(!m_keyDataCallbacks.contains(identifier));
+    m_keyDataCallbacks.add(identifier, callback);
</ins><span class="cx">     return identifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> uint64_t UniqueIDBDatabase::storeCallback(ValueDataCallback callback)
</span><span class="cx"> {
</span><span class="cx">     uint64_t identifier = generateUniqueCallbackIdentifier();
</span><del>-    m_valueDataCallbacks.set(identifier, callback);
</del><ins>+    ASSERT(!m_valueDataCallbacks.contains(identifier));
+    m_valueDataCallbacks.add(identifier, callback);
</ins><span class="cx">     return identifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+uint64_t UniqueIDBDatabase::storeCallback(CountCallback callback)
+{
+    uint64_t identifier = generateUniqueCallbackIdentifier();
+    ASSERT(!m_countCallbacks.contains(identifier));
+    m_countCallbacks.add(identifier, callback);
+    return identifier;
+}
+
</ins><span class="cx"> void UniqueIDBDatabase::startVersionChangeTransaction()
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;(main) UniqueIDBDatabase::startVersionChangeTransaction&quot;);
</span><span class="lines">@@ -431,6 +442,37 @@
</span><span class="cx">     performValueDataCallback(callbackIdentifier, error, resultData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void UniqueIDBDatabase::getCount(const IDBRequestData&amp; requestData, const IDBKeyRangeData&amp; range, CountCallback callback)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, &quot;(main) UniqueIDBDatabase::getCount&quot;);
+
+    uint64_t callbackID = storeCallback(callback);
+    m_server.postDatabaseTask(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::performGetCount, callbackID, requestData.transactionIdentifier(), requestData.objectStoreIdentifier(), range));
+}
+
+void UniqueIDBDatabase::performGetCount(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp; keyRangeData)
+{
+    ASSERT(!isMainThread());
+    LOG(IndexedDB, &quot;(db) UniqueIDBDatabase::performGetCount&quot;);
+
+    ASSERT(m_backingStore);
+    ASSERT(objectStoreIdentifier);
+
+    uint64_t count;
+    IDBError error = m_backingStore-&gt;getCount(transactionIdentifier, objectStoreIdentifier, keyRangeData, count);
+
+    m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &amp;UniqueIDBDatabase::didPerformGetCount, callbackIdentifier, error, count));
+}
+
+void UniqueIDBDatabase::didPerformGetCount(uint64_t callbackIdentifier, const IDBError&amp; error, uint64_t count)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, &quot;(main) UniqueIDBDatabase::didPerformGetCount&quot;);
+
+    performCountCallback(callbackIdentifier, error, count);
+}
+
</ins><span class="cx"> void UniqueIDBDatabase::commitTransaction(UniqueIDBDatabaseTransaction&amp; transaction, ErrorCallback callback)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><span class="lines">@@ -701,6 +743,13 @@
</span><span class="cx">     callback(error, resultData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void UniqueIDBDatabase::performCountCallback(uint64_t callbackIdentifier, const IDBError&amp; error, uint64_t count)
+{
+    auto callback = m_countCallbacks.take(callbackIdentifier);
+    ASSERT(callback);
+    callback(error, count);
+}
+
</ins><span class="cx"> } // namespace IDBServer
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx"> typedef std::function&lt;void(const IDBError&amp;)&gt; ErrorCallback;
</span><span class="cx"> typedef std::function&lt;void(const IDBError&amp;, const IDBKeyData&amp;)&gt; KeyDataCallback;
</span><span class="cx"> typedef std::function&lt;void(const IDBError&amp;, const ThreadSafeDataBuffer&amp;)&gt; ValueDataCallback;
</span><ins>+typedef std::function&lt;void(const IDBError&amp;, uint64_t)&gt; CountCallback;
</ins><span class="cx"> 
</span><span class="cx"> class UniqueIDBDatabase : public ThreadSafeRefCounted&lt;UniqueIDBDatabase&gt; {
</span><span class="cx"> public:
</span><span class="lines">@@ -74,6 +75,7 @@
</span><span class="cx">     void clearObjectStore(UniqueIDBDatabaseTransaction&amp;, uint64_t objectStoreIdentifier, ErrorCallback);
</span><span class="cx">     void putOrAdd(const IDBRequestData&amp;, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; valueData, IndexedDB::ObjectStoreOverwriteMode, KeyDataCallback);
</span><span class="cx">     void getRecord(const IDBRequestData&amp;, const IDBKeyRangeData&amp;, ValueDataCallback);
</span><ins>+    void getCount(const IDBRequestData&amp;, const IDBKeyRangeData&amp;, CountCallback);
</ins><span class="cx">     void commitTransaction(UniqueIDBDatabaseTransaction&amp;, ErrorCallback);
</span><span class="cx">     void abortTransaction(UniqueIDBDatabaseTransaction&amp;, ErrorCallback);
</span><span class="cx">     void transactionDestroyed(UniqueIDBDatabaseTransaction&amp;);
</span><span class="lines">@@ -104,6 +106,7 @@
</span><span class="cx">     void performClearObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier);
</span><span class="cx">     void performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; valueData, IndexedDB::ObjectStoreOverwriteMode);
</span><span class="cx">     void performGetRecord(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;);
</span><ins>+    void performGetCount(uint64_t callbackIdentifier, const IDBResourceIdentifier&amp; transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&amp;);
</ins><span class="cx">     void performActivateTransactionInBackingStore(uint64_t callbackIdentifier, const IDBTransactionInfo&amp;);
</span><span class="cx"> 
</span><span class="cx">     // Main thread callbacks
</span><span class="lines">@@ -113,6 +116,7 @@
</span><span class="cx">     void didPerformClearObjectStore(uint64_t callbackIdentifier, const IDBError&amp;);
</span><span class="cx">     void didPerformPutOrAdd(uint64_t callbackIdentifier, const IDBError&amp;, const IDBKeyData&amp;);
</span><span class="cx">     void didPerformGetRecord(uint64_t callbackIdentifier, const IDBError&amp;, const ThreadSafeDataBuffer&amp;);
</span><ins>+    void didPerformGetCount(uint64_t callbackIdentifier, const IDBError&amp;, uint64_t);
</ins><span class="cx">     void didPerformCommitTransaction(uint64_t callbackIdentifier, const IDBError&amp;, const IDBResourceIdentifier&amp; transactionIdentifier);
</span><span class="cx">     void didPerformAbortTransaction(uint64_t callbackIdentifier, const IDBError&amp;, const IDBResourceIdentifier&amp; transactionIdentifier);
</span><span class="cx">     void didPerformActivateTransactionInBackingStore(uint64_t callbackIdentifier, const IDBError&amp;);
</span><span class="lines">@@ -120,10 +124,12 @@
</span><span class="cx">     uint64_t storeCallback(ErrorCallback);
</span><span class="cx">     uint64_t storeCallback(KeyDataCallback);
</span><span class="cx">     uint64_t storeCallback(ValueDataCallback);
</span><ins>+    uint64_t storeCallback(CountCallback);
</ins><span class="cx"> 
</span><span class="cx">     void performErrorCallback(uint64_t callbackIdentifier, const IDBError&amp;);
</span><span class="cx">     void performKeyDataCallback(uint64_t callbackIdentifier, const IDBError&amp;, const IDBKeyData&amp;);
</span><span class="cx">     void performValueDataCallback(uint64_t callbackIdentifier, const IDBError&amp;, const ThreadSafeDataBuffer&amp;);
</span><ins>+    void performCountCallback(uint64_t callbackIdentifier, const IDBError&amp;, uint64_t);
</ins><span class="cx"> 
</span><span class="cx">     void invokeTransactionScheduler();
</span><span class="cx">     void transactionSchedulingTimerFired();
</span><span class="lines">@@ -147,6 +153,7 @@
</span><span class="cx">     HashMap&lt;uint64_t, ErrorCallback&gt; m_errorCallbacks;
</span><span class="cx">     HashMap&lt;uint64_t, KeyDataCallback&gt; m_keyDataCallbacks;
</span><span class="cx">     HashMap&lt;uint64_t, ValueDataCallback&gt; m_valueDataCallbacks;
</span><ins>+    HashMap&lt;uint64_t, CountCallback&gt; m_countCallbacks;
</ins><span class="cx"> 
</span><span class="cx">     Timer m_transactionSchedulingTimer;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseTransactioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -181,6 +181,23 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void UniqueIDBDatabaseTransaction::getCount(const IDBRequestData&amp; requestData, const IDBKeyRangeData&amp; keyRangeData)
+{
+    LOG(IndexedDB, &quot;UniqueIDBDatabaseTransaction::getCount&quot;);
+
+    ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
+
+    RefPtr&lt;UniqueIDBDatabaseTransaction&gt; self(this);
+    m_databaseConnection-&gt;database().getCount(requestData, keyRangeData, [this, self, requestData](const IDBError&amp; error, uint64_t count) {
+        LOG(IndexedDB, &quot;UniqueIDBDatabaseTransaction::getCount (callback)&quot;);
+
+        if (error.isNull())
+            m_databaseConnection-&gt;connectionToClient().didGetCount(IDBResultData::getCountSuccess(requestData.requestIdentifier(), count));
+        else
+            m_databaseConnection-&gt;connectionToClient().didGetCount(IDBResultData::error(requestData.requestIdentifier(), error));
+    });
+}
+
</ins><span class="cx"> const Vector&lt;uint64_t&gt;&amp; UniqueIDBDatabaseTransaction::objectStoreIdentifiers()
</span><span class="cx"> {
</span><span class="cx">     if (!m_objectStoreIdentifiers.isEmpty())
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabaseTransactionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -69,6 +69,7 @@
</span><span class="cx">     void clearObjectStore(const IDBRequestData&amp;, uint64_t objectStoreIdentifier);
</span><span class="cx">     void putOrAdd(const IDBRequestData&amp;, const IDBKeyData&amp;, const ThreadSafeDataBuffer&amp; valueData, IndexedDB::ObjectStoreOverwriteMode);
</span><span class="cx">     void getRecord(const IDBRequestData&amp;, const IDBKeyRangeData&amp;);
</span><ins>+    void getCount(const IDBRequestData&amp;, const IDBKeyRangeData&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void didActivateInBackingStore(const IDBError&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedIDBResultDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -50,6 +50,7 @@
</span><span class="cx">     , m_requestIdentifier(other.m_requestIdentifier)
</span><span class="cx">     , m_error(other.m_error)
</span><span class="cx">     , m_databaseConnectionIdentifier(other.m_databaseConnectionIdentifier)
</span><ins>+    , m_resultInteger(other.m_resultInteger)
</ins><span class="cx">     , m_resultData(other.m_resultData)
</span><span class="cx"> {
</span><span class="cx">     if (other.m_databaseInfo)
</span><span class="lines">@@ -117,6 +118,13 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IDBResultData IDBResultData::getCountSuccess(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t count)
+{
+    IDBResultData result(IDBResultType::GetRecordSuccess, requestIdentifier);
+    result.m_resultInteger = count;
+    return result;
+}
+
</ins><span class="cx"> const IDBDatabaseInfo&amp; IDBResultData::databaseInfo() const
</span><span class="cx"> {
</span><span class="cx">     RELEASE_ASSERT(m_databaseInfo);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedIDBResultDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx">     ClearObjectStoreSuccess,
</span><span class="cx">     PutOrAddSuccess,
</span><span class="cx">     GetRecordSuccess,
</span><ins>+    GetCountSuccess,
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> namespace IDBServer {
</span><span class="lines">@@ -66,6 +67,7 @@
</span><span class="cx">     static IDBResultData clearObjectStoreSuccess(const IDBResourceIdentifier&amp;);
</span><span class="cx">     static IDBResultData putOrAddSuccess(const IDBResourceIdentifier&amp;, const IDBKeyData&amp;);
</span><span class="cx">     static IDBResultData getRecordSuccess(const IDBResourceIdentifier&amp;, const ThreadSafeDataBuffer&amp; valueData);
</span><ins>+    static IDBResultData getCountSuccess(const IDBResourceIdentifier&amp;, uint64_t count);
</ins><span class="cx"> 
</span><span class="cx">     IDBResultData(const IDBResultData&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -80,6 +82,7 @@
</span><span class="cx"> 
</span><span class="cx">     const IDBKeyData* resultKey() const { return m_resultKey.get(); }
</span><span class="cx">     const ThreadSafeDataBuffer&amp; resultData() const { return m_resultData; }
</span><ins>+    uint64_t resultInteger() const { return m_resultInteger; }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     IDBResultData(const IDBResourceIdentifier&amp;);
</span><span class="lines">@@ -93,6 +96,7 @@
</span><span class="cx">     std::unique_ptr&lt;IDBDatabaseInfo&gt; m_databaseInfo;
</span><span class="cx">     std::unique_ptr&lt;IDBTransactionInfo&gt; m_transactionInfo;
</span><span class="cx">     std::unique_ptr&lt;IDBKeyData&gt; m_resultKey;
</span><ins>+    uint64_t m_resultInteger { 0 };
</ins><span class="cx">     ThreadSafeDataBuffer m_resultData;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -159,6 +159,14 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InProcessIDBServer::didGetCount(const IDBResultData&amp; resultData)
+{
+    RefPtr&lt;InProcessIDBServer&gt; self(this);
+    RunLoop::current().dispatch([this, self, resultData] {
+        m_connectionToServer-&gt;didGetCount(resultData);
+    });
+}
+
</ins><span class="cx"> void InProcessIDBServer::abortTransaction(IDBResourceIdentifier&amp; resourceIdentifier)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;InProcessIDBServer&gt; self(this);
</span><span class="lines">@@ -219,6 +227,13 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InProcessIDBServer::getCount(const IDBRequestData&amp; requestData, const IDBKeyRangeData&amp; keyRangeData)
+{
+    RefPtr&lt;InProcessIDBServer&gt; self(this);
+    RunLoop::current().dispatch([this, self, requestData, keyRangeData] {
+        m_server-&gt;getCount(requestData, keyRangeData);
+    });
+}
</ins><span class="cx"> void InProcessIDBServer::establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&amp; info)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;InProcessIDBServer&gt; self(this);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h (191876 => 191877)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2015-11-02 06:01:37 UTC (rev 191876)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2015-11-02 06:52:50 UTC (rev 191877)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx">     virtual void clearObjectStore(const IDBRequestData&amp;, uint64_t objectStoreIdentifier) override final;
</span><span class="cx">     virtual void putOrAdd(const IDBRequestData&amp;, IDBKey*, SerializedScriptValue&amp;, const IndexedDB::ObjectStoreOverwriteMode) override final;
</span><span class="cx">     virtual void getRecord(const IDBRequestData&amp;, const IDBKeyRangeData&amp;) override final;
</span><ins>+    virtual void getCount(const IDBRequestData&amp;, const IDBKeyRangeData&amp;) override final;
</ins><span class="cx">     virtual void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&amp;) override final;
</span><span class="cx">     virtual void databaseConnectionClosed(uint64_t databaseConnectionIdentifier) override final;
</span><span class="cx"> 
</span><span class="lines">@@ -77,6 +78,7 @@
</span><span class="cx">     virtual void didClearObjectStore(const IDBResultData&amp;) override final;
</span><span class="cx">     virtual void didPutOrAdd(const IDBResultData&amp;) override final;
</span><span class="cx">     virtual void didGetRecord(const IDBResultData&amp;) override final;
</span><ins>+    virtual void didGetCount(const IDBResultData&amp;) override final;
</ins><span class="cx">     virtual void fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion) override final;
</span><span class="cx">     virtual void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;) override final;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>