Bug 618139 - 'IndexedDB: Make delete() and get() not return an error event when the key does not exist'. r=sicking, a=blocking.

This commit is contained in:
Ben Turner 2010-12-15 13:21:09 -08:00
Родитель 0ffb50bf6b
Коммит dfd8298239
6 изменённых файлов: 32 добавлений и 18 удалений

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

@ -428,11 +428,12 @@ AsyncConnectionHelper::OnError(nsIDOMEventTarget* aTarget,
}
nsresult
AsyncConnectionHelper::GetSuccessResult(nsIWritableVariant* /* aResult */)
AsyncConnectionHelper::GetSuccessResult(nsIWritableVariant* aResult)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// Leave the variant remain set to empty.
nsresult rv = aResult->SetAsVoid();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

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

@ -1617,12 +1617,14 @@ GetHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
rv = stmt->ExecuteStep(&hasResult);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
if (!hasResult) {
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
if (hasResult) {
// Set the value based on results.
rv = stmt->GetString(0, mValue);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
else {
mValue.SetIsVoid(PR_TRUE);
}
// Set the value based on results.
(void)stmt->GetString(0, mValue);
return NS_OK;
}
@ -1630,6 +1632,11 @@ GetHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
nsresult
GetHelper::OnSuccess(nsIDOMEventTarget* aTarget)
{
if (mValue.IsVoid()) {
// Default is to have an undefined result.
return AsyncConnectionHelper::OnSuccess(aTarget);
}
nsRefPtr<GetSuccessEvent> event(new GetSuccessEvent(mValue));
nsresult rv = event->Init(mRequest, mTransaction);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);

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

@ -80,7 +80,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
ok(event.result === null, "Correct event.result");
ok(event.result === undefined, "Correct event.result");
request = db.transaction("foo").objectStore("foo").openCursor();
request.onerror = errorHandler;

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

@ -314,10 +314,12 @@
is(gotRemoveEvent, true, "Saw the remove event");
request = objectStore.get(sortedKeys[4]);
request.onerror = new ExpectError(IDBDatabaseException.NOT_FOUND_ERR);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, undefined, "Entry was deleted");
request = objectStore.add("foo", sortedKeys[4]);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;

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

@ -87,9 +87,11 @@ function testSteps()
// Make sure it was removed.
request = objectStore.get(id);
request.onerror = new ExpectError(IDBDatabaseException.NOT_FOUND_ERR);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
ok(event.result === undefined, "Object was deleted");
}
finishTest();

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

@ -21,8 +21,6 @@
const READ_WRITE = Ci.nsIIDBTransaction.READ_WRITE;
const VERSION_CHANGE = Ci.nsIIDBTransaction.VERSION_CHANGE;
const NOT_FOUND_ERR = Ci.nsIIDBDatabaseException.NOT_FOUND_ERR;
const name = window.location.pathname;
const description = "My Test Database";
@ -199,10 +197,12 @@
is(event.type, "abort", "Right kind of event");
request = db.transaction("foo").objectStore("foo").get(key);
request.onerror = new ExpectError(NOT_FOUND_ERR);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, undefined, "Object was removed");
SimpleTest.executeSoon(function() { testGenerator.next(); });
yield;
@ -228,9 +228,11 @@
for (let i = 0; i < 10; i++) {
request = db.transaction("foo").objectStore("foo").get(keys[i]);
request.onerror = new ExpectError(NOT_FOUND_ERR);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, undefined, "Object was removed");
}
finishTest();