IndexedDB 2.0: Support IDBIndex name assignment.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Oct 2016 16:24:09 +0000 (16:24 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Oct 2016 16:24:09 +0000 (16:24 +0000)
<rdar://problem/28806932> and https://bugs.webkit.org/show_bug.cgi?id=163805

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/IndexedDB/idbindex-rename-errors-expected.txt:
* web-platform-tests/IndexedDB/idbindex-rename-expected.txt:

Source/WebCore:

Tests: storage/indexeddb/modern/index-rename-1-private.html
       storage/indexeddb/modern/index-rename-1.html

Touches a *lot* of code sites, but none of them are particularly interesting.
They are all just getting the new name spread out to all of the various objects that need it.

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::renameIndex):
* Modules/indexeddb/IDBDatabase.h:

* Modules/indexeddb/IDBIndex.cpp:
(WebCore::IDBIndex::IDBIndex):
(WebCore::IDBIndex::setName):
(WebCore::IDBIndex::rollbackInfoForVersionChangeAbort):
* Modules/indexeddb/IDBIndex.h:
* Modules/indexeddb/IDBIndex.idl:

* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::rollbackForVersionChangeAbort):
(WebCore::IDBObjectStore::renameReferencedIndex):
(WebCore::IDBObjectStore::rollbackInfoForVersionChangeAbort): Deleted.
* Modules/indexeddb/IDBObjectStore.h:

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::internalAbort):
(WebCore::IDBTransaction::renameIndex):
(WebCore::IDBTransaction::renameIndexOnServer):
(WebCore::IDBTransaction::didRenameIndexOnServer):
* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::renameIndex):
* Modules/indexeddb/client/IDBConnectionProxy.h:

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::renameIndex):
(WebCore::IDBClient::IDBConnectionToServer::didRenameIndex):
* Modules/indexeddb/client/IDBConnectionToServer.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:

* Modules/indexeddb/client/TransactionOperation.h:
(WebCore::IDBClient::createTransactionOperation):

* Modules/indexeddb/server/IDBBackingStore.h:

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

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

* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::indexRenamed):
(WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
* Modules/indexeddb/server/MemoryBackingStoreTransaction.h:

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

* Modules/indexeddb/server/MemoryIndex.h:
(WebCore::IDBServer::MemoryIndex::rename):

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

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

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::renameIndex):
(WebCore::IDBServer::UniqueIDBDatabase::performRenameIndex):
(WebCore::IDBServer::UniqueIDBDatabase::didPerformRenameIndex):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

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

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

* Modules/indexeddb/shared/IDBIndexInfo.h:
(WebCore::IDBIndexInfo::rename):

* Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:
(WebCore::IDBObjectStoreInfo::infoForExistingIndex):
* Modules/indexeddb/shared/IDBObjectStoreInfo.h:

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

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::didRenameIndex):
(WebCore::InProcessIDBServer::renameIndex):
* Modules/indexeddb/shared/InProcessIDBServer.h:

Source/WebKit2:

* DatabaseProcess/IndexedDB/WebIDBConnectionToClient.cpp:
(WebKit::WebIDBConnectionToClient::didRenameIndex):
(WebKit::WebIDBConnectionToClient::renameIndex):
* DatabaseProcess/IndexedDB/WebIDBConnectionToClient.h:
* DatabaseProcess/IndexedDB/WebIDBConnectionToClient.messages.in:

* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
(WebKit::WebIDBConnectionToServer::renameIndex):
(WebKit::WebIDBConnectionToServer::didRenameIndex):
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.messages.in:

LayoutTests:

* storage/indexeddb/modern/index-rename-1-expected.txt: Added.
* storage/indexeddb/modern/index-rename-1-private-expected.txt: Added.
* storage/indexeddb/modern/index-rename-1-private.html: Added.
* storage/indexeddb/modern/index-rename-1.html: Added.
* storage/indexeddb/modern/resources/index-rename-1.js: Added.

* storage/indexeddb/readonly-expected.txt:
* storage/indexeddb/readonly-private-expected.txt:
* storage/indexeddb/resources/readonly.js: Removed the test that verifies that index names are
  readonly as they are no longer readonly.

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

63 files changed:
LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbindex-rename-errors-expected.txt
LayoutTests/imported/w3c/web-platform-tests/IndexedDB/idbindex-rename-expected.txt
LayoutTests/storage/indexeddb/modern/index-rename-1-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/index-rename-1-private-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/index-rename-1-private.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/index-rename-1.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/resources/index-rename-1.js [new file with mode: 0644]
LayoutTests/storage/indexeddb/readonly-expected.txt
LayoutTests/storage/indexeddb/readonly-private-expected.txt
LayoutTests/storage/indexeddb/resources/readonly.js
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/IDBIndex.cpp
Source/WebCore/Modules/indexeddb/IDBIndex.h
Source/WebCore/Modules/indexeddb/IDBIndex.idl
Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
Source/WebCore/Modules/indexeddb/IDBObjectStore.h
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/indexeddb/IDBTransaction.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.h
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/TransactionOperation.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/MemoryIndex.h
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.cpp
Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.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/IDBIndexInfo.h
Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp
Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.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
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/WebIDBConnectionToClient.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/WebIDBConnectionToClient.h
Source/WebKit2/DatabaseProcess/IndexedDB/WebIDBConnectionToClient.messages.in
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.messages.in

index f13e134..5041f87 100644 (file)
@@ -1,3 +1,21 @@
+2016-10-24  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB 2.0: Support IDBIndex name assignment.
+        <rdar://problem/28806932> and https://bugs.webkit.org/show_bug.cgi?id=163805
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/index-rename-1-expected.txt: Added.
+        * storage/indexeddb/modern/index-rename-1-private-expected.txt: Added.
+        * storage/indexeddb/modern/index-rename-1-private.html: Added.
+        * storage/indexeddb/modern/index-rename-1.html: Added.
+        * storage/indexeddb/modern/resources/index-rename-1.js: Added.
+
+        * storage/indexeddb/readonly-expected.txt:
+        * storage/indexeddb/readonly-private-expected.txt:
+        * storage/indexeddb/resources/readonly.js: Removed the test that verifies that index names are
+          readonly as they are no longer readonly.
+
 2016-10-24  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Unprefix -webkit-writing-mode
index 5a284be..935d17e 100644 (file)
@@ -1,3 +1,13 @@
+2016-10-24  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB 2.0: Support IDBIndex name assignment.
+        <rdar://problem/28806932> and https://bugs.webkit.org/show_bug.cgi?id=163805
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/IndexedDB/idbindex-rename-errors-expected.txt:
+        * web-platform-tests/IndexedDB/idbindex-rename-expected.txt:
+
 2016-10-22  Ryosuke Niwa  <rniwa@webkit.org>
 
         Upgrading custom element should enqueue attributeChanged and connected callbacks
index 00a8528..f3c9808 100644 (file)
@@ -1,10 +1,8 @@
 
-FAIL IndexedDB deleted index rename throws assert_throws: function "() => index.name = 'renamed_by_author'" did not throw
-FAIL IndexedDB index rename throws in a readonly transaction assert_throws: function "() => index.name = 'renamed_by_author'" did not throw
-FAIL IndexedDB index rename throws in a readwrite transaction assert_throws: function "() => index.name = 'renamed_by_author'" did not throw
-FAIL IndexedDB index rename throws in an inactive transaction assert_throws: function "() => authorIndex.name = 'renamed_by_author'" did not throw
-FAIL IndexedDB index rename to the name of another index throws assert_throws: function "() => index.name = 'by_title'" did not throw
-FAIL IndexedDB index rename handles exceptions when stringifying names assert_throws: IDBObjectStore rename should re-raise toString() exception function "() => {
-              index.name = {
-                toSt..." did not throw
+PASS IndexedDB deleted index rename throws 
+PASS IndexedDB index rename throws in a readonly transaction 
+PASS IndexedDB index rename throws in a readwrite transaction 
+FAIL IndexedDB index rename throws in an inactive transaction assert_throws: function "() => authorIndex.name = 'renamed_by_author'" threw object "InvalidStateError (DOM Exception 11): Failed set property..." that is not a DOMException TransactionInactiveError: property "code" is equal to 11, expected 0
+FAIL IndexedDB index rename to the name of another index throws assert_throws: function "() => index.name = 'by_title'" threw object "InvalidStateError (DOM Exception 11): Failed set property..." that is not a DOMException ConstraintError: property "code" is equal to 11, expected 0
+PASS IndexedDB index rename handles exceptions when stringifying names 
 
index 4ec1497..3d1edcd 100644 (file)
@@ -1,11 +1,11 @@
 
-FAIL IndexedDB index rename in new transaction assert_equals: IDBIndex name should change immediately after a rename expected "renamed_by_author" but got "by_author"
-FAIL IndexedDB index rename in the transaction where it is created assert_equals: IDBIndex name should change immediately after a rename expected "renamed_by_author" but got "by_author"
+PASS IndexedDB index rename in new transaction 
+PASS IndexedDB index rename in the transaction where it is created 
 PASS IndexedDB index rename to the same name succeeds 
-FAIL IndexedDB index rename to the name of a deleted index succeeds assert_array_equals: IDBObjectStore.indexNames should immediately reflect the rename property 0, expected "by_title" but got "by_author"
-FAIL IndexedDB index swapping via renames succeeds Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
-FAIL IndexedDB index rename stringifies non-string names assert_equals: IDBIndex name should change immediately after a rename to a number expected "42" but got "by_author"
-FAIL IndexedDB index can be renamed to "" assert_equals: IDBIndex name should change immediately after the rename expected "" but got "by_author"
-FAIL IndexedDB index can be renamed to "\u0000" assert_equals: IDBIndex name should change immediately after the rename expected "\0" but got "by_author"
-FAIL IndexedDB index can be renamed to "\uDC00\uD800" assert_equals: IDBIndex name should change immediately after the rename expected "í°\80í \80" but got "by_author"
+PASS IndexedDB index rename to the name of a deleted index succeeds 
+PASS IndexedDB index swapping via renames succeeds 
+PASS IndexedDB index rename stringifies non-string names 
+PASS IndexedDB index can be renamed to "" 
+PASS IndexedDB index can be renamed to "\u0000" 
+PASS IndexedDB index can be renamed to "\uDC00\uD800" 
 
diff --git a/LayoutTests/storage/indexeddb/modern/index-rename-1-expected.txt b/LayoutTests/storage/indexeddb/modern/index-rename-1-expected.txt
new file mode 100644 (file)
index 0000000..c032f25
--- /dev/null
@@ -0,0 +1,40 @@
+This tests expectations with renaming existing indexes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+
+indexedDB.deleteDatabase(dbname)
+indexedDB.open(dbname)
+Initial upgrade needed: Old version - 0 New version - 1
+Failed to rename deleted index: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The index has been deleted.
+Initial index name: NewIndex
+Caught exception renaming index to the name of another existing index: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The owning object store already has an index named 'ExistingIndex'.
+Renamed this index to the same name it already has, it's name is now: NewIndex
+Renamed index name: RenamedIndex
+Current index name in a new transaction: RenamedIndex
+Caught exception renaming index outside of a version change transaction: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The index's transaction is not a version change transaction.
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': true
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+Renamed index to: AnotherName
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': false
+Current indexNames during second upgrade transaction includes 'AnotherName': true
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+Renamed index again to: YetAnotherName
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': false
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': true
+Aborting version change transaction...
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': true
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/modern/index-rename-1-private-expected.txt b/LayoutTests/storage/indexeddb/modern/index-rename-1-private-expected.txt
new file mode 100644 (file)
index 0000000..c032f25
--- /dev/null
@@ -0,0 +1,40 @@
+This tests expectations with renaming existing indexes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+
+indexedDB.deleteDatabase(dbname)
+indexedDB.open(dbname)
+Initial upgrade needed: Old version - 0 New version - 1
+Failed to rename deleted index: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The index has been deleted.
+Initial index name: NewIndex
+Caught exception renaming index to the name of another existing index: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The owning object store already has an index named 'ExistingIndex'.
+Renamed this index to the same name it already has, it's name is now: NewIndex
+Renamed index name: RenamedIndex
+Current index name in a new transaction: RenamedIndex
+Caught exception renaming index outside of a version change transaction: InvalidStateError (DOM Exception 11): Failed set property 'name' on 'IDBIndex': The index's transaction is not a version change transaction.
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': true
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+Renamed index to: AnotherName
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': false
+Current indexNames during second upgrade transaction includes 'AnotherName': true
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+Renamed index again to: YetAnotherName
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': false
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': true
+Aborting version change transaction...
+Current indexNames during second upgrade transaction includes 'ExistingIndex': true
+Current indexNames during second upgrade transaction includes 'RenamedIndex': true
+Current indexNames during second upgrade transaction includes 'AnotherName': false
+Current indexNames during second upgrade transaction includes 'YetAnotherName': false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/modern/index-rename-1-private.html b/LayoutTests/storage/indexeddb/modern/index-rename-1-private.html
new file mode 100644 (file)
index 0000000..51bad4e
--- /dev/null
@@ -0,0 +1,12 @@
+<html>
+<head>
+<script>
+enablePrivateBrowsing = true;
+</script>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/index-rename-1.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/modern/index-rename-1.html b/LayoutTests/storage/indexeddb/modern/index-rename-1.html
new file mode 100644 (file)
index 0000000..b3e26c7
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/index-rename-1.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/modern/resources/index-rename-1.js b/LayoutTests/storage/indexeddb/modern/resources/index-rename-1.js
new file mode 100644 (file)
index 0000000..8761d8a
--- /dev/null
@@ -0,0 +1,137 @@
+description("This tests expectations with renaming existing indexes.");
+
+indexedDBTest(prepareDatabase);
+
+function log(message)
+{
+    debug(message);
+}
+
+var testGenerator;
+function next()
+{
+    testGenerator.next();
+}
+
+function asyncNext()
+{
+    setTimeout("testGenerator.next();", 0);
+}
+
+var db;
+var dbName;
+var dbVersion;
+
+function prepareDatabase(event)
+{
+    log("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+    db = event.target.result;
+       dbName = db.name;
+       dbVersion = db.version;
+
+       objectStore = db.createObjectStore("ObjectStore");
+
+       objectStore.createIndex("ExistingIndex", "foo");
+       
+       indexToDelete = objectStore.createIndex("IndexToDelete", "bar");
+       objectStore.deleteIndex("IndexToDelete");
+       try {
+               indexToDelete.name = "RenamedIndex";
+               log("Was incorrectly able to rename a deleted index");
+       } catch (e) {
+               log("Failed to rename deleted index: " + e)
+       }
+       
+       newIndex = objectStore.createIndex("NewIndex", "bar");
+       
+       log("Initial index name: " + newIndex.name);
+       
+       try {
+               newIndex.name = "ExistingIndex";
+               log("Was incorrectly able to rename this index to the name of another existing index");
+       } catch(e) {
+               log("Caught exception renaming index to the name of another existing index: " + e);
+       }
+
+       newIndex.name = newIndex.name;
+       log("Renamed this index to the same name it already has, it's name is now: " + newIndex.name);
+
+       newIndex.name = "RenamedIndex";
+       log("Renamed index name: " + newIndex.name);
+
+    event.target.onsuccess = function() {
+        testGenerator = testSteps();
+        testGenerator.next();
+    };
+}
+
+function* testSteps()
+{    
+    tx = db.transaction("ObjectStore", "readwrite");
+    tx.oncomplete = next;
+    objectStore = tx.objectStore("ObjectStore");
+       index = objectStore.index("RenamedIndex");
+    log("Current index name in a new transaction: " + index.name);
+
+       try {
+               index.name = "newName";
+               log("Was incorrectly able to rename this index outside of a version change transaction");
+       } catch(e) {
+               log("Caught exception renaming index outside of a version change transaction: " + e);
+       }
+    
+    yield; // For the transaction's completion.
+
+       db.close();
+    
+       upgradeOpenRequest = indexedDB.open(dbName, dbVersion + 1);
+       upgradeOpenRequest.onerror = next;
+       upgradeOpenRequest.onupgradeneeded = function(event) {
+               objectStore = event.target.transaction.objectStore("ObjectStore");
+               
+               log("Current indexNames during second upgrade transaction includes 'ExistingIndex': " + objectStore.indexNames.contains("ExistingIndex"));
+               log("Current indexNames during second upgrade transaction includes 'RenamedIndex': " + objectStore.indexNames.contains("RenamedIndex"));
+               log("Current indexNames during second upgrade transaction includes 'AnotherName': " + objectStore.indexNames.contains("AnotherName"));
+               log("Current indexNames during second upgrade transaction includes 'YetAnotherName': " + objectStore.indexNames.contains("YetAnotherName"));
+
+               index = objectStore.index("RenamedIndex");
+               index.name = "AnotherName";
+               log("Renamed index to: " + index.name);
+               
+               log("Current indexNames during second upgrade transaction includes 'ExistingIndex': " + objectStore.indexNames.contains("ExistingIndex"));
+               log("Current indexNames during second upgrade transaction includes 'RenamedIndex': " + objectStore.indexNames.contains("RenamedIndex"));
+               log("Current indexNames during second upgrade transaction includes 'AnotherName': " + objectStore.indexNames.contains("AnotherName"));
+               log("Current indexNames during second upgrade transaction includes 'YetAnotherName': " + objectStore.indexNames.contains("YetAnotherName"));
+
+               index.name = "YetAnotherName";
+               log("Renamed index again to: " + index.name);
+
+               log("Current indexNames during second upgrade transaction includes 'ExistingIndex': " + objectStore.indexNames.contains("ExistingIndex"));
+               log("Current indexNames during second upgrade transaction includes 'RenamedIndex': " + objectStore.indexNames.contains("RenamedIndex"));
+               log("Current indexNames during second upgrade transaction includes 'AnotherName': " + objectStore.indexNames.contains("AnotherName"));
+               log("Current indexNames during second upgrade transaction includes 'YetAnotherName': " + objectStore.indexNames.contains("YetAnotherName"));
+
+               log("Aborting version change transaction...");
+               event.target.transaction.abort();
+       }
+
+       yield; // For the open request's failure (due to aborting the version change transaction)
+
+       upgradeOpenRequest = indexedDB.open(dbName);
+       upgradeOpenRequest.onsuccess = function(event) {
+               objectStore = event.target.result.transaction("ObjectStore").objectStore("ObjectStore");
+               
+               log("Current indexNames during second upgrade transaction includes 'ExistingIndex': " + objectStore.indexNames.contains("ExistingIndex"));
+               log("Current indexNames during second upgrade transaction includes 'RenamedIndex': " + objectStore.indexNames.contains("RenamedIndex"));
+               log("Current indexNames during second upgrade transaction includes 'AnotherName': " + objectStore.indexNames.contains("AnotherName"));
+               log("Current indexNames during second upgrade transaction includes 'YetAnotherName': " + objectStore.indexNames.contains("YetAnotherName"));
+
+               next();
+       }
+       
+       yield; // To balance the next() above.
+       
+    finishJSTest();
+ }
\ No newline at end of file
index 1e026fb..e28f2db 100644 (file)
@@ -35,9 +35,6 @@ trying to set readonly property cursor.primaryKey
 cursor.primaryKey = Infinity
 PASS cursor.primaryKey is still first
 index = objectStore.createIndex('first', 'first');
-trying to set readonly property index.name
-index.name = 'bar'
-PASS index.name is still first
 trying to set readonly property index.objectStore
 index.objectStore = this
 PASS index.objectStore is still [object IDBObjectStore]
index 051874f..cba45ae 100644 (file)
@@ -35,9 +35,6 @@ trying to set readonly property cursor.primaryKey
 cursor.primaryKey = Infinity
 PASS cursor.primaryKey is still first
 index = objectStore.createIndex('first', 'first');
-trying to set readonly property index.name
-index.name = 'bar'
-PASS index.name is still first
 trying to set readonly property index.objectStore
 index.objectStore = this
 PASS index.objectStore is still [object IDBObjectStore]
index d3ea32f..c743c58 100644 (file)
@@ -63,7 +63,6 @@ function checkCursor()
     }
 
     index = evalAndLog("index = objectStore.createIndex('first', 'first');");
-    setReadonlyProperty("index.name", "'bar'");
     setReadonlyProperty("index.objectStore", "this");
     setReadonlyProperty("index.keyPath", "'bar'");
     setReadonlyProperty("index.unique", "true");
index 47df52f..ac2ca1a 100644 (file)
@@ -1,3 +1,114 @@
+2016-10-24  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB 2.0: Support IDBIndex name assignment.
+        <rdar://problem/28806932> and https://bugs.webkit.org/show_bug.cgi?id=163805
+
+        Reviewed by Alex Christensen.
+
+        Tests: storage/indexeddb/modern/index-rename-1-private.html
+               storage/indexeddb/modern/index-rename-1.html
+
+        Touches a *lot* of code sites, but none of them are particularly interesting.
+        They are all just getting the new name spread out to all of the various objects that need it.
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::renameIndex):
+        * Modules/indexeddb/IDBDatabase.h:
+
+        * Modules/indexeddb/IDBIndex.cpp:
+        (WebCore::IDBIndex::IDBIndex):
+        (WebCore::IDBIndex::setName):
+        (WebCore::IDBIndex::rollbackInfoForVersionChangeAbort):
+        * Modules/indexeddb/IDBIndex.h:
+        * Modules/indexeddb/IDBIndex.idl:
+
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::rollbackForVersionChangeAbort):
+        (WebCore::IDBObjectStore::renameReferencedIndex):
+        (WebCore::IDBObjectStore::rollbackInfoForVersionChangeAbort): Deleted.
+        * Modules/indexeddb/IDBObjectStore.h:
+
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::internalAbort):
+        (WebCore::IDBTransaction::renameIndex):
+        (WebCore::IDBTransaction::renameIndexOnServer):
+        (WebCore::IDBTransaction::didRenameIndexOnServer):
+        * Modules/indexeddb/IDBTransaction.h:
+
+        * Modules/indexeddb/client/IDBConnectionProxy.cpp:
+        (WebCore::IDBClient::IDBConnectionProxy::renameIndex):
+        * Modules/indexeddb/client/IDBConnectionProxy.h:
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::renameIndex):
+        (WebCore::IDBClient::IDBConnectionToServer::didRenameIndex):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+
+        * Modules/indexeddb/client/TransactionOperation.h:
+        (WebCore::IDBClient::createTransactionOperation):
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+
+        * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+        (WebCore::IDBServer::IDBConnectionToClient::didRenameIndex):
+        * Modules/indexeddb/server/IDBConnectionToClient.h:
+        * Modules/indexeddb/server/IDBConnectionToClientDelegate.h:
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::renameIndex):
+        * Modules/indexeddb/server/IDBServer.h:
+
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::indexRenamed):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
+
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::renameIndex):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+
+        * Modules/indexeddb/server/MemoryIndex.h:
+        (WebCore::IDBServer::MemoryIndex::rename):
+
+        * Modules/indexeddb/server/MemoryObjectStore.cpp:
+        (WebCore::IDBServer::MemoryObjectStore::renameIndex):
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::renameIndex):
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::renameIndex):
+        (WebCore::IDBServer::UniqueIDBDatabase::performRenameIndex):
+        (WebCore::IDBServer::UniqueIDBDatabase::didPerformRenameIndex):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::didRenameIndex):
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseTransaction::renameIndex):
+        * Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
+
+        * Modules/indexeddb/shared/IDBIndexInfo.h:
+        (WebCore::IDBIndexInfo::rename):
+
+        * Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:
+        (WebCore::IDBObjectStoreInfo::infoForExistingIndex):
+        * Modules/indexeddb/shared/IDBObjectStoreInfo.h:
+
+        * Modules/indexeddb/shared/IDBResultData.cpp:
+        (WebCore::IDBResultData::renameIndexSuccess):
+        * Modules/indexeddb/shared/IDBResultData.h:
+
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::didRenameIndex):
+        (WebCore::InProcessIDBServer::renameIndex):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
 2016-10-24  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Fix -webkit-box-reflect parsing
index 3ed7c7a..7e7a76a 100644 (file)
@@ -34,6 +34,7 @@
 #include "IDBConnectionProxy.h"
 #include "IDBConnectionToServer.h"
 #include "IDBDatabaseException.h"
+#include "IDBIndex.h"
 #include "IDBObjectStore.h"
 #include "IDBOpenDBRequest.h"
 #include "IDBResultData.h"
@@ -117,6 +118,18 @@ void IDBDatabase::renameObjectStore(IDBObjectStore& objectStore, const String& n
     m_versionChangeTransaction->renameObjectStore(objectStore, newName);
 }
 
+void IDBDatabase::renameIndex(IDBIndex& index, const String& newName)
+{
+    ASSERT(currentThread() == originThreadID());
+    ASSERT(m_versionChangeTransaction);
+    ASSERT(m_info.hasObjectStore(index.objectStore().info().name()));
+    ASSERT(m_info.infoForExistingObjectStore(index.objectStore().info().name())->hasIndex(index.info().name()));
+
+    m_info.infoForExistingObjectStore(index.objectStore().info().name())->infoForExistingIndex(index.info().identifier())->rename(newName);
+
+    m_versionChangeTransaction->renameIndex(index, newName);
+}
+
 ExceptionOr<Ref<IDBObjectStore>> IDBDatabase::createObjectStore(const String&, const Dictionary&)
 {
     ASSERT_NOT_REACHED();
index 7de6458..651c2a9 100644 (file)
@@ -63,6 +63,7 @@ public:
     void close();
 
     void renameObjectStore(IDBObjectStore&, const String& newName);
+    void renameIndex(IDBIndex&, const String& newName);
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const final { return IDBDatabaseEventTargetInterfaceType; }
index 0430af4..9776a2b 100644 (file)
@@ -45,6 +45,7 @@ namespace WebCore {
 IDBIndex::IDBIndex(ScriptExecutionContext& context, const IDBIndexInfo& info, IDBObjectStore& objectStore)
     : ActiveDOMObject(&context)
     , m_info(info)
+    , m_originalInfo(info)
     , m_objectStore(objectStore)
 {
     ASSERT(currentThread() == m_objectStore.transaction().database().originThreadID());
@@ -78,6 +79,34 @@ const String& IDBIndex::name() const
     return m_info.name();
 }
 
+ExceptionOr<void> IDBIndex::setName(const String& name)
+{
+    ASSERT(currentThread() == m_objectStore.transaction().database().originThreadID());
+
+    if (m_deleted)
+        return Exception { INVALID_STATE_ERR, ASCIILiteral("Failed set property 'name' on 'IDBIndex': The index has been deleted.") };
+
+    if (m_objectStore.isDeleted())
+        return Exception { INVALID_STATE_ERR, ASCIILiteral("Failed set property 'name' on 'IDBIndex': The index's object store has been deleted.") };
+
+    if (!m_objectStore.transaction().isVersionChange())
+        return Exception { INVALID_STATE_ERR, ASCIILiteral("Failed set property 'name' on 'IDBIndex': The index's transaction is not a version change transaction.") };
+
+    if (!m_objectStore.transaction().isActive())
+        return Exception { INVALID_STATE_ERR, ASCIILiteral("Failed set property 'name' on 'IDBIndex': The index's transaction is not active.") };
+
+    if (m_info.name() == name)
+        return { };
+
+    if (m_objectStore.info().hasIndex(name))
+        return Exception { INVALID_STATE_ERR, makeString("Failed set property 'name' on 'IDBIndex': The owning object store already has an index named '", name, "'.") };
+
+    m_objectStore.transaction().database().renameIndex(*this, name);
+    m_info.rename(name);
+
+    return { };
+}
+
 IDBObjectStore& IDBIndex::objectStore()
 {
     ASSERT(currentThread() == m_objectStore.transaction().database().originThreadID());
@@ -102,6 +131,12 @@ bool IDBIndex::multiEntry() const
     return m_info.multiEntry();
 }
 
+void IDBIndex::rollbackInfoForVersionChangeAbort()
+{
+    ASSERT(currentThread() == m_objectStore.transaction().database().originThreadID());
+    m_info = m_originalInfo;
+}
+
 ExceptionOr<Ref<IDBRequest>> IDBIndex::openCursor(ExecState& execState, IDBKeyRange* range, const String& directionString)
 {
     LOG(IndexedDB, "IDBIndex::openCursor");
index dae695b..56e2b70 100644 (file)
@@ -48,11 +48,14 @@ public:
     virtual ~IDBIndex();
 
     const String& name() const;
+    ExceptionOr<void> setName(const String&);
     IDBObjectStore& objectStore();
     const IDBKeyPath& keyPath() const;
     bool unique() const;
     bool multiEntry() const;
 
+    void rollbackInfoForVersionChangeAbort();
+
     ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, IDBKeyRange*, const String& direction);
     ExceptionOr<Ref<IDBRequest>> openCursor(JSC::ExecState&, JSC::JSValue key, const String& direction);
 
@@ -87,6 +90,7 @@ private:
     bool hasPendingActivity() const final;
 
     IDBIndexInfo m_info;
+    IDBIndexInfo m_originalInfo;
 
     bool m_deleted { false };
 
index 8b73bc8..8c33c65 100644 (file)
@@ -30,7 +30,7 @@
     JSCustomMarkFunction,
     SkipVTableValidation,
 ] interface IDBIndex {
-    readonly attribute DOMString name;
+    [SetterMayThrowException] attribute DOMString name;
     readonly attribute IDBObjectStore objectStore;
     [ImplementationReturnType=IDBKeyPath] readonly attribute any keyPath;
     readonly attribute boolean multiEntry;
index d41d124..a04da61 100644 (file)
@@ -526,10 +526,14 @@ void IDBObjectStore::markAsDeleted()
     m_deleted = true;
 }
 
-void IDBObjectStore::rollbackInfoForVersionChangeAbort()
+void IDBObjectStore::rollbackForVersionChangeAbort()
 {
     ASSERT(currentThread() == m_transaction->database().originThreadID());
     m_info = m_originalInfo;
+
+    Locker<Lock> locker(m_referencedIndexLock);
+    for (auto& index : m_referencedIndexes.values())
+        index->rollbackInfoForVersionChangeAbort();
 }
 
 void IDBObjectStore::visitReferencedIndexes(SlotVisitor& visitor) const
@@ -539,6 +543,21 @@ void IDBObjectStore::visitReferencedIndexes(SlotVisitor& visitor) const
         visitor.addOpaqueRoot(index.get());
 }
 
+void IDBObjectStore::renameReferencedIndex(IDBIndex& index, const String& newName)
+{
+    LOG(IndexedDB, "IDBObjectStore::renameReferencedIndex");
+
+    auto* indexInfo = m_info.infoForExistingIndex(index.info().identifier());
+    ASSERT(indexInfo);
+    indexInfo->rename(newName);
+
+    ASSERT(m_referencedIndexes.contains(index.info().name()));
+    ASSERT(!m_referencedIndexes.contains(newName));
+    ASSERT(m_referencedIndexes.get(index.info().name()) == &index);
+
+    m_referencedIndexes.set(newName, m_referencedIndexes.take(index.info().name()));
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 9ee62d3..a2cc4a4 100644 (file)
@@ -93,9 +93,10 @@ public:
 
     const IDBObjectStoreInfo& info() const { return m_info; }
 
-    void rollbackInfoForVersionChangeAbort();
+    void rollbackForVersionChangeAbort();
 
     void visitReferencedIndexes(JSC::SlotVisitor&) const;
+    void renameReferencedIndex(IDBIndex&, const String& newName);
 
 private:
     IDBObjectStore(ScriptExecutionContext&, const IDBObjectStoreInfo&, IDBTransaction&);
index 32e943a..a4c8662 100644 (file)
@@ -279,7 +279,7 @@ void IDBTransaction::internalAbort()
 
     if (isVersionChange()) {
         for (auto& objectStore : m_referencedObjectStores.values())
-            objectStore->rollbackInfoForVersionChangeAbort();
+            objectStore->rollbackForVersionChangeAbort();
     }
 
     transitionedToFinishing(IndexedDB::TransactionState::Aborting);
@@ -677,6 +677,40 @@ void IDBTransaction::didCreateIndexOnServer(const IDBResultData& resultData)
     abortDueToFailedRequest(DOMError::create(IDBDatabaseException::getErrorName(resultData.error().code()), resultData.error().message()));
 }
 
+void IDBTransaction::renameIndex(IDBIndex& index, const String& newName)
+{
+    LOG(IndexedDB, "IDBTransaction::renameIndex");
+    ASSERT(isVersionChange());
+    ASSERT(scriptExecutionContext());
+    ASSERT(currentThread() == m_database->originThreadID());
+
+    ASSERT(m_referencedObjectStores.contains(index.objectStore().info().name()));
+    ASSERT(m_referencedObjectStores.get(index.objectStore().info().name()) == &index.objectStore());
+
+    index.objectStore().renameReferencedIndex(index, newName);
+
+    uint64_t objectStoreIdentifier = index.objectStore().info().identifier();
+    uint64_t indexIdentifier = index.info().identifier();
+    auto operation = IDBClient::createTransactionOperation(*this, &IDBTransaction::didRenameIndexOnServer, &IDBTransaction::renameIndexOnServer, objectStoreIdentifier, indexIdentifier, newName);
+    scheduleOperation(WTFMove(operation));
+}
+
+void IDBTransaction::renameIndexOnServer(IDBClient::TransactionOperation& operation, const uint64_t& objectStoreIdentifier, const uint64_t& indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "IDBTransaction::renameIndexOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
+    ASSERT(isVersionChange());
+
+    m_database->connectionProxy().renameIndex(operation, objectStoreIdentifier, indexIdentifier, newName);
+}
+
+void IDBTransaction::didRenameIndexOnServer(const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "IDBTransaction::didRenameIndexOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
+    ASSERT_UNUSED(resultData, resultData.type() == IDBResultType::RenameIndexSuccess || resultData.type() == IDBResultType::Error);
+}
+
 Ref<IDBRequest> IDBTransaction::requestOpenCursor(ExecState& execState, IDBObjectStore& objectStore, const IDBCursorInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::requestOpenCursor");
index 26574a8..ea4ef14 100644 (file)
@@ -115,6 +115,7 @@ public:
     Ref<IDBObjectStore> createObjectStore(const IDBObjectStoreInfo&);
     void renameObjectStore(IDBObjectStore&, const String& newName);
     std::unique_ptr<IDBIndex> createIndex(IDBObjectStore&, const IDBIndexInfo&);
+    void renameIndex(IDBIndex&, const String& newName);
 
     Ref<IDBRequest> requestPutOrAdd(JSC::ExecState&, IDBObjectStore&, IDBKey*, SerializedScriptValue&, IndexedDB::ObjectStoreOverwriteMode);
     Ref<IDBRequest> requestGetRecord(JSC::ExecState&, IDBObjectStore&, const IDBGetRecordData&);
@@ -178,6 +179,9 @@ private:
     void createIndexOnServer(IDBClient::TransactionOperation&, const IDBIndexInfo&);
     void didCreateIndexOnServer(const IDBResultData&);
 
+    void renameIndexOnServer(IDBClient::TransactionOperation&, const uint64_t& objectStoreIdentifier, const uint64_t& indexIdentifier, const String& newName);
+    void didRenameIndexOnServer(const IDBResultData&);
+
     void clearObjectStoreOnServer(IDBClient::TransactionOperation&, const uint64_t& objectStoreIdentifier);
     void didClearObjectStoreOnServer(IDBRequest&, const IDBResultData&);
 
index aa5f191..ce77208 100644 (file)
@@ -133,6 +133,14 @@ void IDBConnectionProxy::renameObjectStore(TransactionOperation& operation, uint
     callConnectionOnMainThread(&IDBConnectionToServer::renameObjectStore, requestData, objectStoreIdentifier, newName);
 }
 
+void IDBConnectionProxy::renameIndex(TransactionOperation& operation, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    const IDBRequestData requestData(operation);
+    saveOperation(operation);
+
+    callConnectionOnMainThread(&IDBConnectionToServer::renameIndex, requestData, objectStoreIdentifier, indexIdentifier, newName);
+}
+
 void IDBConnectionProxy::deleteObjectStore(TransactionOperation& operation, const String& objectStoreName)
 {
     const IDBRequestData requestData(operation);
index 0052a44..844885a 100644 (file)
@@ -78,6 +78,7 @@ public:
     void openCursor(TransactionOperation&, const IDBCursorInfo&);
     void iterateCursor(TransactionOperation&, const IDBKeyData&, unsigned long count);
     void renameObjectStore(TransactionOperation&, uint64_t objectStoreIdentifier, const String& newName);
+    void renameIndex(TransactionOperation&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
 
     void fireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
     void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier);
index d6aa858..a04ebff 100644 (file)
@@ -172,6 +172,20 @@ void IDBConnectionToServer::didDeleteIndex(const IDBResultData& resultData)
     m_proxy->completeOperation(resultData);
 }
 
+void IDBConnectionToServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::renameIndex");
+    ASSERT(isMainThread());
+
+    m_delegate->renameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName);
+}
+
+void IDBConnectionToServer::didRenameIndex(const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::didRenameIndex");
+    m_proxy->completeOperation(resultData);
+}
+
 void IDBConnectionToServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& key, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "IDBConnectionToServer::putOrAdd");
index be269b6..d48a993 100644 (file)
@@ -80,6 +80,9 @@ public:
     void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
     WEBCORE_EXPORT void didDeleteIndex(const IDBResultData&);
 
+    void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
+    WEBCORE_EXPORT void didRenameIndex(const IDBResultData&);
+
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode);
     WEBCORE_EXPORT void didPutOrAdd(const IDBResultData&);
 
index 9ce7549..55a6f6b 100644 (file)
@@ -67,6 +67,7 @@ public:
     virtual void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier) = 0;
     virtual void createIndex(const IDBRequestData&, const IDBIndexInfo&) = 0;
     virtual void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName) = 0;
+    virtual void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) = 0;
     virtual void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode) = 0;
     virtual void getRecord(const IDBRequestData&, const IDBGetRecordData&) = 0;
     virtual void getCount(const IDBRequestData&, const IDBKeyRangeData&) = 0;
index bf07bbc..4a8efeb 100644 (file)
@@ -194,6 +194,19 @@ RefPtr<TransactionOperation> createTransactionOperation(
     return adoptRef(operation);
 }
 
+template<typename MP1, typename P1, typename MP2, typename P2, typename MP3, typename P3>
+RefPtr<TransactionOperation> createTransactionOperation(
+    IDBTransaction& transaction,
+    void (IDBTransaction::*complete)(const IDBResultData&),
+    void (IDBTransaction::*perform)(TransactionOperation&, MP1, MP2, MP3),
+    const P1& parameter1,
+    const P2& parameter2,
+    const P3& parameter3)
+{
+    auto operation = new TransactionOperationImpl<MP1, MP2, MP3>(transaction, complete, perform, parameter1, parameter2, parameter3);
+    return adoptRef(operation);
+}
+
 template<typename MP1, typename P1>
 RefPtr<TransactionOperation> createTransactionOperation(
     IDBTransaction& transaction,
index f8a2039..8f17a2f 100644 (file)
@@ -74,6 +74,7 @@ public:
     virtual IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) = 0;
     virtual IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) = 0;
     virtual IDBError deleteIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier) = 0;
+    virtual IDBError renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) = 0;
     virtual IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) = 0;
     virtual IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) = 0;
     virtual IDBError addRecord(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&, const IDBKeyData&, const IDBValue&) = 0;
index 4f8be9a..5300c01 100644 (file)
@@ -93,6 +93,11 @@ void IDBConnectionToClient::didDeleteIndex(const IDBResultData& result)
     m_delegate->didDeleteIndex(result);
 }
 
+void IDBConnectionToClient::didRenameIndex(const IDBResultData& result)
+{
+    m_delegate->didRenameIndex(result);
+}
+
 void IDBConnectionToClient::didPutOrAdd(const IDBResultData& result)
 {
     m_delegate->didPutOrAdd(result);
index 9e8f8dc..e3021bc 100644 (file)
@@ -59,6 +59,7 @@ public:
     void didClearObjectStore(const IDBResultData&);
     void didCreateIndex(const IDBResultData&);
     void didDeleteIndex(const IDBResultData&);
+    void didRenameIndex(const IDBResultData&);
     void didPutOrAdd(const IDBResultData&);
     void didGetRecord(const IDBResultData&);
     void didGetCount(const IDBResultData&);
index fdbbfe0..d767f68 100644 (file)
@@ -57,6 +57,7 @@ public:
     virtual void didClearObjectStore(const IDBResultData&) = 0;
     virtual void didCreateIndex(const IDBResultData&) = 0;
     virtual void didDeleteIndex(const IDBResultData&) = 0;
+    virtual void didRenameIndex(const IDBResultData&) = 0;
     virtual void didPutOrAdd(const IDBResultData&) = 0;
     virtual void didGetRecord(const IDBResultData&) = 0;
     virtual void didGetCount(const IDBResultData&) = 0;
index 28bd3eb..f73ea24 100644 (file)
@@ -260,6 +260,18 @@ void IDBServer::deleteIndex(const IDBRequestData& requestData, uint64_t objectSt
     transaction->deleteIndex(requestData, objectStoreIdentifier, indexName);
 }
 
+void IDBServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "IDBServer::renameIndex");
+
+    auto transaction = m_transactions.get(requestData.transactionIdentifier());
+    if (!transaction)
+        return;
+
+    ASSERT(transaction->isVersionChange());
+    transaction->renameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName);
+}
+
 void IDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "IDBServer::putOrAdd");
index 05e442a..b5918c0 100644 (file)
@@ -71,6 +71,7 @@ public:
     WEBCORE_EXPORT void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier);
     WEBCORE_EXPORT void createIndex(const IDBRequestData&, const IDBIndexInfo&);
     WEBCORE_EXPORT void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
+    WEBCORE_EXPORT void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
     WEBCORE_EXPORT void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, IndexedDB::ObjectStoreOverwriteMode);
     WEBCORE_EXPORT void getRecord(const IDBRequestData&, const IDBGetRecordData&);
     WEBCORE_EXPORT void getCount(const IDBRequestData&, const IDBKeyRangeData&);
index 2548313..4834384 100644 (file)
@@ -160,6 +160,16 @@ void MemoryBackingStoreTransaction::objectStoreRenamed(MemoryObjectStore& object
     m_originalObjectStoreNames.add(&objectStore, oldName);
 }
 
+void MemoryBackingStoreTransaction::indexRenamed(MemoryIndex& index, const String& oldName)
+{
+    ASSERT(m_objectStores.contains(&index.objectStore()));
+    ASSERT(m_info.mode() == IndexedDB::TransactionMode::VersionChange);
+
+    // We only care about the first rename in a given transaction, because if the transaction is aborted we want
+    // to go back to the first 'oldName'
+    m_originalIndexNames.add(&index, oldName);
+}
+
 void MemoryBackingStoreTransaction::indexCleared(MemoryIndex& index, std::unique_ptr<IndexValueStore>&& valueStore)
 {
     auto addResult = m_clearedIndexValueStores.add(&index, nullptr);
@@ -203,6 +213,10 @@ void MemoryBackingStoreTransaction::abort()
 
     TemporaryChange<bool> change(m_isAborting, true);
 
+    for (auto iterator : m_originalIndexNames)
+        iterator.key->rename(iterator.value);
+    m_originalIndexNames.clear();
+
     for (auto iterator : m_originalObjectStoreNames)
         iterator.key->rename(iterator.value);
     m_originalObjectStoreNames.clear();
index 98b2469..5780ecf 100644 (file)
@@ -65,6 +65,7 @@ public:
     void objectStoreDeleted(Ref<MemoryObjectStore>&&);
     void objectStoreCleared(MemoryObjectStore&, std::unique_ptr<KeyValueMap>&&, std::unique_ptr<std::set<IDBKeyData>>&&);
     void objectStoreRenamed(MemoryObjectStore&, const String& oldName);
+    void indexRenamed(MemoryIndex&, const String& oldName);
     void indexCleared(MemoryIndex&, std::unique_ptr<IndexValueStore>&&);
 
     void addNewIndex(MemoryIndex&);
@@ -97,6 +98,7 @@ private:
     HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_clearedKeyValueMaps;
     HashMap<MemoryObjectStore*, std::unique_ptr<std::set<IDBKeyData>>> m_clearedOrderedKeys;
     HashMap<MemoryObjectStore*, String> m_originalObjectStoreNames;
+    HashMap<MemoryIndex*, String> m_originalIndexNames;
     HashMap<MemoryIndex*, std::unique_ptr<IndexValueStore>> m_clearedIndexValueStores;
 };
 
index df240b5..a2bf28f 100644 (file)
@@ -248,6 +248,42 @@ IDBError MemoryIDBBackingStore::deleteIndex(const IDBResourceIdentifier& transac
     return objectStore->deleteIndex(*rawTransaction, indexIdentifier);
 }
 
+IDBError MemoryIDBBackingStore::renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "MemoryIDBBackingStore::renameIndex");
+
+    ASSERT(m_databaseInfo);
+    auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier);
+    if (!objectStoreInfo)
+        return IDBError(IDBDatabaseException::ConstraintError);
+
+    auto* indexInfo = objectStoreInfo->infoForExistingIndex(indexIdentifier);
+    if (!indexInfo)
+        return IDBError(IDBDatabaseException::ConstraintError);
+
+    auto transaction = m_transactions.get(transactionIdentifier);
+    ASSERT(transaction);
+    ASSERT(transaction->isVersionChange());
+
+    auto objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier);
+    ASSERT(objectStore);
+    if (!objectStore)
+        return IDBError(IDBDatabaseException::ConstraintError);
+
+    auto* index = objectStore->indexForIdentifier(indexIdentifier);
+    ASSERT(index);
+    if (!index)
+        return IDBError(IDBDatabaseException::ConstraintError);
+
+    String oldName = index->info().name();
+    objectStore->renameIndex(*index, newName);
+    transaction->indexRenamed(*index, oldName);
+
+    indexInfo->rename(newName);
+
+    return IDBError();
+}
+
 void MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort(MemoryObjectStore& objectStore)
 {
     LOG(IndexedDB, "MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort");
index b5b981e..a1424cd 100644 (file)
@@ -58,6 +58,7 @@ public:
     IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) final;
     IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) final;
     IDBError deleteIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier) final;
+    IDBError renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
     IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) final;
     IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) final;
     IDBError addRecord(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&, const IDBKeyData&, const IDBValue&) final;
index 305fa6a..7ec47ce 100644 (file)
@@ -62,6 +62,8 @@ public:
 
     const IDBIndexInfo& info() const { return m_info; }
 
+    void rename(const String& newName) { m_info.rename(newName); }
+
     IDBGetResult getResultForKeyRange(IndexedDB::IndexRecordType, const IDBKeyRangeData&) const;
     uint64_t countForKeyRange(const IDBKeyRangeData&);
 
index fc515f2..41e4f40 100644 (file)
@@ -475,6 +475,17 @@ MemoryObjectStoreCursor* MemoryObjectStore::maybeOpenCursor(const IDBCursorInfo&
     return result.iterator->value.get();
 }
 
+void MemoryObjectStore::renameIndex(MemoryIndex& index, const String& newName)
+{
+    ASSERT(m_indexesByName.get(index.info().name()) == &index);
+    ASSERT(!m_indexesByName.contains(newName));
+    ASSERT(m_info.infoForExistingIndex(index.info().name()));
+
+    m_info.infoForExistingIndex(index.info().name())->rename(newName);
+    m_indexesByName.set(newName, m_indexesByName.take(index.info().name()));
+    index.rename(newName);
+}
+
 } // namespace IDBServer
 } // namespace WebCore
 
index 3c76aa0..0bf57d9 100644 (file)
@@ -98,6 +98,7 @@ public:
     void maybeRestoreDeletedIndex(Ref<MemoryIndex>&&);
 
     void rename(const String& newName) { m_info.rename(newName); }
+    void renameIndex(MemoryIndex&, const String& newName);
 
 private:
     MemoryObjectStore(const IDBObjectStoreInfo&);
index 0262146..bd76ef4 100644 (file)
@@ -1275,6 +1275,49 @@ IDBError SQLiteIDBBackingStore::deleteIndex(const IDBResourceIdentifier& transac
     return { };
 }
 
+IDBError SQLiteIDBBackingStore::renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "SQLiteIDBBackingStore::renameIndex - object store %" PRIu64 ", index %" PRIu64, objectStoreIdentifier, indexIdentifier);
+
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier);
+    if (!objectStoreInfo)
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Could not rename index") };
+
+    auto* indexInfo = objectStoreInfo->infoForExistingIndex(indexIdentifier);
+    if (!indexInfo)
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Could not rename index") };
+
+    auto* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction->inProgress()) {
+        LOG_ERROR("Attempt to rename an index without an in-progress transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to rename an index without an in-progress transaction") };
+    }
+
+    if (transaction->mode() != IndexedDB::TransactionMode::VersionChange) {
+        LOG_ERROR("Attempt to rename an index in a non-version-change transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to rename an index in a non-version-change transaction") };
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("UPDATE IndexInfo SET name = ? WHERE objectStoreID = ? AND id = ?;"));
+        if (sql.prepare() != SQLITE_OK
+            || sql.bindText(1, newName) != SQLITE_OK
+            || sql.bindInt64(2, objectStoreIdentifier) != SQLITE_OK
+            || sql.bindInt64(3, indexIdentifier) != SQLITE_OK
+            || sql.step() != SQLITE_DONE) {
+            LOG_ERROR("Could not update name for index id (%" PRIi64 ", %" PRIi64 ") in IndexInfo table (%i) - %s", objectStoreIdentifier, indexIdentifier, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Could not rename index") };
+        }
+    }
+
+    indexInfo->rename(newName);
+
+    return { };
+}
+
 IDBError SQLiteIDBBackingStore::keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreID, const IDBKeyData& keyData, bool& keyExists)
 {
     LOG(IndexedDB, "SQLiteIDBBackingStore::keyExistsInObjectStore - key %s, object store %" PRIu64, keyData.loggingString().utf8().data(), objectStoreID);
index 87dcb92..8c0c9be 100644 (file)
@@ -62,6 +62,7 @@ public:
     IDBError clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier) final;
     IDBError createIndex(const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&) final;
     IDBError deleteIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier) final;
+    IDBError renameIndex(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
     IDBError keyExistsInObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, bool& keyExists) final;
     IDBError deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&) final;
     IDBError addRecord(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo&, const IDBKeyData&, const IDBValue&) final;
index c25677b..302f837 100644 (file)
@@ -819,6 +819,60 @@ void UniqueIDBDatabase::didPerformDeleteIndex(uint64_t callbackIdentifier, const
     performErrorCallback(callbackIdentifier, error);
 }
 
+void UniqueIDBDatabase::renameIndex(UniqueIDBDatabaseTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName, ErrorCallback callback)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::renameIndex");
+
+    uint64_t callbackID = storeCallbackOrFireError(callback);
+    if (!callbackID)
+        return;
+
+    auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier);
+    if (!objectStoreInfo) {
+        performErrorCallback(callbackID, { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to rename index in non-existant object store") });
+        return;
+    }
+
+    auto* indexInfo = objectStoreInfo->infoForExistingIndex(indexIdentifier);
+    if (!indexInfo) {
+        performErrorCallback(callbackID, { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to rename non-existant index") });
+        return;
+    }
+
+    postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::performRenameIndex, callbackID, transaction.info().identifier(), objectStoreIdentifier, indexIdentifier, newName));
+}
+
+void UniqueIDBDatabase::performRenameIndex(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    ASSERT(!isMainThread());
+    LOG(IndexedDB, "(db) UniqueIDBDatabase::performRenameIndex");
+
+    ASSERT(m_backingStore);
+    m_backingStore->renameIndex(transactionIdentifier, objectStoreIdentifier, indexIdentifier, newName);
+
+    IDBError error;
+    postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformRenameIndex, callbackIdentifier, error, objectStoreIdentifier, indexIdentifier, newName));
+}
+
+void UniqueIDBDatabase::didPerformRenameIndex(uint64_t callbackIdentifier, const IDBError& error, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    ASSERT(isMainThread());
+    LOG(IndexedDB, "(main) UniqueIDBDatabase::didPerformRenameIndex");
+
+    if (error.isNull()) {
+        auto* objectStoreInfo = m_databaseInfo->infoForExistingObjectStore(objectStoreIdentifier);
+        ASSERT(objectStoreInfo);
+        if (objectStoreInfo) {
+            auto* indexInfo = objectStoreInfo->infoForExistingIndex(indexIdentifier);
+            ASSERT(indexInfo);
+            indexInfo->rename(newName);
+        }
+    }
+
+    performErrorCallback(callbackIdentifier, error);
+}
+
 void UniqueIDBDatabase::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, IndexedDB::ObjectStoreOverwriteMode overwriteMode, KeyDataCallback callback)
 {
     ASSERT(isMainThread());
index 19fa153..5ce6688 100644 (file)
@@ -91,6 +91,7 @@ public:
     void clearObjectStore(UniqueIDBDatabaseTransaction&, uint64_t objectStoreIdentifier, ErrorCallback);
     void createIndex(UniqueIDBDatabaseTransaction&, const IDBIndexInfo&, ErrorCallback);
     void deleteIndex(UniqueIDBDatabaseTransaction&, uint64_t objectStoreIdentifier, const String& indexName, ErrorCallback);
+    void renameIndex(UniqueIDBDatabaseTransaction&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName, ErrorCallback);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, IndexedDB::ObjectStoreOverwriteMode, KeyDataCallback);
     void getRecord(const IDBRequestData&, const IDBGetRecordData&, GetResultCallback);
     void getCount(const IDBRequestData&, const IDBKeyRangeData&, CountCallback);
@@ -149,6 +150,7 @@ private:
     void performClearObjectStore(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier);
     void performCreateIndex(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, const IDBIndexInfo&);
     void performDeleteIndex(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier);
+    void performRenameIndex(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
     void performPutOrAdd(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const IDBValue&, IndexedDB::ObjectStoreOverwriteMode);
     void performGetRecord(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData&);
     void performGetIndexRecord(uint64_t callbackIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType, const IDBKeyRangeData&);
@@ -168,6 +170,7 @@ private:
     void didPerformClearObjectStore(uint64_t callbackIdentifier, const IDBError&);
     void didPerformCreateIndex(uint64_t callbackIdentifier, const IDBError&, const IDBIndexInfo&);
     void didPerformDeleteIndex(uint64_t callbackIdentifier, const IDBError&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier);
+    void didPerformRenameIndex(uint64_t callbackIdentifier, const IDBError&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
     void didPerformPutOrAdd(uint64_t callbackIdentifier, const IDBError&, const IDBKeyData&);
     void didPerformGetRecord(uint64_t callbackIdentifier, const IDBError&, const IDBGetResult&);
     void didPerformGetCount(uint64_t callbackIdentifier, const IDBError&, uint64_t);
index 252c54b..fd1c3c3 100644 (file)
@@ -212,6 +212,13 @@ void UniqueIDBDatabaseConnection::didDeleteIndex(const IDBResultData& resultData
     m_connectionToClient.didDeleteIndex(resultData);
 }
 
+void UniqueIDBDatabaseConnection::didRenameIndex(const IDBResultData& resultData)
+{
+    LOG(IndexedDB, "UniqueIDBDatabaseConnection::didRenameIndex");
+
+    m_connectionToClient.didRenameIndex(resultData);
+}
+
 } // namespace IDBServer
 } // namespace WebCore
 
index 56cf7df..a4f35be 100644 (file)
@@ -73,6 +73,7 @@ public:
     void didClearObjectStore(const IDBResultData&);
     void didCreateIndex(const IDBResultData&);
     void didDeleteIndex(const IDBResultData&);
+    void didRenameIndex(const IDBResultData&);
     void didFireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier);
     void didFinishHandlingVersionChange(const IDBResourceIdentifier& transactionIdentifier);
     void confirmDidCloseFromServer();
index 0ec2eab..0588d7c 100644 (file)
@@ -204,6 +204,24 @@ void UniqueIDBDatabaseTransaction::deleteIndex(const IDBRequestData& requestData
     });
 }
 
+void UniqueIDBDatabaseTransaction::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    LOG(IndexedDB, "UniqueIDBDatabaseTransaction::renameIndex");
+
+    ASSERT(isVersionChange());
+    ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
+
+    RefPtr<UniqueIDBDatabaseTransaction> protectedThis(this);
+    m_databaseConnection->database().renameIndex(*this, objectStoreIdentifier, indexIdentifier, newName, [this, protectedThis, requestData](const IDBError& error) {
+        LOG(IndexedDB, "UniqueIDBDatabaseTransaction::renameIndex (callback)");
+        if (error.isNull())
+            m_databaseConnection->didRenameIndex(IDBResultData::renameIndexSuccess(requestData.requestIdentifier()));
+        else
+            m_databaseConnection->didRenameIndex(IDBResultData::error(requestData.requestIdentifier(), error));
+    });
+}
+
+
 void UniqueIDBDatabaseTransaction::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     LOG(IndexedDB, "UniqueIDBDatabaseTransaction::putOrAdd");
index 8ccdb77..2326b30 100644 (file)
@@ -73,6 +73,7 @@ public:
     void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier);
     void createIndex(const IDBRequestData&, const IDBIndexInfo&);
     void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
+    void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, IndexedDB::ObjectStoreOverwriteMode);
     void getRecord(const IDBRequestData&, const IDBGetRecordData&);
     void getCount(const IDBRequestData&, const IDBKeyRangeData&);
index 8ee7985..7f09d92 100644 (file)
@@ -47,6 +47,8 @@ public:
     bool unique() const { return m_unique; }
     bool multiEntry() const { return m_multiEntry; }
 
+    void rename(const String& newName) { m_name = newName; }
+
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static bool decode(Decoder&, IDBIndexInfo&);
 
index 28928a1..3f1c85e 100644 (file)
@@ -85,6 +85,15 @@ IDBIndexInfo* IDBObjectStoreInfo::infoForExistingIndex(const String& name)
     return nullptr;
 }
 
+IDBIndexInfo* IDBObjectStoreInfo::infoForExistingIndex(uint64_t identifier)
+{
+    auto iterator = m_indexMap.find(identifier);
+    if (iterator == m_indexMap.end())
+        return nullptr;
+
+    return &iterator->value;
+}
+
 IDBObjectStoreInfo IDBObjectStoreInfo::isolatedCopy() const
 {
     IDBObjectStoreInfo result = { m_identifier, m_name.isolatedCopy(), m_keyPath.isolatedCopy(), m_autoIncrement };
index e879611..ddea1ea 100644 (file)
@@ -57,6 +57,7 @@ public:
     bool hasIndex(const String& name) const;
     bool hasIndex(uint64_t indexIdentifier) const;
     IDBIndexInfo* infoForExistingIndex(const String& name);
+    IDBIndexInfo* infoForExistingIndex(uint64_t identifier);
 
     Vector<String> indexNames() const;
     const HashMap<uint64_t, IDBIndexInfo>& indexMap() const { return m_indexMap; }
@@ -79,7 +80,6 @@ private:
     uint64_t m_maxIndexID { 0 };
 
     HashMap<uint64_t, IDBIndexInfo> m_indexMap;
-
 };
 
 template<class Encoder>
index 078c177..d9061ab 100644 (file)
@@ -159,6 +159,11 @@ IDBResultData IDBResultData::deleteIndexSuccess(const IDBResourceIdentifier& req
     return { IDBResultType::DeleteIndexSuccess, requestIdentifier };
 }
 
+IDBResultData IDBResultData::renameIndexSuccess(const IDBResourceIdentifier& requestIdentifier)
+{
+    return { IDBResultType::RenameIndexSuccess, requestIdentifier };
+}
+
 IDBResultData IDBResultData::putOrAddSuccess(const IDBResourceIdentifier& requestIdentifier, const IDBKeyData& resultKey)
 {
     IDBResultData result(IDBResultType::PutOrAddSuccess, requestIdentifier);
index e8638d8..03bb225 100644 (file)
@@ -58,6 +58,7 @@ enum class IDBResultType {
     OpenCursorSuccess,
     IterateCursorSuccess,
     RenameObjectStoreSuccess,
+    RenameIndexSuccess,
 };
 
 namespace IDBServer {
@@ -77,6 +78,7 @@ public:
     static IDBResultData clearObjectStoreSuccess(const IDBResourceIdentifier&);
     static IDBResultData createIndexSuccess(const IDBResourceIdentifier&);
     static IDBResultData deleteIndexSuccess(const IDBResourceIdentifier&);
+    static IDBResultData renameIndexSuccess(const IDBResourceIdentifier&);
     static IDBResultData putOrAddSuccess(const IDBResourceIdentifier&, const IDBKeyData&);
     static IDBResultData getRecordSuccess(const IDBResourceIdentifier&, const IDBGetResult&);
     static IDBResultData getCountSuccess(const IDBResourceIdentifier&, uint64_t count);
index 181342e..dce4c34 100644 (file)
@@ -174,6 +174,13 @@ void InProcessIDBServer::didDeleteIndex(const IDBResultData& resultData)
     });
 }
 
+void InProcessIDBServer::didRenameIndex(const IDBResultData& resultData)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
+        m_connectionToServer->didRenameIndex(resultData);
+    });
+}
+
 void InProcessIDBServer::didPutOrAdd(const IDBResultData& resultData)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), resultData] {
@@ -279,6 +286,13 @@ void InProcessIDBServer::deleteIndex(const IDBRequestData& requestData, uint64_t
     });
 }
 
+void InProcessIDBServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, objectStoreIdentifier, indexIdentifier, newName] {
+        m_server->renameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName);
+    });
+}
+
 void InProcessIDBServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode overwriteMode)
 {
     RunLoop::current().dispatch([this, protectedThis = makeRef(*this), requestData, keyData, value, overwriteMode] {
index 744043f..7835503 100644 (file)
@@ -68,6 +68,7 @@ public:
     void clearObjectStore(const IDBRequestData&, uint64_t objectStoreIdentifier) final;
     void createIndex(const IDBRequestData&, const IDBIndexInfo&) final;
     void deleteIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName) final;
+    void renameIndex(const IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
     void putOrAdd(const IDBRequestData&, const IDBKeyData&, const IDBValue&, const IndexedDB::ObjectStoreOverwriteMode) final;
     void getRecord(const IDBRequestData&, const IDBGetRecordData&) final;
     void getCount(const IDBRequestData&, const IDBKeyRangeData&) final;
@@ -94,6 +95,7 @@ public:
     void didClearObjectStore(const IDBResultData&) final;
     void didCreateIndex(const IDBResultData&) final;
     void didDeleteIndex(const IDBResultData&) final;
+    void didRenameIndex(const IDBResultData&) final;
     void didPutOrAdd(const IDBResultData&) final;
     void didGetRecord(const IDBResultData&) final;
     void didGetCount(const IDBResultData&) final;
index 2a2486b..a011e57 100644 (file)
@@ -1,3 +1,22 @@
+2016-10-24  Brady Eidson  <beidson@apple.com>
+
+        IndexedDB 2.0: Support IDBIndex name assignment.
+        <rdar://problem/28806932> and https://bugs.webkit.org/show_bug.cgi?id=163805
+
+        Reviewed by Alex Christensen.
+
+        * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.cpp:
+        (WebKit::WebIDBConnectionToClient::didRenameIndex):
+        (WebKit::WebIDBConnectionToClient::renameIndex):
+        * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.h:
+        * DatabaseProcess/IndexedDB/WebIDBConnectionToClient.messages.in:
+
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
+        (WebKit::WebIDBConnectionToServer::renameIndex):
+        (WebKit::WebIDBConnectionToServer::didRenameIndex):
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.messages.in:
+
 2016-10-23  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         [GTK] Remove DO NOT MODIFY headers from files that are no longer autogenerated
index 82dc744..309f37f 100644 (file)
@@ -127,6 +127,11 @@ void WebIDBConnectionToClient::didDeleteIndex(const WebCore::IDBResultData& resu
     send(Messages::WebIDBConnectionToServer::DidDeleteIndex(resultData));
 }
 
+void WebIDBConnectionToClient::didRenameIndex(const WebCore::IDBResultData& resultData)
+{
+    send(Messages::WebIDBConnectionToServer::DidRenameIndex(resultData));
+}
+
 void WebIDBConnectionToClient::didPutOrAdd(const WebCore::IDBResultData& resultData)
 {
     send(Messages::WebIDBConnectionToServer::DidPutOrAdd(resultData));
@@ -260,6 +265,11 @@ void WebIDBConnectionToClient::deleteIndex(const IDBRequestData& request, uint64
     DatabaseProcess::singleton().idbServer().deleteIndex(request, objectStoreIdentifier, name);
 }
 
+void WebIDBConnectionToClient::renameIndex(const IDBRequestData& request, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    DatabaseProcess::singleton().idbServer().renameIndex(request, objectStoreIdentifier, indexIdentifier, newName);
+}
+
 void WebIDBConnectionToClient::putOrAdd(const IDBRequestData& request, const IDBKeyData& key, const IDBValue& value, unsigned overwriteMode)
 {
     if (overwriteMode != static_cast<unsigned>(IndexedDB::ObjectStoreOverwriteMode::NoOverwrite)
index d548201..2c8e4da 100644 (file)
@@ -68,6 +68,7 @@ public:
     void didClearObjectStore(const WebCore::IDBResultData&) final;
     void didCreateIndex(const WebCore::IDBResultData&) final;
     void didDeleteIndex(const WebCore::IDBResultData&) final;
+    void didRenameIndex(const WebCore::IDBResultData&) final;
     void didPutOrAdd(const WebCore::IDBResultData&) final;
     void didGetRecord(const WebCore::IDBResultData&) final;
     void didGetCount(const WebCore::IDBResultData&) final;
@@ -97,6 +98,7 @@ public:
     void clearObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier);
     void createIndex(const WebCore::IDBRequestData&, const WebCore::IDBIndexInfo&);
     void deleteIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName);
+    void renameIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName);
     void putOrAdd(const WebCore::IDBRequestData&, const WebCore::IDBKeyData&, const WebCore::IDBValue&, unsigned overwriteMode);
     void getRecord(const WebCore::IDBRequestData&, const WebCore::IDBGetRecordData&);
     void getCount(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&);
index 20bb575..d9fabd7 100644 (file)
@@ -34,6 +34,7 @@ messages -> WebIDBConnectionToClient {
     ClearObjectStore(WebCore::IDBRequestData requestData, uint64_t objectStoreIdentifier);
     CreateIndex(WebCore::IDBRequestData requestData, WebCore::IDBIndexInfo info);
     DeleteIndex(WebCore::IDBRequestData requestData, uint64_t objectStoreIdentifier, String indexName);
+    RenameIndex(WebCore::IDBRequestData requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, String newName);
     PutOrAdd(WebCore::IDBRequestData requestData, WebCore::IDBKeyData key, WebCore::IDBValue value, unsigned overwriteMode);
     GetRecord(WebCore::IDBRequestData requestData, struct WebCore::IDBGetRecordData getRecordData);
     GetCount(WebCore::IDBRequestData requestData, struct WebCore::IDBKeyRangeData range);
index 6e694c4..7b3b3f8 100644 (file)
@@ -138,6 +138,11 @@ void WebIDBConnectionToServer::deleteIndex(const IDBRequestData& requestData, ui
     send(Messages::WebIDBConnectionToClient::DeleteIndex(requestData, objectStoreIdentifier, indexName));
 }
 
+void WebIDBConnectionToServer::renameIndex(const IDBRequestData& requestData, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName)
+{
+    send(Messages::WebIDBConnectionToClient::RenameIndex(requestData, objectStoreIdentifier, indexIdentifier, newName));
+}
+
 void WebIDBConnectionToServer::putOrAdd(const IDBRequestData& requestData, const IDBKeyData& keyData, const IDBValue& value, const IndexedDB::ObjectStoreOverwriteMode mode)
 {
     send(Messages::WebIDBConnectionToClient::PutOrAdd(requestData, keyData, value, static_cast<unsigned>(mode)));
@@ -253,6 +258,11 @@ void WebIDBConnectionToServer::didDeleteIndex(const IDBResultData& result)
     m_connectionToServer->didDeleteIndex(result);
 }
 
+void WebIDBConnectionToServer::didRenameIndex(const IDBResultData& result)
+{
+    m_connectionToServer->didRenameIndex(result);
+}
+
 void WebIDBConnectionToServer::didPutOrAdd(const IDBResultData& result)
 {
     m_connectionToServer->didPutOrAdd(result);
index 6d523c6..08e82b6 100644 (file)
@@ -57,6 +57,7 @@ public:
     void clearObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier) final;
     void createIndex(const WebCore::IDBRequestData&, const WebCore::IDBIndexInfo&) final;
     void deleteIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName) final;
+    void renameIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName) final;
     void putOrAdd(const WebCore::IDBRequestData&, const WebCore::IDBKeyData&, const WebCore::IDBValue&, const WebCore::IndexedDB::ObjectStoreOverwriteMode) final;
     void getRecord(const WebCore::IDBRequestData&, const WebCore::IDBGetRecordData&) final;
     void getCount(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&) final;
@@ -86,6 +87,7 @@ public:
     void didClearObjectStore(const WebCore::IDBResultData&);
     void didCreateIndex(const WebCore::IDBResultData&);
     void didDeleteIndex(const WebCore::IDBResultData&);
+    void didRenameIndex(const WebCore::IDBResultData&);
     void didPutOrAdd(const WebCore::IDBResultData&);
     void didGetRecord(const WebIDBResult&);
     void didGetCount(const WebCore::IDBResultData&);
index 9b457f5..39800d1 100644 (file)
@@ -33,6 +33,7 @@ messages -> WebIDBConnectionToServer {
     DidClearObjectStore(WebCore::IDBResultData result)
     DidCreateIndex(WebCore::IDBResultData result)
     DidDeleteIndex(WebCore::IDBResultData result)
+    DidRenameIndex(WebCore::IDBResultData result)
     DidPutOrAdd(WebCore::IDBResultData result)
     DidGetRecord(WebKit::WebIDBResult result)
     DidGetCount(WebCore::IDBResultData result)