Bug 618616 - 'IndexedDB: Make IDBObjectStore.get() accept a key range'. r=sicking, a=blocking.
authorBen Turner <bent.mozilla@gmail.com>
Wed, 15 Dec 2010 13:21:20 -0800
changeset 59272 0e45f2a9fccaad2cf9eaabf92575ba0fea021e9d
parent 59271 a1f2e2bb9a7a0a94236d8dc345232197bddb672c
child 59273 b4213fc83849a950918dab75f19f43baf8fef938
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerssicking, blocking
bugs618616
milestone2.0b9pre
Bug 618616 - 'IndexedDB: Make IDBObjectStore.get() accept a key range'. r=sicking, a=blocking.
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/test/test_getAll.html
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -929,17 +929,40 @@ IDBObjectStore::Get(nsIVariant* aKey,
 
   if (!mTransaction->IsOpen()) {
     return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
   }
 
   Key key;
   nsresult rv = GetKeyFromVariant(aKey, key);
   if (NS_FAILED(rv)) {
-    return rv;
+    // Check to see if this is a key range.
+    PRUint16 type;
+    rv = aKey->GetDataType(&type);
+    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
+
+    if (type != nsIDataType::VTYPE_INTERFACE &&
+        type != nsIDataType::VTYPE_INTERFACE_IS) {
+      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
+    }
+
+    // XXX I hate this API. Move to jsvals, stat.
+    nsID* iid;
+    nsCOMPtr<nsISupports> supports;
+    rv = aKey->GetAsInterface(&iid, getter_AddRefs(supports));
+    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
+
+    NS_Free(iid);
+
+    nsCOMPtr<nsIIDBKeyRange> keyRange = do_QueryInterface(supports);
+    if (!keyRange) {
+      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
+    }
+
+    return GetAll(keyRange, 0, 0, _retval);
   }
 
   if (key.IsUnset()) {
     return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
   }
 
   nsRefPtr<IDBRequest> request = GenerateRequest(this);
   NS_ENSURE_TRUE(request, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
--- a/dom/indexedDB/test/test_getAll.html
+++ b/dom/indexedDB/test/test_getAll.html
@@ -100,16 +100,29 @@
 
       is(event.result instanceof Array, true, "Got an array object");
       is(event.result.length, 4, "Correct length");
 
       for (let i in event.result) {
         is(event.result[i], values[parseInt(i) + 3], "Same value");
       }
 
+      // Get should take a key range also.
+      request = db.transaction("foo").objectStore("foo").get(keyRange);
+      request.onerror = errorHandler;
+      request.onsuccess = grabEventAndContinueHandler;
+      event = yield;
+
+      is(event.result instanceof Array, true, "Got an array object");
+      is(event.result.length, 4, "Correct length");
+
+      for (let i in event.result) {
+        is(event.result[i], values[parseInt(i) + 3], "Same value");
+      }
+
       keyRange = IDBKeyRange.bound(4, 7);
 
       request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);
       request.onerror = errorHandler;
       request.onsuccess = grabEventAndContinueHandler;
       event = yield;
 
       is(event.result instanceof Array, true, "Got an array object");