Modern IDB: IDBObjectStore.clear() support.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 23:20:02 +0000 (23:20 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 23:20:02 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150733

Reviewed by Alex Christensen.

Source/WebCore:

Tests: storage/indexeddb/modern/idbobjectstore-clear-1.html
       storage/indexeddb/modern/idbobjectstore-clear-2.html

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::clearObjectStore):
(WebCore::IDBClient::IDBConnectionToServer::didClearObjectStore):
* Modules/indexeddb/client/IDBConnectionToServer.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:

* Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
(WebCore::IDBClient::IDBObjectStore::clear):

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

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::requestClearObjectStore):
(WebCore::IDBClient::IDBTransaction::clearObjectStoreOnServer):
(WebCore::IDBClient::IDBTransaction::didClearObjectStoreOnServer):
* Modules/indexeddb/client/IDBTransactionImpl.h:

* Modules/indexeddb/server/IDBBackingStore.h:

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

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

* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::objectStoreCleared):
(WebCore::IDBServer::MemoryBackingStoreTransaction::recordValueChanged):
(WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
* Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
(WebCore::IDBServer::MemoryBackingStoreTransaction::isAborting):

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

* Modules/indexeddb/server/MemoryObjectStore.cpp:
(WebCore::IDBServer::MemoryObjectStore::clear):
(WebCore::IDBServer::MemoryObjectStore::replaceKeyValueStore):
* Modules/indexeddb/server/MemoryObjectStore.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::clearObjectStore):
(WebCore::IDBServer::UniqueIDBDatabase::performClearObjectStore):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformClearObjectStore):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

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

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

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

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::didClearObjectStore):
(WebCore::InProcessIDBServer::clearObjectStore):
* Modules/indexeddb/shared/InProcessIDBServer.h:

LayoutTests:

* storage/indexeddb/modern/idbobjectstore-clear-1-expected.txt: Added.
* storage/indexeddb/modern/idbobjectstore-clear-1.html: Added.
* storage/indexeddb/modern/idbobjectstore-clear-2-expected.txt: Added.
* storage/indexeddb/modern/idbobjectstore-clear-2.html: Added.
* storage/indexeddb/modern/idbobjectstore-put-and-clear-failures-expected.txt: Added.
* storage/indexeddb/modern/idbobjectstore-put-and-clear-failures.html: Added.

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

38 files changed:
LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h
Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.h
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp
Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h
Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp
Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h
Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/Modules/indexeddb/server/IDBServer.h
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp
Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.h
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp
Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h
Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp
Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h

index 1503216..503905c 100644 (file)
@@ -1,3 +1,17 @@
+2015-10-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: IDBObjectStore.clear() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150733
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/idbobjectstore-clear-1-expected.txt: Added.
+        * storage/indexeddb/modern/idbobjectstore-clear-1.html: Added.
+        * storage/indexeddb/modern/idbobjectstore-clear-2-expected.txt: Added.
+        * storage/indexeddb/modern/idbobjectstore-clear-2.html: Added.
+        * storage/indexeddb/modern/idbobjectstore-put-and-clear-failures-expected.txt: Added.
+        * storage/indexeddb/modern/idbobjectstore-put-and-clear-failures.html: Added.
+
 2015-10-30  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking imported/w3c/web-platform-tests/XMLHttpRequest/send-timeout-events.htm as flaky on win
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1-expected.txt b/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1-expected.txt
new file mode 100644 (file)
index 0000000..744ca7c
--- /dev/null
@@ -0,0 +1,27 @@
+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Success opening database connection - Starting readwrite transaction
+ALERT: Value gotten was bar1
+ALERT: Value gotten was bar2
+ALERT: Value gotten was bar3
+ALERT: Value gotten was bar4
+ALERT: Value gotten was bar5
+ALERT: Value gotten was bar6
+ALERT: Value gotten was bar7
+ALERT: Value gotten was bar8
+ALERT: Value gotten was bar9
+ALERT: Object store cleared
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Readwrite transaction complete
+ALERT: Done
+This test creates an object store then populates it.
+It then clears it and makes sure it has nothing left in it.
+
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1.html b/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-1.html
new file mode 100644 (file)
index 0000000..0e5efaf
--- /dev/null
@@ -0,0 +1,111 @@
+This test creates an object store then populates it.<br>
+It then clears it and makes sure it has nothing left in it.<br>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open("IDBObjectStoreClearDatabase", 1);
+
+createRequest.onupgradeneeded = function(event) {
+    alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    var database = event.target.result;
+    var objectStore = database.createObjectStore("TestObjectStore", { autoIncrement: true });
+    var request = objectStore.put("bar1");
+    var request = objectStore.put("bar2");
+    var request = objectStore.put("bar3");
+    var request = objectStore.put("bar4");
+    var request = objectStore.put("bar5");
+    var request = objectStore.put("bar6");
+    var request = objectStore.put("bar7");
+    var request = objectStore.put("bar8");
+    var request = objectStore.put("bar9");
+
+    versionTransaction.onabort = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected aborted");
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        alert("Initial upgrade versionchange transaction complete");
+        continueTest1();
+        database.close();
+    }
+
+    versionTransaction.onerror = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected error" + event);
+        done();
+    }
+}
+
+function getChecker(event) {
+    alert("Value gotten was " + event.target.result);
+}
+
+function continueTest1()
+{
+    var openRequest = window.indexedDB.open("IDBObjectStoreClearDatabase", 1);
+
+    openRequest.onerror = function(event) {
+        alert("Request unexpected error - " + event);
+        done();
+    }
+    openRequest.onblocked = function(event) {
+        alert("Request unexpected blocked - " + event);
+        done();
+    }
+    openRequest.onupgradeneeded = function(event) {
+        alert("Request unexpected upgradeneeded - " + event);
+        done();
+    }
+
+    openRequest.onsuccess = function(event) {
+        alert("Success opening database connection - Starting readwrite transaction");
+        var database = event.target.result;
+        var transaction = database.transaction("TestObjectStore", "readwrite");
+        var objectStore = transaction.objectStore("TestObjectStore");
+    
+        var request;
+        for (var i = 1; i <= 9; ++i) {
+            request = objectStore.get(i);
+            request.onsuccess = getChecker;
+        }
+        
+        request = objectStore.clear();
+        request.onsuccess = function() {
+            alert("Object store cleared");
+            var newRequests;
+            for (var i = 1; i <= 9; ++i) {
+                newRequests = objectStore.get(i);
+                newRequests.onsuccess = getChecker;
+            }    
+        }
+
+        transaction.onabort = function(event) {
+            alert("Readwrite transaction unexpected abort");
+            done();
+        }
+
+        transaction.oncomplete = function(event) {
+            alert("Readwrite transaction complete");
+            done();
+        }
+
+        transaction.onerror = function(event) {
+            alert("Readwrite transaction unexpected error - " + event);
+            done();
+        }
+    }
+}
+</script>
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2-expected.txt b/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2-expected.txt
new file mode 100644 (file)
index 0000000..d600c53
--- /dev/null
@@ -0,0 +1,39 @@
+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Success opening database connection - Starting readwrite transaction
+ALERT: Value gotten was bar1
+ALERT: Value gotten was bar2
+ALERT: Value gotten was bar3
+ALERT: Value gotten was bar4
+ALERT: Value gotten was bar5
+ALERT: Value gotten was bar6
+ALERT: Value gotten was bar7
+ALERT: Value gotten was bar8
+ALERT: Value gotten was bar9
+ALERT: Object store cleared, making sure its all gone.
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Value gotten was undefined
+ALERT: Readwrite transaction abort
+ALERT: Success opening database connection - Starting final transaction
+ALERT: Value gotten was bar1
+ALERT: Value gotten was bar2
+ALERT: Value gotten was bar3
+ALERT: Value gotten was bar4
+ALERT: Value gotten was bar5
+ALERT: Value gotten was bar6
+ALERT: Value gotten was bar7
+ALERT: Value gotten was bar8
+ALERT: Value gotten was bar9
+ALERT: Readwrite transaction complete
+ALERT: Done
+This test creates an object store then populates it, then commits that transaction.
+It then clears it, but aborts that transaction.
+Finally it checks to make sure everything from step 1 is still in there.
+
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2.html b/LayoutTests/storage/indexeddb/modern/idbobjectstore-clear-2.html
new file mode 100644 (file)
index 0000000..bb25596
--- /dev/null
@@ -0,0 +1,167 @@
+This test creates an object store then populates it, then commits that transaction.<br>
+It then clears it, but aborts that transaction.<br>
+Finally it checks to make sure everything from step 1 is still in there.<br>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
+
+createRequest.onupgradeneeded = function(event) {
+    alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    var database = event.target.result;
+    var objectStore = database.createObjectStore("TestObjectStore", { autoIncrement: true });
+    var request = objectStore.put("bar1");
+    var request = objectStore.put("bar2");
+    var request = objectStore.put("bar3");
+    var request = objectStore.put("bar4");
+    var request = objectStore.put("bar5");
+    var request = objectStore.put("bar6");
+    var request = objectStore.put("bar7");
+    var request = objectStore.put("bar8");
+    var request = objectStore.put("bar9");
+
+    versionTransaction.onabort = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected aborted");
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        alert("Initial upgrade versionchange transaction complete");
+        continueTest1();
+        database.close();
+    }
+
+    versionTransaction.onerror = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected error" + event);
+        done();
+    }
+}
+
+function getChecker(event) {
+    alert("Value gotten was " + event.target.result);
+}
+
+function continueTest1()
+{
+    var openRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
+
+    openRequest.onerror = function(event) {
+        alert("Request unexpected error - " + event);
+        done();
+    }
+    openRequest.onblocked = function(event) {
+        alert("Request unexpected blocked - " + event);
+        done();
+    }
+    openRequest.onupgradeneeded = function(event) {
+        alert("Request unexpected upgradeneeded - " + event);
+        done();
+    }
+
+    openRequest.onsuccess = function(event) {
+        alert("Success opening database connection - Starting readwrite transaction");
+        var database = event.target.result;
+        var transaction = database.transaction("TestObjectStore", "readwrite");
+        var objectStore = transaction.objectStore("TestObjectStore");
+    
+        var request;
+        for (var i = 1; i <= 9; ++i) {
+            request = objectStore.get(i);
+            request.onsuccess = getChecker;
+        }
+        
+        request = objectStore.clear();
+        request.onsuccess = function() {
+            alert("Object store cleared, making sure its all gone.");
+            var newRequests;
+            for (var i = 1; i <= 9; ++i) {
+                newRequests = objectStore.get(i);
+                newRequests.onsuccess = getChecker;
+            }
+            
+            // We'll be on the last request here, can just override it.
+            newRequests.onsuccess = function(event) {
+                getChecker(event);
+                transaction.abort();
+            }
+        }
+        
+        // Just for fun clear it twice, won't change anything
+        objectStore.clear();
+
+        transaction.onabort = function(event) {
+            alert("Readwrite transaction abort");
+            continueTest2();
+        }
+
+        transaction.oncomplete = function(event) {
+            alert("Readwrite transaction unexpected complete");
+            done();
+        }
+
+        transaction.onerror = function(event) {
+            alert("Readwrite transaction unexpected error - " + event);
+            done();
+        }
+    }
+}
+
+function continueTest2()
+{
+    var openRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
+
+    openRequest.onerror = function(event) {
+        alert("Request unexpected error - " + event);
+        done();
+    }
+    openRequest.onblocked = function(event) {
+        alert("Request unexpected blocked - " + event);
+        done();
+    }
+    openRequest.onupgradeneeded = function(event) {
+        alert("Request unexpected upgradeneeded - " + event);
+        done();
+    }
+
+    openRequest.onsuccess = function(event) {
+        alert("Success opening database connection - Starting final transaction");
+        var database = event.target.result;
+        var transaction = database.transaction("TestObjectStore", "readwrite");
+        var objectStore = transaction.objectStore("TestObjectStore");
+    
+        var request;
+        for (var i = 1; i <= 9; ++i) {
+            request = objectStore.get(i);
+            request.onsuccess = getChecker;
+        }
+
+        transaction.onabort = function(event) {
+            alert("Readwrite transaction unexpected abort");
+            done();
+        }
+
+        transaction.oncomplete = function(event) {
+            alert("Readwrite transaction complete");
+            done();
+        }
+
+        transaction.onerror = function(event) {
+            alert("Readwrite transaction unexpected error - " + event);
+            done();
+        }
+    }
+}
+</script>
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures-expected.txt b/LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures-expected.txt
new file mode 100644 (file)
index 0000000..7f68fdd
--- /dev/null
@@ -0,0 +1,11 @@
+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Failed to put record into object store with an invalid key
+ALERT: Failed to put record into object store that has been deleted
+ALERT: Failed to clear object store that has been deleted
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Failed to clear object store in read-only transaction
+ALERT: Failed to put record into object store with inactive transaction
+ALERT: Failed to clear object store with inactive transaction
+ALERT: readwrite transaction complete
+ALERT: Done
+This tests some obvious failures that can happen while calling IDBObjectStore.put() and IDBObjectStore.clear().
diff --git a/LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures.html b/LayoutTests/storage/indexeddb/modern/idbobjectstore-put-and-clear-failures.html
new file mode 100644 (file)
index 0000000..cdf5812
--- /dev/null
@@ -0,0 +1,119 @@
+This tests some obvious failures that can happen while calling IDBObjectStore.put() and IDBObjectStore.clear().
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open("IDBObjectStorePutAndClearFailuresDatabase", 1);
+var database;
+
+createRequest.onupgradeneeded = function(event) {
+    alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    database = event.target.result;
+    var objectStore = database.createObjectStore("TestObjectStore");
+    var request = objectStore.put("bar", "foo");
+
+    request.onsuccess = function() {
+        try {
+            objectStore.put("bar", NaN);
+        } catch(e) {
+            alert("Failed to put record into object store with an invalid key");
+        }
+        
+        database.deleteObjectStore("TestObjectStore");
+        
+        try {
+            objectStore.put("bar", "foo");
+        } catch(e) {
+            alert("Failed to put record into object store that has been deleted");
+        } 
+
+        try {
+            objectStore.clear();
+        } catch(e) {
+            alert("Failed to clear object store that has been deleted");
+        } 
+
+        // Recreate the objectstore because we'll need it in phase 2.
+        var objectStore = database.createObjectStore("TestObjectStore");
+        objectStore.put("bar", "foo");    
+    }
+    
+    versionTransaction.onabort = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected aborted");
+        done();
+    }
+
+    versionTransaction.oncomplete = function(event) {
+        alert("Initial upgrade versionchange transaction complete");
+        continueTest1();
+    }
+
+    versionTransaction.onerror = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected error" + event);
+        done();
+    }
+}
+
+function continueTest1()
+{
+    var transaction = database.transaction("TestObjectStore", "readonly");
+    var objectStore = transaction.objectStore("TestObjectStore");
+    
+    try {
+        objectStore.clear();
+    } catch(e) {
+        alert("Failed to clear object store in read-only transaction");
+    }
+    
+    var transaction = database.transaction("TestObjectStore", "readwrite");
+    var objectStore = transaction.objectStore("TestObjectStore");
+
+    // Queue up a whole bunch of gets to keep the transaction alive for awhile
+    for (var i = 0; i < 10; ++i)
+        objectStore.get("foo");
+
+    var testWhileInactive = function() {
+        try {
+            objectStore.put("bar", "foo");
+        } catch(e) {
+            alert("Failed to put record into object store with inactive transaction");
+        }
+        
+        try {
+            objectStore.clear();
+        } catch(e) {
+            alert("Failed to clear object store with inactive transaction");
+        } 
+    }
+    
+    setTimeout(testWhileInactive, 0);
+    
+    transaction.onabort = function(event) {
+        alert("readwrite transaction unexpected abort" + event);
+        done();
+    }
+
+    transaction.oncomplete = function(event) {
+        alert("readwrite transaction complete");
+        done();
+    }
+
+    transaction.onerror = function(event) {
+        alert("readwrite transaction unexpected error" + event);
+        done();
+    }
+}
+
+</script>
index dfb9eed..5f38db0 100644 (file)
@@ -1,3 +1,82 @@
+2015-10-30  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: IDBObjectStore.clear() support.
+        https://bugs.webkit.org/show_bug.cgi?id=150733
+
+        Reviewed by Alex Christensen.
+
+        Tests: storage/indexeddb/modern/idbobjectstore-clear-1.html
+               storage/indexeddb/modern/idbobjectstore-clear-2.html
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::clearObjectStore):
+        (WebCore::IDBClient::IDBConnectionToServer::didClearObjectStore):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+        
+        * Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
+        (WebCore::IDBClient::IDBObjectStore::clear):
+        
+        * Modules/indexeddb/client/IDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBRequest::setResultToUndefined):
+        * Modules/indexeddb/client/IDBRequestImpl.h:
+        
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::requestClearObjectStore):
+        (WebCore::IDBClient::IDBTransaction::clearObjectStoreOnServer):
+        (WebCore::IDBClient::IDBTransaction::didClearObjectStoreOnServer):
+        * Modules/indexeddb/client/IDBTransactionImpl.h:
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+
+        * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+        (WebCore::IDBServer::IDBConnectionToClient::didClearObjectStore):
+        * Modules/indexeddb/server/IDBConnectionToClient.h:
+        * Modules/indexeddb/server/IDBConnectionToClientDelegate.h:
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::clearObjectStore):
+        * Modules/indexeddb/server/IDBServer.h:
+
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::objectStoreCleared):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::recordValueChanged):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::isAborting):
+
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::clearObjectStore):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::clear):
+        (WebCore::IDBServer::MemoryObjectStore::replaceKeyValueStore):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::clearObjectStore):
+        (WebCore::IDBServer::UniqueIDBDatabase::performClearObjectStore):
+        (WebCore::IDBServer::UniqueIDBDatabase::didPerformClearObjectStore):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didClearObjectStore):
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseTransaction::clearObjectStore):
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
+
+        * Modules/indexeddb/shared/IDBResultData.cpp:
+        (WebCore::IDBResultData::clearObjectStoreSuccess):
+        * Modules/indexeddb/shared/IDBResultData.h:
+
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::didClearObjectStore):
+        (WebCore::InProcessIDBServer::clearObjectStore):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
 2015-10-30  Joseph Pecoraro  <pecoraro@apple.com>
 
         CSSParserVariable leaks seen on leaks bots
index d058f41..b1ed6d3 100644 (file)
@@ -124,6 +124,21 @@ void IDBConnectionToServer::didDeleteObjectStore(const IDBResultData& resultData
     completeOperation(resultData);
 }
 
+void IDBConnectionToServer::clearObjectStore(TransactionOperation& operation, uint64_t objectStoreIdentifier)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::clearObjectStore");
+
+    saveOperation(operation);
+
+    m_delegate->clearObjectStore(IDBRequestData(operation), objectStoreIdentifier);
+}
+
+void IDBConnectionToServer::didClearObjectStore(const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::didClearObjectStore");
+    completeOperation(resultData);
+}
+
 void IDBConnectionToServer::putOrAdd(TransactionOperation& operation, RefPtr<IDBKey>& key, RefPtr<SerializedScriptValue>& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "IDBConnectionToServer::putOrAdd");
index 52911e7..f2ccbb1 100644 (file)
@@ -67,6 +67,9 @@ public:
     void deleteObjectStore(TransactionOperation&, const String& objectStoreName);
     void didDeleteObjectStore(const IDBResultData&);
 
+    void clearObjectStore(TransactionOperation&, uint64_t objectStoreIdentifier);
+    void didClearObjectStore(const IDBResultData&);
+
     void putOrAdd(TransactionOperation&, RefPtr<IDBKey>&, RefPtr<SerializedScriptValue>&, const IndexedDB::ObjectStoreOverwriteMode);
     void didPutOrAdd(const IDBResultData&);
 
index eada736..8971a8e 100644 (file)
@@ -56,6 +56,7 @@ public:
     virtual void commitTransaction(IDBResourceIdentifier&) = 0;
     virtual void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&) = 0;
     virtual void deleteObjectStore(const IDBRequestData&, const String& objectStoreName) = 0;
+    virtual void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier) = 0;
     virtual void putOrAdd(const IDBRequestData&, IDBKey*, SerializedScriptValue&, const IndexedDB::ObjectStoreOverwriteMode) = 0;
     virtual void getRecord(const IDBRequestData&, IDBKey*) = 0;
     virtual void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&) = 0;
index cce2b1d..365bc57 100644 (file)
@@ -260,9 +260,27 @@ RefPtr<WebCore::IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContex
     RELEASE_ASSERT_NOT_REACHED();
 }
 
-RefPtr<WebCore::IDBRequest> IDBObjectStore::clear(ScriptExecutionContext*, ExceptionCode&)
+RefPtr<WebCore::IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, ExceptionCode& ec)
 {
-    RELEASE_ASSERT_NOT_REACHED();
+    LOG(IndexedDB, "IDBObjectStore::clear");
+
+    if (m_transaction->isReadOnly()) {
+        ec = static_cast<ExceptionCode>(IDBExceptionCode::ReadOnlyError);
+        return nullptr;
+    }
+
+    if (!m_transaction->isActive()) {
+        ec = static_cast<ExceptionCode>(IDBExceptionCode::TransactionInactiveError);
+        return nullptr;
+    }
+
+    if (m_deleted) {
+        ec = static_cast<ExceptionCode>(IDBExceptionCode::InvalidStateError);
+        return nullptr;
+    }
+
+    Ref<IDBRequest> request = m_transaction->requestClearObjectStore(*context, *this);
+    return adoptRef(request.leakRef());
 }
 
 RefPtr<WebCore::IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext*, const String&, const IDBKeyPath&, bool, bool, ExceptionCode&)
index e4c2cd4..cb29401 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "DOMRequestState.h"
 #include "EventQueue.h"
 #include "IDBBindingUtilities.h"
 #include "IDBEventDispatcher.h"
@@ -191,6 +192,17 @@ void IDBRequest::setResultToStructuredClone(const ThreadSafeDataBuffer& valueDat
     m_result = IDBAny::create(WTF::move(value));
 }
 
+void IDBRequest::setResultToUndefined()
+{
+    auto context = scriptExecutionContext();
+    if (!context)
+        return;
+
+    DOMRequestState state(context);
+    if (auto* execState = state.exec())
+        m_result = IDBAny::create(Deprecated::ScriptValue(execState->vm(), JSC::jsUndefined()));
+}
+
 void IDBRequest::requestCompleted(const IDBResultData& resultData)
 {
     m_idbError = resultData.error();
index 1dffb12..0a7f81a 100644 (file)
@@ -79,6 +79,7 @@ public:
 
     void setResult(const IDBKeyData*);
     void setResultToStructuredClone(const ThreadSafeDataBuffer&);
+    void setResultToUndefined();
 
 protected:
     IDBRequest(IDBConnectionToServer&, ScriptExecutionContext*);
index bbaf66b..a547204 100644 (file)
@@ -414,6 +414,35 @@ void IDBTransaction::didGetRecordOnServer(IDBRequest& request, const IDBResultDa
     request.requestCompleted(resultData);
 }
 
+Ref<IDBRequest> IDBTransaction::requestClearObjectStore(ScriptExecutionContext& context, IDBObjectStore& objectStore)
+{
+    LOG(IndexedDB, "IDBTransaction::requestClearObjectStore");
+    ASSERT(isActive());
+
+    Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
+
+    uint64_t objectStoreIdentifier = objectStore.info().identifier();
+    auto operation = createTransactionOperation(*this, request.get(), &IDBTransaction::didClearObjectStoreOnServer, &IDBTransaction::clearObjectStoreOnServer, objectStoreIdentifier);
+    scheduleOperation(WTF::move(operation));
+
+    return WTF::move(request);
+}
+
+void IDBTransaction::clearObjectStoreOnServer(TransactionOperation& operation, const uint64_t& objectStoreIdentifier)
+{
+    LOG(IndexedDB, "IDBTransaction::clearObjectStoreOnServer");
+
+    serverConnection().clearObjectStore(operation, objectStoreIdentifier);
+}
+
+void IDBTransaction::didClearObjectStoreOnServer(IDBRequest& request, const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "IDBTransaction::didClearObjectStoreOnServer");
+
+    request.setResultToUndefined();
+    request.requestCompleted(resultData);
+}
+
 Ref<IDBRequest> IDBTransaction::requestPutOrAdd(ScriptExecutionContext& context, IDBObjectStore& objectStore, IDBKey* key, SerializedScriptValue& value, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "IDBTransaction::requestPutOrAdd");
index b33b654..4ef51a1 100644 (file)
@@ -89,6 +89,7 @@ public:
 
     Ref<IDBRequest> requestPutOrAdd(ScriptExecutionContext&, IDBObjectStore&, IDBKey*, SerializedScriptValue&, IndexedDB::ObjectStoreOverwriteMode);
     Ref<IDBRequest> requestGetRecord(ScriptExecutionContext&, IDBObjectStore&, IDBKey&);
+    Ref<IDBRequest> requestClearObjectStore(ScriptExecutionContext&, IDBObjectStore&);
 
     void deleteObjectStore(const String& objectStoreName);
 
@@ -121,6 +122,9 @@ private:
     void createObjectStoreOnServer(TransactionOperation&, const IDBObjectStoreInfo&);
     void didCreateObjectStoreOnServer(const IDBResultData&);
 
+    void clearObjectStoreOnServer(TransactionOperation&, const uint64_t& objectStoreIdentifier);
+    void didClearObjectStoreOnServer(IDBRequest&, const IDBResultData&);
+
     void putOrAddOnServer(TransactionOperation&, RefPtr<IDBKey>, RefPtr<SerializedScriptValue>, const IndexedDB::ObjectStoreOverwriteMode&);
     void didPutOrAddOnServer(IDBRequest&, const IDBResultData&);
 
index 7ec58f2..08fa646 100644 (file)
@@ -53,6 +53,7 @@ public:
 
     virtual IDBError createObjectStore(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&) = 0;
     virtual IDBError deleteObjectStore(const IDBResourceIdentifier& transactionIdentifier, const String& objectStoreName) = 0;
+    virtual IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) = 0;
     virtual IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) = 0;
     virtual IDBError deleteRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&) = 0;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) = 0;
index d68d486..b10c456 100644 (file)
@@ -73,6 +73,11 @@ void IDBConnectionToClient::didDeleteObjectStore(const IDBResultData& result)
     m_delegate->didDeleteObjectStore(result);
 }
 
+void IDBConnectionToClient::didClearObjectStore(const IDBResultData& result)
+{
+    m_delegate->didClearObjectStore(result);
+}
+
 void IDBConnectionToClient::didPutOrAdd(const IDBResultData& result)
 {
     m_delegate->didPutOrAdd(result);
index 355cbd1..244d98e 100644 (file)
@@ -54,6 +54,7 @@ public:
     void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&);
     void didCreateObjectStore(const IDBResultData&);
     void didDeleteObjectStore(const IDBResultData&);
+    void didClearObjectStore(const IDBResultData&);
     void didPutOrAdd(const IDBResultData&);
     void didGetRecord(const IDBResultData&);
 
index 662383a..31d0a50 100644 (file)
@@ -50,6 +50,7 @@ public:
     virtual void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&) = 0;
     virtual void didCreateObjectStore(const IDBResultData&) = 0;
     virtual void didDeleteObjectStore(const IDBResultData&) = 0;
+    virtual void didClearObjectStore(const IDBResultData&) = 0;
     virtual void didPutOrAdd(const IDBResultData&) = 0;
     virtual void didGetRecord(const IDBResultData&) = 0;
 
index 02bdebd..9ff2783 100644 (file)
@@ -180,6 +180,17 @@ void IDBServer::deleteObjectStore(const IDBRequestData& requestData, const Strin
     transaction->deleteObjectStore(requestData, objectStoreName);
 }
 
+void IDBServer::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
+{
+    LOG(IndexedDB, "IDBServer::clearObjectStore");
+
+    auto transaction = m_transactions.get(requestData.transactionIdentifier());
+    if (!transaction)
+        return;
+
+    transaction->clearObjectStore(requestData, objectStoreIdentifier);
+}
+
 void IDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "IDBServer::putOrAdd");
index 31d873b..da00c38 100644 (file)
@@ -61,6 +61,7 @@ public:
     void commitTransaction(const IDBResourceIdentifier&);
     void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&);
     void deleteObjectStore(const IDBRequestData&, const String& objectStoreName);
+    void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode);
     void getRecord(const IDBRequestData&, const IDBKeyData&);
     void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&);
index feaafa3..f87e374 100644 (file)
@@ -90,6 +90,27 @@ void MemoryBackingStoreTransaction::objectStoreDeleted(std::unique_ptr<MemoryObj
         addResult.iterator->value = WTF::move(objectStore);
 }
 
+void MemoryBackingStoreTransaction::objectStoreCleared(MemoryObjectStore& objectStore, std::unique_ptr<KeyValueMap>&& keyValueMap)
+{
+    ASSERT(m_objectStores.contains(&objectStore));
+
+    auto addResult = m_clearedKeyValueMaps.add(&objectStore, nullptr);
+
+    // If this object store has already been cleared during this transaction, we don't need to remember this clearing.
+    if (!addResult.isNewEntry)
+        return;
+
+    // If values had previously been changed during this transaction, fold those changes back into the
+    // cleared key-value map now, so we have exactly the map that will need to be restored if the transaction is aborted.
+    auto originalValues = m_originalValues.take(&objectStore);
+    if (originalValues) {
+        for (auto iterator : *originalValues)
+            keyValueMap->set(iterator.key, iterator.value);
+    }
+
+    addResult.iterator->value = WTF::move(keyValueMap);
+}
+
 void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& objectStore, const IDBKeyData& key)
 {
     ASSERT(m_objectStores.contains(&objectStore));
@@ -97,6 +118,11 @@ void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& object
     if (m_isAborting)
         return;
 
+    // If this object store had been cleared during the transaction, no point in recording this
+    // individual key/value change as its entire key/value map will be restored upon abort.
+    if (m_clearedKeyValueMaps.contains(&objectStore))
+        return;
+
     auto originalAddResult = m_originalValues.add(&objectStore, nullptr);
     if (originalAddResult.isNewEntry)
         originalAddResult.iterator->value = std::make_unique<KeyValueMap>();
@@ -138,7 +164,13 @@ void MemoryBackingStoreTransaction::abort()
         ASSERT(m_originalKeyGenerators.contains(objectStore));
         objectStore->setKeyGeneratorValue(m_originalKeyGenerators.get(objectStore));
 
-        auto keyValueMap = m_originalValues.get(objectStore);
+        auto clearedKeyValueMap = m_clearedKeyValueMaps.take(objectStore);
+        if (clearedKeyValueMap) {
+            objectStore->replaceKeyValueStore(WTF::move(clearedKeyValueMap));
+            continue;
+        }
+
+        auto keyValueMap = m_originalValues.take(objectStore);
         if (!keyValueMap)
             continue;
 
@@ -146,8 +178,6 @@ void MemoryBackingStoreTransaction::abort()
             objectStore->deleteRecord(entry.key);
             objectStore->setKeyValue(entry.key, entry.value);
         }
-
-        m_originalValues.remove(objectStore);
     }
 
     finish();
index 58ca5de..290215f 100644 (file)
@@ -52,6 +52,7 @@ public:
 
     bool isVersionChange() const { return m_info.mode() == IndexedDB::TransactionMode::VersionChange; }
     bool isWriting() const { return m_info.mode() != IndexedDB::TransactionMode::ReadOnly; }
+    bool isAborting() const { return m_isAborting; }
 
     const IDBDatabaseInfo& originalDatabaseInfo() const;
 
@@ -59,6 +60,7 @@ public:
     void addExistingObjectStore(MemoryObjectStore&);
     void recordValueChanged(MemoryObjectStore&, const IDBKeyData&);
     void objectStoreDeleted(std::unique_ptr<MemoryObjectStore>);
+    void objectStoreCleared(MemoryObjectStore&, std::unique_ptr<KeyValueMap>&&);
 
     void abort();
     void commit();
@@ -82,7 +84,7 @@ private:
     HashMap<MemoryObjectStore*, uint64_t> m_originalKeyGenerators;
     HashMap<String, std::unique_ptr<MemoryObjectStore>> m_deletedObjectStores;
     HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_originalValues;
-
+    HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_clearedKeyValueMaps;
 };
 
 } // namespace IDBServer
index 207eafc..c846357 100644 (file)
@@ -161,6 +161,27 @@ IDBError MemoryIDBBackingStore::deleteObjectStore(const IDBResourceIdentifier& t
     return IDBError();
 }
 
+IDBError MemoryIDBBackingStore::clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier)
+{
+    LOG(IndexedDB, "MemoryIDBBackingStore::clearObjectStore");
+    ASSERT(objectStoreIdentifier);
+
+    ASSERT_UNUSED(transactionIdentifier, m_transactions.contains(transactionIdentifier));
+
+#ifndef NDEBUG
+    auto transaction = m_transactions.get(transactionIdentifier);
+    ASSERT(transaction->isWriting());
+#endif
+
+    auto objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier);
+    if (!objectStore)
+        return IDBError(IDBExceptionCode::ConstraintError);
+
+    objectStore->clear();
+
+    return IDBError();
+}
+
 void MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort(MemoryObjectStore& objectStore)
 {
     LOG(IndexedDB, "MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort");
index eee8397..77bbe39 100644 (file)
@@ -54,6 +54,7 @@ public:
     virtual IDBError commitTransaction(const IDBResourceIdentifier& transactionIdentifier) override final;
     virtual IDBError createObjectStore(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&) override final;
     virtual IDBError deleteObjectStore(const IDBResourceIdentifier& transactionIdentifier, const String& objectStoreName) override final;
+    virtual IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) override final;
     virtual IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) override final;
     virtual IDBError deleteRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&) override final;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) override final;
index 145c89e..2409ab3 100644 (file)
@@ -73,6 +73,22 @@ bool MemoryObjectStore::containsRecord(const IDBKeyData& key)
     return m_keyValueStore->contains(key);
 }
 
+void MemoryObjectStore::clear()
+{
+    LOG(IndexedDB, "MemoryObjectStore::clear");
+    ASSERT(m_writeTransaction);
+
+    m_writeTransaction->objectStoreCleared(*this, WTF::move(m_keyValueStore));
+}
+
+void MemoryObjectStore::replaceKeyValueStore(std::unique_ptr<KeyValueMap>&& store)
+{
+    ASSERT(m_writeTransaction);
+    ASSERT(m_writeTransaction->isAborting());
+
+    m_keyValueStore = WTF::move(store);
+}
+
 void MemoryObjectStore::deleteRecord(const IDBKeyData& key)
 {
     LOG(IndexedDB, "MemoryObjectStore::deleteRecord");
index 6be196e..d047a79 100644 (file)
@@ -63,6 +63,9 @@ public:
     uint64_t currentKeyGeneratorValue() const { return m_keyGeneratorValue; }
     void setKeyGeneratorValue(uint64_t value) { m_keyGeneratorValue = value; }
 
+    void clear();
+    void replaceKeyValueStore(std::unique_ptr<KeyValueMap>&&);
+
     ThreadSafeDataBuffer valueForKey(const IDBKeyData&) const;
 
     const IDBObjectStoreInfo& info() const { return m_info; }
index d41ba02..30b3fa3 100644 (file)
@@ -296,6 +296,35 @@ void UniqueIDBDatabase::didPerformDeleteObjectStore(uint64_t callbackIdentifier,
     performErrorCallback(callbackIdentifier, error);
 }
 
+void UniqueIDBDatabase::clearObjectStore(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, ErrorCallback callback)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::clearObjectStore");
+
+    uint64_t callbackID = storeCallback(callback);
+    m_server.postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::performClearObjectStore, callbackID, transaction.info().identifier(), objectStoreIdentifier));
+}
+
+void UniqueIDBDatabase::performClearObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier)
+{
+    ASSERT(!isMainThread());
+    LOG(IndexedDB, "(db) UniqueIDBDatabase::performClearObjectStore");
+
+    ASSERT(m_backingStore);
+    m_backingStore->clearObjectStore(transactionIdentifier, objectStoreIdentifier);
+
+    IDBError error;
+    m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformClearObjectStore, callbackIdentifier, error));
+}
+
+void UniqueIDBDatabase::didPerformClearObjectStore(uint64_t callbackIdentifier, const IDBError& error)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::didPerformClearObjectStore");
+
+    performErrorCallback(callbackIdentifier, error);
+}
+
 void UniqueIDBDatabase::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode overwriteMode, KeyDataCallback callback)
 {
     ASSERT(isMainThread());
index 6d3f072..2cb63ff 100644 (file)
@@ -71,6 +71,7 @@ public:
 
     void createObjectStore(UniqueIDBDatabaseTransaction&, const IDBObjectStoreInfo&, ErrorCallback);
     void deleteObjectStore(UniqueIDBDatabaseTransaction&, const String& objectStoreName, ErrorCallback);
+    void clearObjectStore(UniqueIDBDatabaseTransaction&, uint64_t objectStoreIdentifier, ErrorCallback);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode, KeyDataCallback);
     void getRecord(const IDBRequestData&, const IDBKeyData&, ValueDataCallback);
     void commitTransaction(UniqueIDBDatabaseTransaction&, ErrorCallback);
@@ -100,6 +101,7 @@ private:
     void beginTransactionInBackingStore(const IDBTransactionInfo&);
     void performCreateObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&);
     void performDeleteObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, const String& objectStoreName);
+    void performClearObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier);
     void performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode);
     void performGetRecord(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&);
     void performActivateTransactionInBackingStore(uint64_t callbackIdentifier, const IDBTransactionInfo&);
@@ -108,6 +110,7 @@ private:
     void didOpenBackingStore(const IDBDatabaseInfo&);
     void didPerformCreateObjectStore(uint64_t callbackIdentifier, const IDBError&, const IDBObjectStoreInfo&);
     void didPerformDeleteObjectStore(uint64_t callbackIdentifier, const IDBError&, const String& objectStoreName);
+    void didPerformClearObjectStore(uint64_t callbackIdentifier, const IDBError&);
     void didPerformPutOrAdd(uint64_t callbackIdentifier, const IDBError&, const IDBKeyData&);
     void didPerformGetRecord(uint64_t callbackIdentifier, const IDBError&, const ThreadSafeDataBuffer&);
     void didPerformCommitTransaction(uint64_t callbackIdentifier, const IDBError&, const IDBResourceIdentifier& transactionIdentifier);
index 4439bd2..372b3ae 100644 (file)
@@ -146,6 +146,13 @@ void UniqueIDBDatabaseConnection::didDeleteObjectStore(const IDBResultData& resu
     m_connectionToClient.didDeleteObjectStore(resultData);
 }
 
+void UniqueIDBDatabaseConnection::didClearObjectStore(const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didClearObjectStore");
+
+    m_connectionToClient.didClearObjectStore(resultData);
+}
+
 } // namespace IDBServer
 } // namespace WebCore
 
index 4b5676a..8f11f15 100644 (file)
@@ -68,6 +68,7 @@ public:
     void didCommitTransaction(UniqueIDBDatabaseTransaction&, const IDBError&);
     void didCreateObjectStore(const IDBResultData&);
     void didDeleteObjectStore(const IDBResultData&);
+    void didClearObjectStore(const IDBResultData&);
 
 private:
     UniqueIDBDatabaseConnection(UniqueIDBDatabase&, IDBConnectionToClient&);
index 5782ca8..ea6b64a 100644 (file)
@@ -130,6 +130,21 @@ void UniqueIDBDatabaseTransaction::deleteObjectStore(const IDBRequestData& reque
     });
 }
 
+void UniqueIDBDatabaseTransaction::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
+{
+    LOG(IndexedDB, "UniqueIDBDatabaseTransaction::clearObjectStore");
+
+    ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
+
+    RefPtr<UniqueIDBDatabaseTransaction> self(this);
+    m_databaseConnection->database().clearObjectStore(*this, objectStoreIdentifier, [this, self, requestData](const IDBError& error) {
+        LOG(IndexedDB, "UniqueIDBDatabaseTransaction::clearObjectStore (callback)");
+        if (error.isNull())
+            m_databaseConnection->didClearObjectStore(IDBResultData::clearObjectStoreSuccess(requestData.requestIdentifier()));
+        else
+            m_databaseConnection->didClearObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
+    });
+}
 
 void UniqueIDBDatabaseTransaction::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
index 80a8fae..9c66876 100644 (file)
@@ -64,6 +64,7 @@ public:
 
     void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&);
     void deleteObjectStore(const IDBRequestData&, const String& objectStoreName);
+    void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const ThreadSafeDataBuffer& valueData, IndexedDB::ObjectStoreOverwriteMode);
     void getRecord(const IDBRequestData&, const IDBKeyData&);
 
index 5a5c7c1..2cf5c3d 100644 (file)
@@ -98,6 +98,11 @@ IDBResultData IDBResultData::deleteObjectStoreSuccess(const IDBResourceIdentifie
     return { IDBResultType::DeleteObjectStoreSuccess, requestIdentifier };
 }
 
+IDBResultData IDBResultData::clearObjectStoreSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+    return { IDBResultType::ClearObjectStoreSuccess, requestIdentifier };
+}
+
 IDBResultData IDBResultData::putOrAddSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBKeyData& resultKey)
 {
     IDBResultData result(IDBResultType::PutOrAddSuccess, requestIdentifier);
index b8054ad..9d65316 100644 (file)
@@ -46,6 +46,7 @@ enum class IDBResultType {
     OpenDatabaseUpgradeNeeded,
     CreateObjectStoreSuccess,
     DeleteObjectStoreSuccess,
+    ClearObjectStoreSuccess,
     PutOrAddSuccess,
     GetRecordSuccess,
 };
@@ -62,6 +63,7 @@ public:
     static IDBResultData openDatabaseUpgradeNeeded(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseTransaction&);
     static IDBResultData createObjectStoreSuccess(const IDBResourceIdentifier&);
     static IDBResultData deleteObjectStoreSuccess(const IDBResourceIdentifier&);
+    static IDBResultData clearObjectStoreSuccess(const IDBResourceIdentifier&);
     static IDBResultData putOrAddSuccess(const IDBResourceIdentifier&, const IDBKeyData&);
     static IDBResultData getRecordSuccess(const IDBResourceIdentifier&, const ThreadSafeDataBuffer& valueData);
 
index dc09a09..afadb2a 100644 (file)
@@ -135,6 +135,14 @@ void InProcessIDBServer::didDeleteObjectStore(const IDBResultData& resultData)
     });
 }
 
+void InProcessIDBServer::didClearObjectStore(const IDBResultData& resultData)
+{
+    RefPtr<InProcessIDBServer> self(this);
+    RunLoop::current().dispatch([this, self, resultData] {
+        m_connectionToServer->didClearObjectStore(resultData);
+    });
+}
+
 void InProcessIDBServer::didPutOrAdd(const IDBResultData& resultData)
 {
     RefPtr<InProcessIDBServer> self(this);
@@ -183,6 +191,14 @@ void InProcessIDBServer::deleteObjectStore(const IDBRequestData& requestData, co
     });
 }
 
+void InProcessIDBServer::clearObjectStore(const IDBRequestData& requestData, uint64_t objectStoreIdentifier)
+{
+    RefPtr<InProcessIDBServer> self(this);
+    RunLoop::current().dispatch([this, self, requestData, objectStoreIdentifier] {
+        m_server->clearObjectStore(requestData, objectStoreIdentifier);
+    });
+}
+
 void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, IDBKey* key, SerializedScriptValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     RefPtr<InProcessIDBServer> self(this);
index b6ac429..db5637e 100644 (file)
@@ -60,6 +60,7 @@ public:
     virtual void commitTransaction(IDBResourceIdentifier&) override final;
     virtual void createObjectStore(const IDBRequestData&, const IDBObjectStoreInfo&) override final;
     virtual void deleteObjectStore(const IDBRequestData&, const String& objectStoreName) override final;
+    virtual void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier) override final;
     virtual void putOrAdd(const IDBRequestData&, IDBKey*, SerializedScriptValue&, const IndexedDB::ObjectStoreOverwriteMode) override final;
     virtual void getRecord(const IDBRequestData&, IDBKey*) override final;
     virtual void establishTransaction(uint64_t databaseConnectionIdentifier, const IDBTransactionInfo&) override final;
@@ -73,6 +74,7 @@ public:
     virtual void didCommitTransaction(const IDBResourceIdentifier& transactionIdentifier, const IDBError&) override final;
     virtual void didCreateObjectStore(const IDBResultData&) override final;
     virtual void didDeleteObjectStore(const IDBResultData&) override final;
+    virtual void didClearObjectStore(const IDBResultData&) override final;
     virtual void didPutOrAdd(const IDBResultData&) override final;
     virtual void didGetRecord(const IDBResultData&) override final;
     virtual void fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConnection&, uint64_t requestedVersion) override final;