Title: [105137] trunk
Revision
105137
Author
[email protected]
Date
2012-01-17 02:51:55 -0800 (Tue, 17 Jan 2012)

Log Message

IndexedDB: IDBIndex.get/getKey should yield undefined, not an error
https://bugs.webkit.org/show_bug.cgi?id=76116

Source/WebCore:

Pass an undefined value (for IDBIndex.get()) or a null key
(for IDBIndex.getKey()) back as the result, rather than raising
an exception.

Reviewed by Adam Barth.

Tests: storage/indexeddb/index-basics.html
       storage/indexeddb/cursor-index-delete.html
       storage/indexeddb/duplicates.html

* storage/IDBIndexBackendImpl.cpp:
(WebCore::IDBIndexBackendImpl::getInternal):
* storage/IDBRequest.cpp:
(WebCore::IDBRequest::onSuccess):

LayoutTests:

Reviewed by Adam Barth.

* storage/indexeddb/cursor-index-delete-expected.txt:
* storage/indexeddb/cursor-index-delete.html:
* storage/indexeddb/duplicates-expected.txt:
* storage/indexeddb/duplicates.html:
* storage/indexeddb/index-basics-expected.txt:
* storage/indexeddb/index-basics.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (105136 => 105137)


--- trunk/LayoutTests/ChangeLog	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/ChangeLog	2012-01-17 10:51:55 UTC (rev 105137)
@@ -1,3 +1,17 @@
+2012-01-17  Joshua Bell  <[email protected]>
+
+        IndexedDB: IDBIndex.get/getKey should yield undefined, not an error
+        https://bugs.webkit.org/show_bug.cgi?id=76116
+
+        Reviewed by Adam Barth.
+
+        * storage/indexeddb/cursor-index-delete-expected.txt:
+        * storage/indexeddb/cursor-index-delete.html:
+        * storage/indexeddb/duplicates-expected.txt:
+        * storage/indexeddb/duplicates.html:
+        * storage/indexeddb/index-basics-expected.txt:
+        * storage/indexeddb/index-basics.html:
+
 2012-01-17  Philippe Normand  <[email protected]>
 
         Unreviewed, GTK rebaseline after r105129.

Modified: trunk/LayoutTests/storage/indexeddb/cursor-index-delete-expected.txt (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/cursor-index-delete-expected.txt	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/cursor-index-delete-expected.txt	2012-01-17 10:51:55 UTC (rev 105137)
@@ -43,7 +43,7 @@
 PASS [object IDBCursorWithValue] is non-null.
 event.target.result.delete()
 index.get(1)
-event.preventDefault()
+PASS event.target.result is undefined
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/storage/indexeddb/cursor-index-delete.html (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/cursor-index-delete.html	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/cursor-index-delete.html	2012-01-17 10:51:55 UTC (rev 105137)
@@ -104,13 +104,13 @@
     shouldBeNonNull(event.target.result);
     evalAndLog("event.target.result.delete()");
     request = evalAndLog("index.get(1)");
-    request._onsuccess_ = unexpectedSuccessCallback;
-    request._onerror_ = verifyObjectDeleted;
+    request._onsuccess_ = verifyObjectDeleted;
+    request._onerror_ = unexpectedErrorCallback;
 }
 
 function verifyObjectDeleted()
 {
-    evalAndLog("event.preventDefault()");
+    shouldBe("event.target.result", "undefined");
     done();
 }
 

Modified: trunk/LayoutTests/storage/indexeddb/duplicates-expected.txt (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/duplicates-expected.txt	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/duplicates-expected.txt	2012-01-17 10:51:55 UTC (rev 105137)
@@ -20,11 +20,9 @@
 PASS event.target.result.x is "value"
 PASS event.target.result.y is "zzz"
 indexObject.getKey('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject.get('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject.openKeyCursor()
 PASS event.target.result === null is false
 PASS event.target.result.key is "value"
@@ -64,11 +62,9 @@
 PASS event.target.result.x is "value"
 PASS event.target.result.y is "zzz"
 indexObject.getKey('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject.get('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject.openKeyCursor()
 PASS event.target.result === null is false
 PASS event.target.result.key is "value"

Modified: trunk/LayoutTests/storage/indexeddb/duplicates.html (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/duplicates.html	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/duplicates.html	2012-01-17 10:51:55 UTC (rev 105137)
@@ -82,27 +82,23 @@
     shouldBeEqualToString("event.target.result.y", "zzz");
 
     request = evalAndLog("indexObject.getKey('does not exist')");
-    request._onsuccess_ = unexpectedSuccessCallback;
-    request._onerror_ = getObjectDataFail;
+    request._onsuccess_ = getObjectDataFail;
+    request._onerror_ = unexpectedErrorCallback;
 }
 
 function getObjectDataFail()
 {
-    shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
+    shouldBe("event.target.result", "undefined");
 
-    evalAndLog("event.preventDefault()");
-
     request = evalAndLog("indexObject.get('does not exist')");
-    request._onsuccess_ = unexpectedSuccessCallback;
-    request._onerror_ = openKeyCursor;
+    request._onsuccess_ = openKeyCursor;
+    request._onerror_ = unexpectedErrorCallback;
 }
 
 function openKeyCursor()
 {
-    shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
+    shouldBe("event.target.result", "undefined");
 
-    evalAndLog("event.preventDefault()");
-
     window.request = evalAndLog("indexObject.openKeyCursor()");
     request._onsuccess_ = cursor1Continue;
     request._onerror_ = unexpectedErrorCallback;

Modified: trunk/LayoutTests/storage/indexeddb/index-basics-expected.txt (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/index-basics-expected.txt	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/index-basics-expected.txt	2012-01-17 10:51:55 UTC (rev 105137)
@@ -49,11 +49,9 @@
 PASS event.target.result.x is "value"
 PASS event.target.result.y is "zzz"
 indexObject.getKey('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject.get('does not exist')
-PASS event.target.errorCode is webkitIDBDatabaseException.NOT_FOUND_ERR
-event.preventDefault()
+PASS event.target.result is undefined
 indexObject4.getKey('value2')
 PASS event.target.result is "key2"
 indexObject.openKeyCursor()

Modified: trunk/LayoutTests/storage/indexeddb/index-basics.html (105136 => 105137)


--- trunk/LayoutTests/storage/indexeddb/index-basics.html	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/LayoutTests/storage/indexeddb/index-basics.html	2012-01-17 10:51:55 UTC (rev 105137)
@@ -9,7 +9,7 @@
 <script>
 
 description("Test the basics of IndexedDB's webkitIDBIndex.");
-if (window.layoutTestController) 
+if (window.layoutTestController)
     layoutTestController.waitUntilDone();
 
 function test()
@@ -129,25 +129,22 @@
     shouldBeEqualToString("event.target.result.y", "zzz");
 
     request = evalAndLog("indexObject.getKey('does not exist')");
-    request._onsuccess_ = unexpectedSuccessCallback;
-    request._onerror_ = getObjectDataFail;
+    request._onsuccess_ = getObjectDataFail;
+    request._onerror_ = unexpectedSuccessCallback;
 }
 
 function getObjectDataFail()
 {
-    shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
+    shouldBe("event.target.result", "undefined");
 
-    evalAndLog("event.preventDefault()");
-
     request = evalAndLog("indexObject.get('does not exist')");
-    request._onsuccess_ = unexpectedSuccessCallback;
-    request._onerror_ = getObjectData4;
+    request._onsuccess_ = getObjectData4;
+    request._onerror_ = unexpectedSuccessCallback;
 }
 
 function getObjectData4()
 {
-    shouldBe("event.target.errorCode", "webkitIDBDatabaseException.NOT_FOUND_ERR");
-    evalAndLog("event.preventDefault()");
+    shouldBe("event.target.result", "undefined");
 
     request = evalAndLog("indexObject4.getKey('value2')");
     request._onsuccess_ = openKeyCursor;

Modified: trunk/Source/WebCore/ChangeLog (105136 => 105137)


--- trunk/Source/WebCore/ChangeLog	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/Source/WebCore/ChangeLog	2012-01-17 10:51:55 UTC (rev 105137)
@@ -1,3 +1,23 @@
+2012-01-17  Joshua Bell  <[email protected]>
+
+        IndexedDB: IDBIndex.get/getKey should yield undefined, not an error
+        https://bugs.webkit.org/show_bug.cgi?id=76116
+
+        Pass an undefined value (for IDBIndex.get()) or a null key
+        (for IDBIndex.getKey()) back as the result, rather than raising
+        an exception.
+
+        Reviewed by Adam Barth.
+
+        Tests: storage/indexeddb/index-basics.html
+               storage/indexeddb/cursor-index-delete.html
+               storage/indexeddb/duplicates.html
+
+        * storage/IDBIndexBackendImpl.cpp:
+        (WebCore::IDBIndexBackendImpl::getInternal):
+        * storage/IDBRequest.cpp:
+        (WebCore::IDBRequest::onSuccess):
+
 2012-01-17  Luke Macpherson   <[email protected]>
 
         Remove references to CSSPrimitiveValue::primitiveType().

Modified: trunk/Source/WebCore/storage/IDBIndexBackendImpl.cpp (105136 => 105137)


--- trunk/Source/WebCore/storage/IDBIndexBackendImpl.cpp	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/Source/WebCore/storage/IDBIndexBackendImpl.cpp	2012-01-17 10:51:55 UTC (rev 105137)
@@ -151,14 +151,14 @@
     if (getObject) {
         String value = index->m_backingStore->getObjectViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
         if (value.isNull()) {
-            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::NOT_FOUND_ERR, "Key does not exist in the index."));
+            callbacks->onSuccess(SerializedScriptValue::undefinedValue());
             return;
         }
         callbacks->onSuccess(SerializedScriptValue::createFromWire(value));
     } else {
         RefPtr<IDBKey> keyResult = index->m_backingStore->getPrimaryKeyViaIndex(index->m_databaseId, index->m_objectStoreBackend->id(), index->id(), *key);
         if (!keyResult) {
-            callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::NOT_FOUND_ERR, "Key does not exist in the index."));
+            callbacks->onSuccess(static_cast<IDBKey*>(0));
             return;
         }
         callbacks->onSuccess(keyResult.get());

Modified: trunk/Source/WebCore/storage/IDBRequest.cpp (105136 => 105137)


--- trunk/Source/WebCore/storage/IDBRequest.cpp	2012-01-17 10:49:20 UTC (rev 105136)
+++ trunk/Source/WebCore/storage/IDBRequest.cpp	2012-01-17 10:51:55 UTC (rev 105137)
@@ -231,7 +231,10 @@
 void IDBRequest::onSuccess(PassRefPtr<IDBKey> idbKey)
 {
     ASSERT(!m_errorCode && m_errorMessage.isNull() && !m_result);
-    m_result = IDBAny::create(idbKey);
+    if (idbKey && idbKey->valid())
+        m_result = IDBAny::create(idbKey);
+    else
+        m_result = IDBAny::create(SerializedScriptValue::undefinedValue());
     enqueueEvent(createSuccessEvent());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to