1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_idbkeyrange_h__
8 #define mozilla_dom_idbkeyrange_h__
10 #include "js/RootingAPI.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/IndexedDatabaseManager.h"
14 #include "mozilla/dom/indexedDB/Key.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupports.h"
20 class mozIStorageStatement
;
31 class SerializedKeyRange
;
32 } // namespace indexedDB
34 class IDBKeyRange
: public nsISupports
{
36 nsCOMPtr
<nsISupports
> mGlobal
;
37 indexedDB::Key mLower
;
38 indexedDB::Key mUpper
;
39 JS::Heap
<JS::Value
> mCachedLowerVal
;
40 JS::Heap
<JS::Value
> mCachedUpperVal
;
42 const bool mLowerOpen
: 1;
43 const bool mUpperOpen
: 1;
44 const bool mIsOnly
: 1;
45 bool mHaveCachedLowerVal
: 1;
46 bool mHaveCachedUpperVal
: 1;
50 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange
)
53 // aCx is allowed to be null, but only if aVal.isUndefined().
54 static void FromJSVal(JSContext
* aCx
, JS::Handle
<JS::Value
> aVal
,
55 RefPtr
<IDBKeyRange
>* aKeyRange
, ErrorResult
& aRv
);
57 [[nodiscard
]] static RefPtr
<IDBKeyRange
> FromSerialized(
58 const indexedDB::SerializedKeyRange
& aKeyRange
);
60 [[nodiscard
]] static RefPtr
<IDBKeyRange
> Only(const GlobalObject
& aGlobal
,
61 JS::Handle
<JS::Value
> aValue
,
64 [[nodiscard
]] static RefPtr
<IDBKeyRange
> LowerBound(
65 const GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aValue
, bool aOpen
,
68 [[nodiscard
]] static RefPtr
<IDBKeyRange
> UpperBound(
69 const GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aValue
, bool aOpen
,
72 [[nodiscard
]] static RefPtr
<IDBKeyRange
> Bound(const GlobalObject
& aGlobal
,
73 JS::Handle
<JS::Value
> aLower
,
74 JS::Handle
<JS::Value
> aUpper
,
79 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBKeyRange
); }
81 void ToSerialized(indexedDB::SerializedKeyRange
& aKeyRange
) const;
83 const indexedDB::Key
& Lower() const { return mLower
; }
85 indexedDB::Key
& Lower() { return mLower
; }
87 const indexedDB::Key
& Upper() const { return mIsOnly
? mLower
: mUpper
; }
89 indexedDB::Key
& Upper() { return mIsOnly
? mLower
: mUpper
; }
91 bool Includes(JSContext
* aCx
, JS::Handle
<JS::Value
> aValue
,
92 ErrorResult
& aRv
) const;
94 bool IsOnly() const { return mIsOnly
; }
99 bool WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
,
100 JS::MutableHandle
<JSObject
*> aReflector
);
102 nsISupports
* GetParentObject() const { return mGlobal
; }
104 void GetLower(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
107 void GetUpper(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
110 bool LowerOpen() const { return mLowerOpen
; }
112 bool UpperOpen() const { return mUpperOpen
; }
115 IDBKeyRange(nsISupports
* aGlobal
, bool aLowerOpen
, bool aUpperOpen
,
118 virtual ~IDBKeyRange();
121 class IDBLocaleAwareKeyRange final
: public IDBKeyRange
{
122 IDBLocaleAwareKeyRange(nsISupports
* aGlobal
, bool aLowerOpen
, bool aUpperOpen
,
125 ~IDBLocaleAwareKeyRange();
128 [[nodiscard
]] static RefPtr
<IDBLocaleAwareKeyRange
> Bound(
129 const GlobalObject
& aGlobal
, JS::Handle
<JS::Value
> aLower
,
130 JS::Handle
<JS::Value
> aUpper
, bool aLowerOpen
, bool aUpperOpen
,
133 NS_INLINE_DECL_REFCOUNTING_INHERITED(IDBLocaleAwareKeyRange
, IDBKeyRange
)
136 bool WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
,
137 JS::MutableHandle
<JSObject
*> aReflector
);
141 } // namespace mozilla
143 #endif // mozilla_dom_idbkeyrange_h__