From 8abebec458ff72c2e940c5055fa9497068b68744 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 29 Mar 2012 23:09:09 +0200 Subject: [PATCH] Bug 738647 - DOMStorageImpl::GetKey shouldn't throw; r=honzab --- dom/interfaces/storage/nsIDOMStorage.idl | 3 +- dom/src/storage/nsDOMStorage.cpp | 9 ++-- .../localstorage/test_localStorageBase.html | 45 +++++++------------ .../test_localStorageBasePrivateBrowsing.html | 45 +++++++------------ .../test_localStorageBaseSessionOnly.html | 45 +++++++------------ .../test_sessionStorageBase.html | 45 +++++++------------ 6 files changed, 64 insertions(+), 128 deletions(-) diff --git a/dom/interfaces/storage/nsIDOMStorage.idl b/dom/interfaces/storage/nsIDOMStorage.idl index b09ebc3cff6..e393da6b783 100644 --- a/dom/interfaces/storage/nsIDOMStorage.idl +++ b/dom/interfaces/storage/nsIDOMStorage.idl @@ -64,8 +64,7 @@ interface nsIDOMStorage : nsISupports * Retrieve the name of the key at a particular index. * * @param index index of the item to retrieve - * @returns the key at index - * @throws INDEX_SIZE_ERR if there is no key at that index + * @returns the key at index, null if there is no key at that index */ DOMString key(in unsigned long index); diff --git a/dom/src/storage/nsDOMStorage.cpp b/dom/src/storage/nsDOMStorage.cpp index a116ca20865..116752d6ca1 100644 --- a/dom/src/storage/nsDOMStorage.cpp +++ b/dom/src/storage/nsDOMStorage.cpp @@ -1131,10 +1131,6 @@ IndexFinder(nsSessionStorageEntry* aEntry, void* userArg) nsresult DOMStorageImpl::GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey) { - // XXXjst: This is as retarded as the DOM spec is, takes an unsigned - // int, but the spec talks about what to do if a negative value is - // passed in. - // XXX: This does a linear search for the key at index, which would // suck if there's a large numer of indexes. Do we care? If so, // maybe we need to have a lazily populated key array here or @@ -1148,8 +1144,9 @@ DOMStorageImpl::GetKey(bool aCallerSecure, PRUint32 aIndex, nsAString& aKey) mItems.EnumerateEntries(IndexFinder, &data); if (!data.mItem) { - // aIndex was larger than the number of accessible keys. Throw. - return NS_ERROR_DOM_INDEX_SIZE_ERR; + // aIndex was larger than the number of accessible keys. Return null. + aKey.SetIsVoid(true); + return NS_OK; } aKey = data.mItem->GetKey(); diff --git a/dom/tests/mochitest/localstorage/test_localStorageBase.html b/dom/tests/mochitest/localstorage/test_localStorageBase.html index 630702755f7..11d86c79e5b 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageBase.html +++ b/dom/tests/mochitest/localstorage/test_localStorageBase.html @@ -7,28 +7,13 @@