Bumping manifests a=b2g-bump
[gecko.git] / dom / indexedDB / KeyPath.h
blobbee0c2cad0e8879eb751abba7a61ef235639fa7e
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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_indexeddb_keypath_h__
8 #define mozilla_dom_indexeddb_keypath_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "mozilla/dom/BindingDeclarations.h"
14 BEGIN_INDEXEDDB_NAMESPACE
16 class Key;
18 class KeyPath
20 public:
21 enum KeyPathType {
22 NONEXISTENT,
23 STRING,
24 ARRAY,
25 ENDGUARD
28 void SetType(KeyPathType aType);
30 // This does not set exceptions.
31 bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString);
33 explicit KeyPath(int aDummy)
34 : mType(NONEXISTENT)
36 MOZ_COUNT_CTOR(KeyPath);
39 KeyPath(const KeyPath& aOther)
41 MOZ_COUNT_CTOR(KeyPath);
42 *this = aOther;
45 ~KeyPath()
47 MOZ_COUNT_DTOR(KeyPath);
50 static nsresult
51 Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath);
53 static nsresult
54 Parse(JSContext* aCx, const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
56 static nsresult
57 Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath);
59 nsresult
60 ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
62 nsresult
63 ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
64 JS::Value* aOutVal) const;
66 typedef nsresult
67 (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure);
69 nsresult
70 ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey,
71 ExtractOrCreateKeyCallback aCallback,
72 void* aClosure) const;
74 inline bool IsValid() const {
75 return mType != NONEXISTENT;
78 inline bool IsArray() const {
79 return mType == ARRAY;
82 inline bool IsString() const {
83 return mType == STRING;
86 inline bool IsEmpty() const {
87 return mType == STRING && mStrings[0].IsEmpty();
90 bool operator==(const KeyPath& aOther) const
92 return mType == aOther.mType && mStrings == aOther.mStrings;
95 void SerializeToString(nsAString& aString) const;
96 static KeyPath DeserializeFromString(const nsAString& aString);
98 nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
99 nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
101 bool IsAllowedForObjectStore(bool aAutoIncrement) const;
103 KeyPathType mType;
105 nsTArray<nsString> mStrings;
108 END_INDEXEDDB_NAMESPACE
110 #endif /* mozilla_dom_indexeddb_keypath_h__ */