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_idbobjectstore_h__
8 #define mozilla_dom_idbobjectstore_h__
10 #include "js/RootingAPI.h"
11 #include "mozilla/dom/IDBCursorBinding.h"
12 #include "mozilla/dom/IDBIndexBinding.h"
13 #include "nsAutoPtr.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsISupports.h"
18 #include "nsWrapperCache.h"
21 class nsPIDOMWindowInner
;
33 template <typename
> class Sequence
;
38 class IndexUpdateInfo
;
39 class ObjectStoreSpec
;
40 struct StructuredCloneReadInfo
;
41 } // namespace indexedDB
43 class IDBObjectStore final
45 , public nsWrapperCache
47 typedef indexedDB::IndexUpdateInfo IndexUpdateInfo
;
48 typedef indexedDB::Key Key
;
49 typedef indexedDB::KeyPath KeyPath
;
50 typedef indexedDB::ObjectStoreSpec ObjectStoreSpec
;
51 typedef indexedDB::StructuredCloneReadInfo StructuredCloneReadInfo
;
53 // For AddOrPut() and DeleteInternal().
54 friend class IDBCursor
;
56 static const JSClass sDummyPropJSClass
;
58 RefPtr
<IDBTransaction
> mTransaction
;
59 JS::Heap
<JS::Value
> mCachedKeyPath
;
61 // This normally points to the ObjectStoreSpec owned by the parent IDBDatabase
62 // object. However, if this objectStore is part of a versionchange transaction
63 // and it gets deleted then the spec is copied into mDeletedSpec and mSpec is
64 // set to point at mDeletedSpec.
65 const ObjectStoreSpec
* mSpec
;
66 nsAutoPtr
<ObjectStoreSpec
> mDeletedSpec
;
68 nsTArray
<RefPtr
<IDBIndex
>> mIndexes
;
74 struct StructuredCloneWriteInfo
;
76 static already_AddRefed
<IDBObjectStore
>
77 Create(IDBTransaction
* aTransaction
, const ObjectStoreSpec
& aSpec
);
80 AppendIndexUpdateInfo(int64_t aIndexID
,
81 const KeyPath
& aKeyPath
,
84 const nsCString
& aLocale
,
86 JS::Handle
<JS::Value
> aObject
,
87 nsTArray
<IndexUpdateInfo
>& aUpdateInfoArray
);
90 ClearCloneReadInfo(StructuredCloneReadInfo
& aReadInfo
);
93 DeserializeValue(JSContext
* aCx
,
94 StructuredCloneReadInfo
& aCloneReadInfo
,
95 JS::MutableHandle
<JS::Value
> aValue
);
98 DeserializeIndexValue(JSContext
* aCx
,
99 StructuredCloneReadInfo
& aCloneReadInfo
,
100 JS::MutableHandle
<JS::Value
> aValue
);
102 #if !defined(MOZ_B2G)
104 DeserializeUpgradeValue(JSContext
* aCx
,
105 StructuredCloneReadInfo
& aCloneReadInfo
,
106 JS::MutableHandle
<JS::Value
> aValue
);
109 static const JSClass
*
112 return &sDummyPropJSClass
;
116 AssertIsOnOwningThread() const
126 AssertIsOnOwningThread();
135 AutoIncrement() const;
141 HasValidKeyPath() const;
144 GetParentObject() const;
147 GetName(nsString
& aName
) const
149 AssertIsOnOwningThread();
155 GetKeyPath(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
,
158 already_AddRefed
<DOMStringList
>
164 AssertIsOnOwningThread();
169 already_AddRefed
<IDBRequest
>
171 JS::Handle
<JS::Value
> aValue
,
172 JS::Handle
<JS::Value
> aKey
,
175 AssertIsOnOwningThread();
177 return AddOrPut(aCx
, aValue
, aKey
, false, /* aFromCursor */ false, aRv
);
180 already_AddRefed
<IDBRequest
>
182 JS::Handle
<JS::Value
> aValue
,
183 JS::Handle
<JS::Value
> aKey
,
186 AssertIsOnOwningThread();
188 return AddOrPut(aCx
, aValue
, aKey
, true, /* aFromCursor */ false, aRv
);
191 already_AddRefed
<IDBRequest
>
192 Delete(JSContext
* aCx
,
193 JS::Handle
<JS::Value
> aKey
,
196 AssertIsOnOwningThread();
198 return DeleteInternal(aCx
, aKey
, /* aFromCursor */ false, aRv
);
201 already_AddRefed
<IDBRequest
>
202 Get(JSContext
* aCx
, JS::Handle
<JS::Value
> aKey
, ErrorResult
& aRv
);
204 already_AddRefed
<IDBRequest
>
205 Clear(JSContext
* aCx
, ErrorResult
& aRv
);
207 already_AddRefed
<IDBIndex
>
208 CreateIndex(const nsAString
& aName
,
209 const nsAString
& aKeyPath
,
210 const IDBIndexParameters
& aOptionalParameters
,
213 already_AddRefed
<IDBIndex
>
214 CreateIndex(const nsAString
& aName
,
215 const Sequence
<nsString
>& aKeyPath
,
216 const IDBIndexParameters
& aOptionalParameters
,
219 already_AddRefed
<IDBIndex
>
220 Index(const nsAString
& aName
, ErrorResult
&aRv
);
223 DeleteIndex(const nsAString
& aIndexName
, ErrorResult
& aRv
);
225 already_AddRefed
<IDBRequest
>
226 Count(JSContext
* aCx
,
227 JS::Handle
<JS::Value
> aKey
,
230 already_AddRefed
<IDBRequest
>
231 GetAll(JSContext
* aCx
,
232 JS::Handle
<JS::Value
> aKey
,
233 const Optional
<uint32_t>& aLimit
,
236 AssertIsOnOwningThread();
238 return GetAllInternal(/* aKeysOnly */ false, aCx
, aKey
, aLimit
, aRv
);
241 already_AddRefed
<IDBRequest
>
242 GetAllKeys(JSContext
* aCx
,
243 JS::Handle
<JS::Value
> aKey
,
244 const Optional
<uint32_t>& aLimit
,
247 AssertIsOnOwningThread();
249 return GetAllInternal(/* aKeysOnly */ true, aCx
, aKey
, aLimit
, aRv
);
252 already_AddRefed
<IDBRequest
>
253 OpenCursor(JSContext
* aCx
,
254 JS::Handle
<JS::Value
> aRange
,
255 IDBCursorDirection aDirection
,
258 AssertIsOnOwningThread();
260 return OpenCursorInternal(/* aKeysOnly */ false, aCx
, aRange
, aDirection
,
264 already_AddRefed
<IDBRequest
>
265 OpenCursor(JSContext
* aCx
,
266 IDBCursorDirection aDirection
,
269 AssertIsOnOwningThread();
271 return OpenCursorInternal(/* aKeysOnly */ false, aCx
,
272 JS::UndefinedHandleValue
, aDirection
, aRv
);
275 already_AddRefed
<IDBRequest
>
276 OpenKeyCursor(JSContext
* aCx
,
277 JS::Handle
<JS::Value
> aRange
,
278 IDBCursorDirection aDirection
,
281 AssertIsOnOwningThread();
283 return OpenCursorInternal(/* aKeysOnly */ true, aCx
, aRange
, aDirection
,
288 RefreshSpec(bool aMayDelete
);
290 const ObjectStoreSpec
&
299 AssertIsOnOwningThread();
301 return !!mDeletedSpec
;
304 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
305 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBObjectStore
)
309 WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
312 IDBObjectStore(IDBTransaction
* aTransaction
, const ObjectStoreSpec
* aSpec
);
317 GetAddInfo(JSContext
* aCx
,
318 JS::Handle
<JS::Value
> aValue
,
319 JS::Handle
<JS::Value
> aKeyVal
,
320 StructuredCloneWriteInfo
& aCloneWriteInfo
,
322 nsTArray
<IndexUpdateInfo
>& aUpdateInfoArray
);
324 already_AddRefed
<IDBRequest
>
325 AddOrPut(JSContext
* aCx
,
326 JS::Handle
<JS::Value
> aValue
,
327 JS::Handle
<JS::Value
> aKey
,
332 already_AddRefed
<IDBRequest
>
333 DeleteInternal(JSContext
* aCx
,
334 JS::Handle
<JS::Value
> aKey
,
338 already_AddRefed
<IDBRequest
>
339 GetAllInternal(bool aKeysOnly
,
341 JS::Handle
<JS::Value
> aKey
,
342 const Optional
<uint32_t>& aLimit
,
345 already_AddRefed
<IDBIndex
>
346 CreateIndexInternal(const nsAString
& aName
,
347 const KeyPath
& aKeyPath
,
348 const IDBIndexParameters
& aOptionalParameters
,
351 already_AddRefed
<IDBRequest
>
352 OpenCursorInternal(bool aKeysOnly
,
354 JS::Handle
<JS::Value
> aRange
,
355 IDBCursorDirection aDirection
,
360 } // namespace mozilla
362 #endif // mozilla_dom_idbobjectstore_h__