IDBKeyRange.h (3788B)
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/. */ 6 7 #ifndef mozilla_dom_idbkeyrange_h__ 8 #define mozilla_dom_idbkeyrange_h__ 9 10 #include "js/RootingAPI.h" 11 #include "js/Value.h" 12 #include "mozilla/dom/IndexedDatabaseManager.h" 13 #include "mozilla/dom/indexedDB/Key.h" 14 #include "nsCOMPtr.h" 15 #include "nsCycleCollectionParticipant.h" 16 #include "nsString.h" 17 18 class mozIStorageStatement; 19 20 namespace mozilla { 21 22 class ErrorResult; 23 24 namespace dom { 25 26 class GlobalObject; 27 28 namespace indexedDB { 29 class SerializedKeyRange; 30 } // namespace indexedDB 31 32 class IDBKeyRange { 33 protected: 34 indexedDB::Key mLower; 35 indexedDB::Key mUpper; 36 JS::Heap<JS::Value> mCachedLowerVal; 37 JS::Heap<JS::Value> mCachedUpperVal; 38 39 const bool mLowerOpen : 1; 40 const bool mUpperOpen : 1; 41 const bool mIsOnly : 1; 42 bool mHaveCachedLowerVal : 1; 43 bool mHaveCachedUpperVal : 1; 44 bool mRooted : 1; 45 46 public: 47 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(IDBKeyRange) 48 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(IDBKeyRange) 49 50 // aCx is allowed to be null, but only if aVal.isUndefined(). 51 static void FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal, 52 RefPtr<IDBKeyRange>* aKeyRange, ErrorResult& aRv); 53 54 [[nodiscard]] static RefPtr<IDBKeyRange> FromSerialized( 55 const indexedDB::SerializedKeyRange& aKeyRange); 56 57 [[nodiscard]] static RefPtr<IDBKeyRange> Only(const GlobalObject& aGlobal, 58 JS::Handle<JS::Value> aValue, 59 ErrorResult& aRv); 60 61 [[nodiscard]] static RefPtr<IDBKeyRange> LowerBound( 62 const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen, 63 ErrorResult& aRv); 64 65 [[nodiscard]] static RefPtr<IDBKeyRange> UpperBound( 66 const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen, 67 ErrorResult& aRv); 68 69 [[nodiscard]] static RefPtr<IDBKeyRange> Bound(const GlobalObject& aGlobal, 70 JS::Handle<JS::Value> aLower, 71 JS::Handle<JS::Value> aUpper, 72 bool aLowerOpen, 73 bool aUpperOpen, 74 ErrorResult& aRv); 75 76 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBKeyRange); } 77 78 void ToSerialized(indexedDB::SerializedKeyRange& aKeyRange) const; 79 80 const indexedDB::Key& Lower() const { return mLower; } 81 82 indexedDB::Key& Lower() { return mLower; } 83 84 const indexedDB::Key& Upper() const { return mIsOnly ? mLower : mUpper; } 85 86 indexedDB::Key& Upper() { return mIsOnly ? mLower : mUpper; } 87 88 bool Includes(JSContext* aCx, JS::Handle<JS::Value> aValue, 89 ErrorResult& aRv) const; 90 91 bool IsOnly() const { return mIsOnly; } 92 93 void DropJSObjects(); 94 95 // WebIDL 96 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, 97 JS::MutableHandle<JSObject*> aReflector); 98 99 void GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 100 ErrorResult& aRv); 101 102 void GetUpper(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 103 ErrorResult& aRv); 104 105 bool LowerOpen() const { return mLowerOpen; } 106 107 bool UpperOpen() const { return mUpperOpen; } 108 109 protected: 110 IDBKeyRange(bool aLowerOpen, bool aUpperOpen, bool aIsOnly); 111 112 virtual ~IDBKeyRange(); 113 }; 114 115 } // namespace dom 116 } // namespace mozilla 117 118 #endif // mozilla_dom_idbkeyrange_h__