From ef22731cc4f0dbbd3dcbe2973a4cb591fa4d3c93 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 26 Feb 2016 13:58:47 -0800 Subject: [PATCH] Bug 1251498: Implement IDBKeyRange.includes(). r=baku --- dom/indexedDB/IDBKeyRange.cpp | 49 +++++++++++++++++++ dom/indexedDB/IDBKeyRange.h | 5 ++ dom/indexedDB/Key.h | 2 +- dom/webidl/IDBKeyRange.webidl | 4 ++ testing/web-platform/meta/MANIFEST.json | 8 ++- .../web-platform/mozilla/meta/MANIFEST.json | 6 +++ .../tests/IndexedDB/idbkeyrange-includes.htm | 33 +++++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 testing/web-platform/tests/IndexedDB/idbkeyrange-includes.htm diff --git a/dom/indexedDB/IDBKeyRange.cpp b/dom/indexedDB/IDBKeyRange.cpp index 5aa2c2bc35f7..17562f4b5e31 100644 --- a/dom/indexedDB/IDBKeyRange.cpp +++ b/dom/indexedDB/IDBKeyRange.cpp @@ -334,6 +334,55 @@ IDBKeyRange::GetUpper(JSContext* aCx, JS::MutableHandle aResult, aResult.set(mCachedUpperVal); } +bool +IDBKeyRange::Includes(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) const +{ + Key key; + aRv = GetKeyFromJSVal(aCx, aValue, key); + if (aRv.Failed()) { + return false; + } + + switch (Key::CompareKeys(Lower(), key)) { + case 1: + return false; + case 0: + // Identical keys. + if (LowerOpen()) { + return false; + } + break; + case -1: + if (IsOnly()) { + return false; + } + break; + default: + MOZ_CRASH(); + } + + if (!IsOnly()) { + switch (Key::CompareKeys(key, Upper())) { + case 1: + return false; + case 0: + // Identical keys. + if (UpperOpen()) { + return false; + } + break; + case -1: + break; + } + } else { + MOZ_ASSERT(key == Lower()); + } + + return true; +} + // static already_AddRefed IDBKeyRange::Only(const GlobalObject& aGlobal, diff --git a/dom/indexedDB/IDBKeyRange.h b/dom/indexedDB/IDBKeyRange.h index 01bd2466a483..f94dc50781be 100644 --- a/dom/indexedDB/IDBKeyRange.h +++ b/dom/indexedDB/IDBKeyRange.h @@ -125,6 +125,11 @@ public: return mIsOnly ? mLower : mUpper; } + bool + Includes(JSContext* aCx, + JS::Handle aKey, + ErrorResult& aRv) const; + bool IsOnly() const { diff --git a/dom/indexedDB/Key.h b/dom/indexedDB/Key.h index 159c5c0beb57..2744dfb5d1a3 100644 --- a/dom/indexedDB/Key.h +++ b/dom/indexedDB/Key.h @@ -235,7 +235,7 @@ public: SetFromValueArray(mozIStorageValueArray* aValues, uint32_t aIndex); static int16_t - CompareKeys(Key& aFirst, Key& aSecond) + CompareKeys(const Key& aFirst, const Key& aSecond) { int32_t result = Compare(aFirst.mBuffer, aSecond.mBuffer); diff --git a/dom/webidl/IDBKeyRange.webidl b/dom/webidl/IDBKeyRange.webidl index ddf9f4469aa2..8bbb1e025f4a 100644 --- a/dom/webidl/IDBKeyRange.webidl +++ b/dom/webidl/IDBKeyRange.webidl @@ -19,6 +19,10 @@ interface IDBKeyRange { readonly attribute boolean lowerOpen; [Constant] readonly attribute boolean upperOpen; + [Throws] + boolean includes(any key); + + [NewObject, Throws] static IDBKeyRange only (any value); [NewObject, Throws] diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 53036e965492..4075580ffdca 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -33768,7 +33768,13 @@ { "path": "html/semantics/embedded-content/the-img-element/update-media.html", "url": "/html/semantics/embedded-content/the-img-element/update-media.html" - } + } + ], + "IndexedDB/idbkeyrange-includes.htm": [ + { + "path": "IndexedDB/idbkeyrange-includes.htm", + "url": "/IndexedDB/idbkeyrange-includes.htm" + } ] } }, diff --git a/testing/web-platform/mozilla/meta/MANIFEST.json b/testing/web-platform/mozilla/meta/MANIFEST.json index da83a8fb1e9b..3d2a6844eba0 100644 --- a/testing/web-platform/mozilla/meta/MANIFEST.json +++ b/testing/web-platform/mozilla/meta/MANIFEST.json @@ -218,6 +218,12 @@ "url": "/_mozilla/service-workers/service-worker/fetch-request-css-base-url.https.html" } ], + "service-workers/service-worker/fetch-request-css-images.https.html": [ + { + "path": "service-workers/service-worker/fetch-request-css-images.https.html", + "url": "/_mozilla/service-workers/service-worker/fetch-request-css-images.https.html" + } + ], "service-workers/service-worker/fetch-request-fallback.https.html": [ { "path": "service-workers/service-worker/fetch-request-fallback.https.html", diff --git a/testing/web-platform/tests/IndexedDB/idbkeyrange-includes.htm b/testing/web-platform/tests/IndexedDB/idbkeyrange-includes.htm new file mode 100644 index 000000000000..bfe9d2c482d6 --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbkeyrange-includes.htm @@ -0,0 +1,33 @@ + + + + + +