From 3e5b1fa7454a033a0491160247ef32a6a2b11dcb Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Tue, 19 Oct 2010 10:58:49 -0700 Subject: [PATCH] Bug 598108 - 'IndexedDB: Remove IDBDatabase.objectStore()'. r=sicking --- dom/indexedDB/IDBDatabase.cpp | 51 ------------------- dom/indexedDB/nsIIDBDatabase.idl | 7 +-- dom/indexedDB/test/test_clear.html | 10 ++-- dom/indexedDB/test/test_getAll.html | 16 +++--- dom/indexedDB/test/test_global_data.html | 3 +- dom/indexedDB/test/test_index_getAll.html | 3 +- .../test/test_index_getAllObjects.html | 3 +- dom/indexedDB/test/test_indexes.html | 6 ++- .../test/test_indexes_bad_values.html | 3 +- dom/indexedDB/test/test_objectCursors.html | 3 +- dom/indexedDB/test/test_open_objectStore.html | 3 +- .../test/test_readonly_transactions.html | 22 +++++--- .../test/test_transaction_abort.html | 10 ++-- .../test/test_writer_starvation.html | 8 +-- 14 files changed, 54 insertions(+), 94 deletions(-) diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index b547903c0a5..48ea6693e16 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -737,57 +737,6 @@ IDBDatabase::Transaction(nsIVariant* aStoreNames, return NS_OK; } -NS_IMETHODIMP -IDBDatabase::ObjectStore(const nsAString& aName, - PRUint16 aMode, - JSContext* aCx, - PRUint8 aOptionalArgCount, - nsIIDBObjectStore** _retval) -{ - NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - - if (aName.IsEmpty()) { - return NS_ERROR_INVALID_ARG; - } - - if (aOptionalArgCount) { - if (aMode != nsIIDBTransaction::READ_WRITE && - aMode != nsIIDBTransaction::READ_ONLY && - aMode != nsIIDBTransaction::SNAPSHOT_READ) { - return NS_ERROR_INVALID_ARG; - } - } - else { - aMode = nsIIDBTransaction::READ_ONLY; - } - - DatabaseInfo* info; - if (!DatabaseInfo::Get(mDatabaseId, &info)) { - NS_ERROR("This should never fail!"); - return NS_ERROR_UNEXPECTED; - } - - if (!info->ContainsStoreName(aName)) { - return NS_ERROR_NOT_AVAILABLE; - } - - nsTArray storesToOpen; - if (!storesToOpen.AppendElement(aName)) { - NS_ERROR("Out of memory?"); - return NS_ERROR_OUT_OF_MEMORY; - } - - nsRefPtr transaction = - IDBTransaction::Create(this, storesToOpen, aMode, - kDefaultDatabaseTimeoutSeconds); - NS_ENSURE_TRUE(transaction, NS_ERROR_FAILURE); - - nsresult rv = transaction->ObjectStore(aName, _retval); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - PRUint16 SetVersionHelper::DoDatabaseWork(mozIStorageConnection* aConnection) { diff --git a/dom/indexedDB/nsIIDBDatabase.idl b/dom/indexedDB/nsIIDBDatabase.idl index 17f831f8512..26f22614183 100644 --- a/dom/indexedDB/nsIIDBDatabase.idl +++ b/dom/indexedDB/nsIIDBDatabase.idl @@ -54,7 +54,7 @@ interface nsIDOMDOMStringList; * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase * for more information. */ -[scriptable, uuid(e258ad44-3306-427f-ac17-c528060c661a)] +[scriptable, uuid(c6255028-c807-4f1e-817f-e4a23638368b)] interface nsIIDBDatabase : nsISupports { readonly attribute DOMString name; @@ -84,9 +84,4 @@ interface nsIIDBDatabase : nsISupports transaction(in nsIVariant storeNames, // js array of strings [optional /* READ_ONLY */] in unsigned short mode, [optional /* 5000ms */] in unsigned long timeout); - - [optional_argc, implicit_jscontext] - nsIIDBObjectStore - objectStore(in AString name, - [optional /* READ_ONLY */] in unsigned short mode); }; diff --git a/dom/indexedDB/test/test_clear.html b/dom/indexedDB/test/test_clear.html index f5a1e393024..6a0e914307f 100644 --- a/dom/indexedDB/test/test_clear.html +++ b/dom/indexedDB/test/test_clear.html @@ -51,7 +51,7 @@ let seenEntryCount = 0; - request = db.objectStore("foo").openCursor(); + request = db.transaction("foo").objectStore("foo").openCursor(); request.onerror = errorHandler; request.onsuccess = function(event) { let cursor = event.result; @@ -68,21 +68,21 @@ is(seenEntryCount, entryCount, "Correct entry count"); try { - db.objectStore("foo").clear(); + db.transaction("foo").objectStore("foo").clear(); ok(false, "clear should throw on READ_ONLY transactions"); } catch (e) { ok(true, "clear should throw on READ_ONLY transactions"); } - request = db.objectStore("foo", READ_WRITE).clear(); + request = db.transaction("foo", READ_WRITE).objectStore("foo").clear(); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; ok(event.result === null, "Correct event.result"); - request = db.objectStore("foo").openCursor(); + request = db.transaction("foo").objectStore("foo").openCursor(); request.onerror = errorHandler; request.onsuccess = function(event) { let cursor = event.result; @@ -93,7 +93,7 @@ } yield; - request = db.objectStore("foo", READ_WRITE).add({}); + request = db.transaction("foo", READ_WRITE).objectStore("foo").add({}); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; diff --git a/dom/indexedDB/test/test_getAll.html b/dom/indexedDB/test/test_getAll.html index fdc1cd4ae1e..89e6adfc23c 100644 --- a/dom/indexedDB/test/test_getAll.html +++ b/dom/indexedDB/test/test_getAll.html @@ -53,7 +53,7 @@ } yield; - request = db.objectStore("foo").getAll(); + request = db.transaction("foo").objectStore("foo").getAll(); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -65,7 +65,7 @@ is(event.result[i], values[i], "Same value"); } - request = db.objectStore("foo").getAll(null, 5); + request = db.transaction("foo").objectStore("foo").getAll(null, 5); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -79,7 +79,7 @@ let keyRange = moz_indexedDB.makeBoundKeyRange(1, 9); - request = db.objectStore("foo").getAll(keyRange); + request = db.transaction("foo").objectStore("foo").getAll(keyRange); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -93,7 +93,7 @@ keyRange = moz_indexedDB.makeBoundKeyRange(4, 7); - request = db.objectStore("foo").getAll(keyRange); + request = db.transaction("foo").objectStore("foo").getAll(keyRange); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -107,7 +107,7 @@ keyRange = moz_indexedDB.makeBoundKeyRange(4, 7); - request = db.objectStore("foo").getAll(keyRange, 2); + request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -121,7 +121,7 @@ keyRange = moz_indexedDB.makeBoundKeyRange(4, 7); - request = db.objectStore("foo").getAll(keyRange, 50); + request = db.transaction("foo").objectStore("foo").getAll(keyRange, 50); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -135,7 +135,7 @@ keyRange = moz_indexedDB.makeBoundKeyRange(4, 7); - request = db.objectStore("foo").getAll(keyRange, 0); + request = db.transaction("foo").objectStore("foo").getAll(keyRange, 0); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -145,7 +145,7 @@ keyRange = moz_indexedDB.makeBoundKeyRange(4, 7, true, true); - request = db.objectStore("foo").getAll(keyRange); + request = db.transaction("foo").objectStore("foo").getAll(keyRange); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; diff --git a/dom/indexedDB/test/test_global_data.html b/dom/indexedDB/test/test_global_data.html index 753c1630af1..aff224a718d 100644 --- a/dom/indexedDB/test/test_global_data.html +++ b/dom/indexedDB/test/test_global_data.html @@ -55,7 +55,8 @@ is(objectStore1.autoIncrement, objectStore.autoIncrement, "Same value for autoIncrement"); - let objectStore2 = db1.objectStore(objectStore.name); + let objectStore2 = db1.transaction(objectStore.name) + .objectStore(objectStore.name); ok(objectStore1 !== objectStore2, "Different objectStores"); is(objectStore1.name, objectStore2.name, "Same name"); diff --git a/dom/indexedDB/test/test_index_getAll.html b/dom/indexedDB/test/test_index_getAll.html index 65e69af9993..cf92e4d9d64 100644 --- a/dom/indexedDB/test/test_index_getAll.html +++ b/dom/indexedDB/test/test_index_getAll.html @@ -102,7 +102,8 @@ } yield; - objectStore = db.objectStore(objectStoreName); + objectStore = db.transaction(objectStoreName) + .objectStore(objectStoreName); request = objectStore.index("height").getAll(65); request.onerror = errorHandler; diff --git a/dom/indexedDB/test/test_index_getAllObjects.html b/dom/indexedDB/test/test_index_getAllObjects.html index f060054b194..f8b2e8b6aaf 100644 --- a/dom/indexedDB/test/test_index_getAllObjects.html +++ b/dom/indexedDB/test/test_index_getAllObjects.html @@ -102,7 +102,8 @@ } yield; - objectStore = db.objectStore(objectStoreName); + objectStore = db.transaction(objectStoreName) + .objectStore(objectStoreName); request = objectStore.index("height").getAllObjects(65); request.onerror = errorHandler; diff --git a/dom/indexedDB/test/test_indexes.html b/dom/indexedDB/test/test_indexes.html index e6f152bffd1..51f4d12101c 100644 --- a/dom/indexedDB/test/test_indexes.html +++ b/dom/indexedDB/test/test_indexes.html @@ -113,7 +113,8 @@ } yield; - objectStore = db.objectStore(objectStoreName); + objectStore = db.transaction(objectStoreName) + .objectStore(objectStoreName); // Check global properties to make sure they are correct. is(objectStore.indexNames.length, indexData.length, "Good index count"); @@ -210,7 +211,8 @@ is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys"); // Check that the name index enforces its unique constraint. - objectStore = db.objectStore(objectStoreName, READ_WRITE); + objectStore = db.transaction(objectStoreName, READ_WRITE) + .objectStore(objectStoreName); request = objectStore.add({ name: "Bob", height: 62, weight: 170 }, "237-23-7738"); request.onerror = new ExpectError(CONSTRAINT_ERR); diff --git a/dom/indexedDB/test/test_indexes_bad_values.html b/dom/indexedDB/test/test_indexes_bad_values.html index 0babfc4b249..51bd340a194 100644 --- a/dom/indexedDB/test/test_indexes_bad_values.html +++ b/dom/indexedDB/test/test_indexes_bad_values.html @@ -104,7 +104,8 @@ } yield; - objectStore = db.objectStore(objectStoreName); + objectStore = db.transaction(objectStoreName) + .objectStore(objectStoreName); let keyIndex = 0; diff --git a/dom/indexedDB/test/test_objectCursors.html b/dom/indexedDB/test/test_objectCursors.html index 0df7b3a2966..11a95140c8b 100644 --- a/dom/indexedDB/test/test_objectCursors.html +++ b/dom/indexedDB/test/test_objectCursors.html @@ -70,7 +70,8 @@ for (let i in objectStores) { for (let j in indexes) { - let objectStore = db.objectStore(objectStores[i].name); + let objectStore = db.transaction(objectStores[i].name) + .objectStore(objectStores[i].name); let index = objectStore.index(indexes[j].name); request = index.openObjectCursor(); diff --git a/dom/indexedDB/test/test_open_objectStore.html b/dom/indexedDB/test/test_open_objectStore.html index c2487e7f4f3..45b5554443a 100644 --- a/dom/indexedDB/test/test_open_objectStore.html +++ b/dom/indexedDB/test/test_open_objectStore.html @@ -39,7 +39,8 @@ is(db.objectStoreNames.length, 1, "Bad objectStores list"); is(db.objectStoreNames.item(0), objectStoreName, "Bad name"); - let objectStore = db.objectStore(objectStoreName); + let objectStore = db.transaction(objectStoreName) + .objectStore(objectStoreName); is(objectStore.name, objectStoreName, "Bad name"); is(objectStore.mode, nsIIDBObjectStore.READ_ONLY, "Bad mode"); is(objectStore.keyPath, "foo", "Bad keyPath"); diff --git a/dom/indexedDB/test/test_readonly_transactions.html b/dom/indexedDB/test/test_readonly_transactions.html index 5440b685d6e..d0793625b10 100644 --- a/dom/indexedDB/test/test_readonly_transactions.html +++ b/dom/indexedDB/test/test_readonly_transactions.html @@ -49,7 +49,7 @@ } yield; - request = db.objectStore(osName, READ_WRITE).add({}); + request = db.transaction(osName, READ_WRITE).objectStore(osName).add({}); request.onerror = errorHandler; request.onsuccess = function(event) { is(event.transaction.mode, READ_WRITE, "Correct mode"); @@ -68,7 +68,9 @@ } yield; - request = db.objectStore(osName, READ_WRITE).put({}, key2); + request = db.transaction(osName, READ_WRITE) + .objectStore(osName) + .put({}, key2); request.onerror = errorHandler; request.onsuccess = function(event) { is(event.transaction.mode, READ_WRITE, "Correct mode"); @@ -86,7 +88,9 @@ } yield; - request = db.objectStore(osName, READ_WRITE).put({}, key1); + request = db.transaction(osName, READ_WRITE) + .objectStore(osName) + .put({}, key1); request.onerror = errorHandler; request.onsuccess = function(event) { is(event.transaction.mode, READ_WRITE, "Correct mode"); @@ -104,7 +108,9 @@ } yield; - request = db.objectStore(osName, READ_WRITE).remove(key2); + request = db.transaction(osName, READ_WRITE) + .objectStore(osName) + .remove(key2); request.onerror = errorHandler; request.onsuccess = function(event) { is(event.transaction.mode, READ_WRITE, "Correct mode"); @@ -121,7 +127,7 @@ } try { - request = db.objectStore(osName).add({}); + request = db.transaction(osName).objectStore(osName).add({}); ok(false, "Adding to a readonly transaction should fail!"); } catch (e) { @@ -137,7 +143,7 @@ } try { - request = db.objectStore(osName).put({}); + request = db.transaction(osName).objectStore(osName).put({}); ok(false, "Adding or modifying a readonly transaction should fail!"); } catch (e) { @@ -153,7 +159,7 @@ } try { - request = db.objectStore(osName).put({}, key1); + request = db.transaction(osName).objectStore(osName).put({}, key1); ok(false, "Modifying a readonly transaction should fail!"); } catch (e) { @@ -169,7 +175,7 @@ } try { - request = db.objectStore(osName).remove(key2); + request = db.transaction(osName).objectStore(osName).remove(key2); ok(false, "Removing from a readonly transaction should fail!"); } catch (e) { diff --git a/dom/indexedDB/test/test_transaction_abort.html b/dom/indexedDB/test/test_transaction_abort.html index 93cb7c39a3d..8ec15481ec1 100644 --- a/dom/indexedDB/test/test_transaction_abort.html +++ b/dom/indexedDB/test/test_transaction_abort.html @@ -162,7 +162,7 @@ ok(true, "RemoveIndex threw"); } - request = db.objectStore("foo", READ_WRITE).add({}); + request = db.transaction("foo", READ_WRITE).objectStore("foo").add({}); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -177,7 +177,7 @@ let key; - request = db.objectStore("foo", READ_WRITE).add({}); + request = db.transaction("foo", READ_WRITE).objectStore("foo").add({}); request.onerror = errorHandler; request.onsuccess = grabEventAndContinueHandler; event = yield; @@ -197,7 +197,7 @@ is(event.type, "abort", "Right kind of event"); - request = db.objectStore("foo").get(key); + request = db.transaction("foo").objectStore("foo").get(key); request.onerror = new ExpectError(NOT_FOUND_ERR); request.onsuccess = unexpectedSuccessHandler; event = yield; @@ -206,7 +206,7 @@ yield; let keys = []; - objectStore = db.objectStore("foo", READ_WRITE); + objectStore = db.transaction("foo", READ_WRITE).objectStore("foo"); for (let i = 0; i < 10; i++) { request = objectStore.add({}); @@ -226,7 +226,7 @@ is(keys.length, 10, "Not enough keys!"); for (let i = 0; i < 10; i++) { - request = db.objectStore("foo").get(keys[i]); + request = db.transaction("foo").objectStore("foo").get(keys[i]); request.onerror = new ExpectError(NOT_FOUND_ERR); request.onsuccess = unexpectedSuccessHandler; event = yield; diff --git a/dom/indexedDB/test/test_writer_starvation.html b/dom/indexedDB/test/test_writer_starvation.html index f4cc7def18d..d687c118392 100644 --- a/dom/indexedDB/test/test_writer_starvation.html +++ b/dom/indexedDB/test/test_writer_starvation.html @@ -53,7 +53,7 @@ // loop. for (let i = 0; i < 20; i++) { readerCount++; - request = db.objectStore("foo").get(key); + request = db.transaction("foo").objectStore("foo").get(key); request.onerror = errorHandler; request.onsuccess = function(event) { callbackCount++; @@ -62,13 +62,15 @@ while (continueReading) { readerCount++; - request = db.objectStore("foo").get(key); + request = db.transaction("foo").objectStore("foo").get(key); request.onerror = errorHandler; request.onsuccess = function(event) { is(event.transaction.mode, READ_ONLY, "Correct mode"); callbackCount++; if (callbackCount == 100) { - request = db.objectStore("foo", READ_WRITE).add({}, readerCount); + request = db.transaction("foo", READ_WRITE) + .objectStore("foo") + .add({}, readerCount); request.onerror = errorHandler; request.onsuccess = function(event) { continueReading = false;