Source code

Revision control

Other Tools

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/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"
19
20
class mozIStorageStatement;
21
22
namespace mozilla {
23
24
class ErrorResult;
25
26
namespace dom {
27
28
class GlobalObject;
29
30
namespace indexedDB {
31
class SerializedKeyRange;
32
} // namespace indexedDB
33
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;
41
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;
48
49
public:
50
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
52
53
// aCx is allowed to be null, but only if aVal.isUndefined().
54
static void FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
55
IDBKeyRange** aKeyRange, ErrorResult& aRv);
56
57
static already_AddRefed<IDBKeyRange> FromSerialized(
58
const indexedDB::SerializedKeyRange& aKeyRange);
59
60
static already_AddRefed<IDBKeyRange> Only(const GlobalObject& aGlobal,
61
JS::Handle<JS::Value> aValue,
62
ErrorResult& aRv);
63
64
static already_AddRefed<IDBKeyRange> LowerBound(const GlobalObject& aGlobal,
65
JS::Handle<JS::Value> aValue,
66
bool aOpen, ErrorResult& aRv);
67
68
static already_AddRefed<IDBKeyRange> UpperBound(const GlobalObject& aGlobal,
69
JS::Handle<JS::Value> aValue,
70
bool aOpen, ErrorResult& aRv);
71
72
static already_AddRefed<IDBKeyRange> Bound(const GlobalObject& aGlobal,
73
JS::Handle<JS::Value> aLower,
74
JS::Handle<JS::Value> aUpper,
75
bool aLowerOpen, bool aUpperOpen,
76
ErrorResult& aRv);
77
78
void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBKeyRange); }
79
80
void ToSerialized(indexedDB::SerializedKeyRange& aKeyRange) const;
81
82
const indexedDB::Key& Lower() const { return mLower; }
83
84
indexedDB::Key& Lower() { return mLower; }
85
86
const indexedDB::Key& Upper() const { return mIsOnly ? mLower : mUpper; }
87
88
indexedDB::Key& Upper() { return mIsOnly ? mLower : mUpper; }
89
90
bool Includes(JSContext* aCx, JS::Handle<JS::Value> aValue,
91
ErrorResult& aRv) const;
92
93
bool IsOnly() const { return mIsOnly; }
94
95
void DropJSObjects();
96
97
// WebIDL
98
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
99
JS::MutableHandle<JSObject*> aReflector);
100
101
nsISupports* GetParentObject() const { return mGlobal; }
102
103
void GetLower(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
104
ErrorResult& aRv);
105
106
void GetUpper(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
107
ErrorResult& aRv);
108
109
bool LowerOpen() const { return mLowerOpen; }
110
111
bool UpperOpen() const { return mUpperOpen; }
112
113
protected:
114
IDBKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen,
115
bool aIsOnly);
116
117
virtual ~IDBKeyRange();
118
};
119
120
class IDBLocaleAwareKeyRange final : public IDBKeyRange {
121
IDBLocaleAwareKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen,
122
bool aIsOnly);
123
124
~IDBLocaleAwareKeyRange();
125
126
public:
127
static already_AddRefed<IDBLocaleAwareKeyRange> Bound(
128
const GlobalObject& aGlobal, JS::Handle<JS::Value> aLower,
129
JS::Handle<JS::Value> aUpper, bool aLowerOpen, bool aUpperOpen,
130
ErrorResult& aRv);
131
132
NS_INLINE_DECL_REFCOUNTING_INHERITED(IDBLocaleAwareKeyRange, IDBKeyRange)
133
134
// WebIDL
135
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
136
JS::MutableHandle<JSObject*> aReflector);
137
};
138
139
} // namespace dom
140
} // namespace mozilla
141
142
#endif // mozilla_dom_idbkeyrange_h__