Title: [196518] trunk
Revision
196518
Author
beid...@apple.com
Date
2016-02-12 15:01:20 -0800 (Fri, 12 Feb 2016)

Log Message

Modern IDB: Simplify the relationship between IDBObjectStore and IDBIndex.
https://bugs.webkit.org/show_bug.cgi?id=154187

Reviewed by Alex Christensen.

Source/WebCore:

Tests: storage/indexeddb/modern/deleteindex-3-private.html
       storage/indexeddb/modern/deleteindex-3.html

Instead of allowing IDBIndex to have two different lifecycle modes, it is now always
owned by an IDBObjectStore.

To support the case where an IDBIndex is deleted from its IDBObjectStore, the object
store simply hangs on to deleted indexes until it is destroyed itself.

* Modules/indexeddb/client/IDBIndexImpl.cpp:
(WebCore::IDBClient::IDBIndex::markAsDeleted):
(WebCore::IDBClient::IDBIndex::ref):
(WebCore::IDBClient::IDBIndex::deref):
* Modules/indexeddb/client/IDBIndexImpl.h:

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

LayoutTests:

* storage/indexeddb/modern/deleteindex-3-expected.txt: Added.
* storage/indexeddb/modern/deleteindex-3-private-expected.txt: Added.
* storage/indexeddb/modern/deleteindex-3-private.html: Added.
* storage/indexeddb/modern/deleteindex-3.html: Added.
* storage/indexeddb/modern/resources/deleteindex-3.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (196517 => 196518)


--- trunk/LayoutTests/ChangeLog	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/LayoutTests/ChangeLog	2016-02-12 23:01:20 UTC (rev 196518)
@@ -1,3 +1,16 @@
+2016-02-12  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Simplify the relationship between IDBObjectStore and IDBIndex.
+        https://bugs.webkit.org/show_bug.cgi?id=154187
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/deleteindex-3-expected.txt: Added.
+        * storage/indexeddb/modern/deleteindex-3-private-expected.txt: Added.
+        * storage/indexeddb/modern/deleteindex-3-private.html: Added.
+        * storage/indexeddb/modern/deleteindex-3.html: Added.
+        * storage/indexeddb/modern/resources/deleteindex-3.js: Added.
+
 2016-02-12  Yusuke Suzuki  <utatane....@gmail.com>
 
         [ES6] Implement @@search

Added: trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-expected.txt (0 => 196518)


--- trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-expected.txt	2016-02-12 23:01:20 UTC (rev 196518)
@@ -0,0 +1,23 @@
+This tests creating an index, deleting it, creating a new one with the same name, and making sure those two indexes aren't equal.
+
+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)
+First and Second indexes are the same: false
+First index keyPath: foo
+Second index keyPath: bar
+First index unique: false
+Second index unique: true
+First index references back to objectStore: true
+Second index references back to objectStore: true
+objectStore's index for 'FooIndex' is equal to first index: false
+objectStore's index for 'FooIndex' is equal to second index: true
+Initial upgrade versionchange transaction complete
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private-expected.txt (0 => 196518)


--- trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private-expected.txt	2016-02-12 23:01:20 UTC (rev 196518)
@@ -0,0 +1,23 @@
+This tests creating an index, deleting it, creating a new one with the same name, and making sure those two indexes aren't equal.
+
+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)
+First and Second indexes are the same: false
+First index keyPath: foo
+Second index keyPath: bar
+First index unique: false
+Second index unique: true
+First index references back to objectStore: true
+Second index references back to objectStore: true
+objectStore's index for 'FooIndex' is equal to first index: false
+objectStore's index for 'FooIndex' is equal to second index: true
+Initial upgrade versionchange transaction complete
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private.html (0 => 196518)


--- trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private.html	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3-private.html	2016-02-12 23:01:20 UTC (rev 196518)
@@ -0,0 +1,12 @@
+<html>
+<head>
+<script>
+enablePrivateBrowsing = true;
+</script>
+<script src=""
+<script src=""
+</head>
+<body>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3.html (0 => 196518)


--- trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3.html	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/deleteindex-3.html	2016-02-12 23:01:20 UTC (rev 196518)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/storage/indexeddb/modern/resources/deleteindex-3.js (0 => 196518)


--- trunk/LayoutTests/storage/indexeddb/modern/resources/deleteindex-3.js	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/resources/deleteindex-3.js	2016-02-12 23:01:20 UTC (rev 196518)
@@ -0,0 +1,41 @@
+description("This tests creating an index, deleting it, creating a new one with the same name, and making sure those two indexes aren't equal.");
+
+indexedDBTest(prepareDatabase);
+
+function prepareDatabase(event)
+{
+    var versionTransaction = event.target.transaction;
+    var database = event.target.result;
+    var objectStore = database.createObjectStore("TestObjectStore");
+    objectStore.put({ foo: "a", bar: "A" }, 1);
+    objectStore.put({ foo: "b", bar: "B" }, 2);
+
+    var index1 = objectStore.createIndex("FooIndex", "foo");
+    objectStore.deleteIndex("FooIndex");
+    var index2 = objectStore.createIndex("FooIndex", "bar", { unique: true });
+
+    debug("First and Second indexes are the same: " + (index1 == index2));
+    debug("First index keyPath: " + index1.keyPath);
+    debug("Second index keyPath: " + index2.keyPath);
+    debug("First index unique: " + index1.unique);
+    debug("Second index unique: " + index2.unique);
+    debug("First index references back to objectStore: " + (index1.objectStore == objectStore));
+    debug("Second index references back to objectStore: " + (index2.objectStore == objectStore));
+    debug("objectStore's index for 'FooIndex' is equal to first index: " + (objectStore.index("FooIndex") == index1));
+    debug("objectStore's index for 'FooIndex' is equal to second index: " + (objectStore.index("FooIndex") == index2));
+    
+    versionTransaction._onabort_ = function(event) {
+        debug("Initial upgrade versionchange transaction unexpected abort");
+        finishJSTest();
+    }
+
+    versionTransaction._oncomplete_ = function(event) {
+        debug("Initial upgrade versionchange transaction complete");
+        finishJSTest();
+    }
+
+    versionTransaction._onerror_ = function(event) {
+        debug("Initial upgrade versionchange transaction unexpected error" + event);
+        finishJSTest();
+    }
+}

Modified: trunk/Source/WebCore/ChangeLog (196517 => 196518)


--- trunk/Source/WebCore/ChangeLog	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/Source/WebCore/ChangeLog	2016-02-12 23:01:20 UTC (rev 196518)
@@ -1,3 +1,29 @@
+2016-02-12  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Simplify the relationship between IDBObjectStore and IDBIndex.
+        https://bugs.webkit.org/show_bug.cgi?id=154187
+
+        Reviewed by Alex Christensen.
+
+        Tests: storage/indexeddb/modern/deleteindex-3-private.html
+               storage/indexeddb/modern/deleteindex-3.html
+
+        Instead of allowing IDBIndex to have two different lifecycle modes, it is now always
+        owned by an IDBObjectStore.
+        
+        To support the case where an IDBIndex is deleted from its IDBObjectStore, the object
+        store simply hangs on to deleted indexes until it is destroyed itself.
+        
+        * Modules/indexeddb/client/IDBIndexImpl.cpp:
+        (WebCore::IDBClient::IDBIndex::markAsDeleted):
+        (WebCore::IDBClient::IDBIndex::ref):
+        (WebCore::IDBClient::IDBIndex::deref):
+        * Modules/indexeddb/client/IDBIndexImpl.h:
+        
+        * Modules/indexeddb/client/IDBObjectStoreImpl.cpp:
+        (WebCore::IDBClient::IDBObjectStore::deleteIndex):
+        * Modules/indexeddb/client/IDBObjectStoreImpl.h:
+
 2016-02-12  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [CSS Font Loading] Implement CSSFontFace Boilerplate

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.cpp (196517 => 196518)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.cpp	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.cpp	2016-02-12 23:01:20 UTC (rev 196518)
@@ -339,49 +339,20 @@
     return transaction.requestGetKey(context, *this, range);
 }
 
-void IDBIndex::markAsDeleted(std::unique_ptr<IDBIndex>&& indexOwner)
+void IDBIndex::markAsDeleted()
 {
     ASSERT(!m_deleted);
-    ASSERT(!m_selfOwner);
-    ASSERT(indexOwner.get() == this);
-
-    // If nobody was keeping a ref to this IDBIndex while under IDBObjectStore ownership,
-    // it can be deleted now by letting indexOwner go out of scope.
-    if (!m_refCount)
-        return;
-
-    m_selfOwner = WTFMove(indexOwner);
-
-    // Now that the IDBIndex is managing its own lifetime, it must ref() its IDBObjectStore to keep it alive.
-    m_objectStoreRef = &m_objectStore;
-
-    // It must undo all of the refs it had previously given its IDBObjectStore when the lifetimes were intertwined.
-    for (unsigned i = m_refCount; i > 0; --i)
-        m_objectStore.deref();
-
     m_deleted = true;
 }
 
 void IDBIndex::ref()
 {
-    ++m_refCount;
-
-    if (!m_deleted)
-        m_objectStore.ref();
+    m_objectStore.ref();
 }
 
 void IDBIndex::deref()
 {
-    --m_refCount;
-
-    if (!m_deleted)
-        m_objectStore.deref();
-    else {
-        // This IDBIndex has been detached from its IDBObjectStore so if its RefCount
-        // just went to 0 it should be destroyed.
-        if (!m_refCount)
-            m_selfOwner = nullptr;
-    }
+    m_objectStore.deref();
 }
 
 } // namespace IDBClient

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.h (196517 => 196518)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.h	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBIndexImpl.h	2016-02-12 23:01:20 UTC (rev 196518)
@@ -79,7 +79,7 @@
 
     IDBObjectStore& modernObjectStore() { return m_objectStore; }
 
-    void markAsDeleted(std::unique_ptr<IDBIndex>&&);
+    void markAsDeleted();
     bool isDeleted() const { return m_deleted; }
 
     virtual bool isModern() const override { return true; }
@@ -96,19 +96,9 @@
 
     bool m_deleted { false };
 
-    // Most of the time, an IDBObjectStore owns an IDBIndex through a std::unique_ptr.
-    // In that scenario, attempts to ref() the IDBIndex directly ref the IDBObjectStore, so it is okay to
-    // keep a raw reference to the IDBObjectStore because it will always outlive the IDBIndex.
+    // IDBIndex objects are always owned by their referencing IDBObjectStore.
+    // Indexes will never outlive ObjectStores so its okay to keep a raw C++ reference here.
     IDBObjectStore& m_objectStore;
-
-    // But when an IDBIndex is deleted from its IDBObjectStore that lifetime is no longer guaranteed.
-    // The IDBObjectStore no longer owns the IDBIndex, so the following needs to change:
-    // 1 - The IDBIndex must directly ref its IDBObjectStore to keep it alive.
-    // 2 - The IDBIndex becomes traditionally RefCounted.
-    // 2 - The IDBIndex holds its own std::unique_ptr, which it will clear out when its RefCount reaches 0.
-    RefPtr<IDBObjectStore> m_objectStoreRef;
-    unsigned m_refCount { 0 };
-    std::unique_ptr<IDBIndex> m_selfOwner;
 };
 
 } // namespace IDBClient

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp (196517 => 196518)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.cpp	2016-02-12 23:01:20 UTC (rev 196518)
@@ -567,8 +567,11 @@
 
     {
         Locker<Lock> locker(m_referencedIndexLock);
-        if (auto index = m_referencedIndexes.take(name))
-            index->markAsDeleted(WTFMove(index));
+        if (auto index = m_referencedIndexes.take(name)) {
+            index->markAsDeleted();
+            m_deletedIndexes.add(WTFMove(index));
+        }
+
     }
 
     m_transaction->deleteIndex(m_info.identifier(), name);

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h (196517 => 196518)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h	2016-02-12 22:44:22 UTC (rev 196517)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBObjectStoreImpl.h	2016-02-12 23:01:20 UTC (rev 196518)
@@ -117,6 +117,7 @@
 
     mutable Lock m_referencedIndexLock;
     HashMap<String, std::unique_ptr<IDBIndex>> m_referencedIndexes;
+    HashSet<std::unique_ptr<IDBIndex>> m_deletedIndexes;
 };
 
 } // namespace IDBClient
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to