diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index 655fe7e87b1..1c30d6f8a41 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -499,6 +499,9 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName) NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); info->RemoveObjectStore(aName); + + transaction->ReleaseCachedObjectStore(aName); + return NS_OK; } diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index fd2ecacc364..400b32d2a3b 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -1550,6 +1550,14 @@ IDBObjectStore::DeleteIndex(const nsAString& aName) NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); info->indexes.RemoveElementAt(index); + + for (PRUint32 i = 0; i < mCreatedIndexes.Length(); i++) { + if (mCreatedIndexes[i]->Name() == aName) { + mCreatedIndexes.RemoveElementAt(i); + break; + } + } + return NS_OK; } diff --git a/dom/indexedDB/IDBTransaction.cpp b/dom/indexedDB/IDBTransaction.cpp index 8a999a87461..ef583148b2d 100644 --- a/dom/indexedDB/IDBTransaction.cpp +++ b/dom/indexedDB/IDBTransaction.cpp @@ -213,6 +213,17 @@ IDBTransaction::OnRequestFinished() } } +void +IDBTransaction::ReleaseCachedObjectStore(const nsAString& aName) +{ + for (PRUint32 i = 0; i < mCreatedObjectStores.Length(); i++) { + if (mCreatedObjectStores[i]->Name() == aName) { + mCreatedObjectStores.RemoveElementAt(i); + break; + } + } +} + void IDBTransaction::SetTransactionListener(IDBTransactionListener* aListener) { diff --git a/dom/indexedDB/IDBTransaction.h b/dom/indexedDB/IDBTransaction.h index 73f3b190b1b..0bb02c2a764 100644 --- a/dom/indexedDB/IDBTransaction.h +++ b/dom/indexedDB/IDBTransaction.h @@ -103,6 +103,8 @@ public: void OnNewRequest(); void OnRequestFinished(); + void ReleaseCachedObjectStore(const nsAString& aName); + void SetTransactionListener(IDBTransactionListener* aListener); bool StartSavepoint(); diff --git a/dom/indexedDB/test/test_remove_index.html b/dom/indexedDB/test/test_remove_index.html index 6515918205f..c7549f3f26e 100644 --- a/dom/indexedDB/test/test_remove_index.html +++ b/dom/indexedDB/test/test_remove_index.html @@ -32,14 +32,30 @@ is(objectStore.indexNames.length, 0, "Correct indexNames list"); - objectStore.createIndex(indexName, "foo"); + let index = objectStore.createIndex(indexName, "foo"); is(objectStore.indexNames.length, 1, "Correct indexNames list"); is(objectStore.indexNames.item(0), indexName, "Correct name"); + is(objectStore.index(indexName), index, "Correct instance"); objectStore.deleteIndex(indexName); is(objectStore.indexNames.length, 0, "Correct indexNames list"); + try { + objectStore.index(indexName); + ok(false, "should have thrown"); + } + catch(ex) { + ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException"); + is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR"); + } + + let index2 = objectStore.createIndex(indexName, "foo"); + isnot(index, index2, "New instance should be created"); + + is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list"); + is(objectStore.indexNames.item(0), indexName, "Correct recreacted name"); + is(objectStore.index(indexName), index2, "Correct instance"); finishTest(); yield; diff --git a/dom/indexedDB/test/test_remove_objectStore.html b/dom/indexedDB/test/test_remove_objectStore.html index eca99428d29..78afa3c5387 100644 --- a/dom/indexedDB/test/test_remove_objectStore.html +++ b/dom/indexedDB/test/test_remove_objectStore.html @@ -55,13 +55,26 @@ let event = yield; let db = event.target.result; + let trans = event.target.transaction; - db.deleteObjectStore(objectStore.name); + let oldObjectStore = trans.objectStore(objectStoreName); + isnot(oldObjectStore, null, "Correct object store prior to deleting"); + db.deleteObjectStore(objectStoreName); is(db.objectStoreNames.length, 0, "Correct objectStores list"); + try { + trans.objectStore(objectStoreName); + ok(false, "should have thrown"); + } + catch(ex) { + ok(ex instanceof IDBDatabaseException, "Got a IDBDatabaseException"); + is(ex.code, IDBDatabaseException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR"); + } objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" }); is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); is(db.objectStoreNames.item(0), objectStoreName, "Correct name"); + is(trans.objectStore(objectStoreName), objectStore, "Correct new objectStore"); + isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore"); request = objectStore.openCursor(); request.onerror = errorHandler;