Bug 1910110 - Return early when channel URI is void r=rpl a=Aryx
[gecko.git] / dom / indexedDB / IDBKeyRange.h
blobdd73fb94211d4516fb5acc573b567f5d3e22c8ee
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"
11 #include "js/Value.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/IndexedDatabaseManager.h"
14 #include "mozilla/dom/indexedDB/Key.h"
15 #include "nsCOMPtr.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupports.h"
18 #include "nsString.h"
20 class mozIStorageStatement;
22 namespace mozilla {
24 class ErrorResult;
26 namespace dom {
28 class GlobalObject;
30 namespace indexedDB {
31 class SerializedKeyRange;
32 } // namespace indexedDB
34 class IDBKeyRange : public nsISupports {
35 protected:
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;
47 bool mRooted : 1;
49 public:
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,
62 ErrorResult& aRv);
64 [[nodiscard]] static RefPtr<IDBKeyRange> LowerBound(
65 const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
66 ErrorResult& aRv);
68 [[nodiscard]] static RefPtr<IDBKeyRange> UpperBound(
69 const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
70 ErrorResult& aRv);
72 [[nodiscard]] static RefPtr<IDBKeyRange> Bound(const GlobalObject& aGlobal,
73 JS::Handle<JS::Value> aLower,
74 JS::Handle<JS::Value> aUpper,
75 bool aLowerOpen,
76 bool aUpperOpen,
77 ErrorResult& aRv);
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; }
96 void DropJSObjects();
98 // WebIDL
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,
105 ErrorResult& aRv);
107 void GetUpper(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
108 ErrorResult& aRv);
110 bool LowerOpen() const { return mLowerOpen; }
112 bool UpperOpen() const { return mUpperOpen; }
114 protected:
115 IDBKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen,
116 bool aIsOnly);
118 virtual ~IDBKeyRange();
121 } // namespace dom
122 } // namespace mozilla
124 #endif // mozilla_dom_idbkeyrange_h__