Bug 598108 - 'IndexedDB: Remove IDBDatabase.objectStore()'. r=sicking

This commit is contained in:
Ben Turner 2010-10-19 10:58:49 -07:00
Родитель 88b443f419
Коммит 93e25b0573
14 изменённых файлов: 54 добавлений и 94 удалений

Просмотреть файл

@ -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<nsString> storesToOpen;
if (!storesToOpen.AppendElement(aName)) {
NS_ERROR("Out of memory?");
return NS_ERROR_OUT_OF_MEMORY;
}
nsRefPtr<IDBTransaction> 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)
{

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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");

Просмотреть файл

@ -102,7 +102,8 @@
}
yield;
objectStore = db.objectStore(objectStoreName);
objectStore = db.transaction(objectStoreName)
.objectStore(objectStoreName);
request = objectStore.index("height").getAll(65);
request.onerror = errorHandler;

Просмотреть файл

@ -102,7 +102,8 @@
}
yield;
objectStore = db.objectStore(objectStoreName);
objectStore = db.transaction(objectStoreName)
.objectStore(objectStoreName);
request = objectStore.index("height").getAllObjects(65);
request.onerror = errorHandler;

Просмотреть файл

@ -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);

Просмотреть файл

@ -104,7 +104,8 @@
}
yield;
objectStore = db.objectStore(objectStoreName);
objectStore = db.transaction(objectStoreName)
.objectStore(objectStoreName);
let keyIndex = 0;

Просмотреть файл

@ -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();

Просмотреть файл

@ -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");

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;