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
28 void SetType(KeyPathType aType
);
30 // This does not set exceptions.
31 bool AppendStringWithValidation(JSContext
* aCx
, const nsAString
& aString
);
33 explicit KeyPath(int aDummy
)
36 MOZ_COUNT_CTOR(KeyPath
);
39 KeyPath(const KeyPath
& aOther
)
41 MOZ_COUNT_CTOR(KeyPath
);
47 MOZ_COUNT_DTOR(KeyPath
);
51 Parse(JSContext
* aCx
, const nsAString
& aString
, KeyPath
* aKeyPath
);
54 Parse(JSContext
* aCx
, const Sequence
<nsString
>& aStrings
, KeyPath
* aKeyPath
);
57 Parse(JSContext
* aCx
, const JS::Value
& aValue
, KeyPath
* aKeyPath
);
60 ExtractKey(JSContext
* aCx
, const JS::Value
& aValue
, Key
& aKey
) const;
63 ExtractKeyAsJSVal(JSContext
* aCx
, const JS::Value
& aValue
,
64 JS::Value
* aOutVal
) const;
67 (*ExtractOrCreateKeyCallback
)(JSContext
* aCx
, void* aClosure
);
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;
105 nsTArray
<nsString
> mStrings
;
108 END_INDEXEDDB_NAMESPACE
110 #endif /* mozilla_dom_indexeddb_keypath_h__ */