Bug 618616 - 'IndexedDB: Make IDBObjectStore.get() accept a key range'. r=sicking, a=blocking.

This commit is contained in:
Ben Turner 2010-12-15 13:21:20 -08:00
Родитель 88e75c321c
Коммит 4bc2fd98ac
2 изменённых файлов: 37 добавлений и 1 удалений

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

@ -934,7 +934,30 @@ IDBObjectStore::Get(nsIVariant* aKey,
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()) {

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

@ -105,6 +105,19 @@
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);