From dfd8298239558f1aae998c3ddd38e646e9058247 Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Wed, 15 Dec 2010 13:21:09 -0800 Subject: [PATCH] Bug 618139 - 'IndexedDB: Make delete() and get() not return an error event when the key does not exist'. r=sicking, a=blocking. --- dom/indexedDB/AsyncConnectionHelper.cpp | 5 +++-- dom/indexedDB/IDBObjectStore.cpp | 17 ++++++++++++----- dom/indexedDB/test/test_clear.html | 2 +- dom/indexedDB/test/test_cursors.html | 6 ++++-- .../test/test_objectStore_remove_values.html | 6 ++++-- dom/indexedDB/test/test_transaction_abort.html | 14 ++++++++------ 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/dom/indexedDB/AsyncConnectionHelper.cpp b/dom/indexedDB/AsyncConnectionHelper.cpp index 1cb759bd12c..d0982dcf0ae 100644 --- a/dom/indexedDB/AsyncConnectionHelper.cpp +++ b/dom/indexedDB/AsyncConnectionHelper.cpp @@ -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; } diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 13762b20f7f..f0b2d7fff5d 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -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 event(new GetSuccessEvent(mValue)); nsresult rv = event->Init(mRequest, mTransaction); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); diff --git a/dom/indexedDB/test/test_clear.html b/dom/indexedDB/test/test_clear.html index 85748aaac73..1558a89ce95 100644 --- a/dom/indexedDB/test/test_clear.html +++ b/dom/indexedDB/test/test_clear.html @@ -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; diff --git a/dom/indexedDB/test/test_cursors.html b/dom/indexedDB/test/test_cursors.html index 3f484979e96..1b3a86a504c 100644 --- a/dom/indexedDB/test/test_cursors.html +++ b/dom/indexedDB/test/test_cursors.html @@ -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; diff --git a/dom/indexedDB/test/test_objectStore_remove_values.html b/dom/indexedDB/test/test_objectStore_remove_values.html index b36b15ff056..ad066c231f6 100644 --- a/dom/indexedDB/test/test_objectStore_remove_values.html +++ b/dom/indexedDB/test/test_objectStore_remove_values.html @@ -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(); diff --git a/dom/indexedDB/test/test_transaction_abort.html b/dom/indexedDB/test/test_transaction_abort.html index b3b5e3d2522..042e640323a 100644 --- a/dom/indexedDB/test/test_transaction_abort.html +++ b/dom/indexedDB/test/test_transaction_abort.html @@ -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();