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_indexeddb_keypath_h__
8
#define mozilla_dom_indexeddb_keypath_h__
9
10
#include "mozilla/dom/BindingDeclarations.h"
11
#include "mozilla/dom/Nullable.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
class OwningStringOrStringSequence;
17
18
namespace indexedDB {
19
20
class IndexMetadata;
21
class Key;
22
class ObjectStoreMetadata;
23
24
class KeyPath {
25
// This private constructor is only to be used by IPDL-generated classes.
26
friend class IndexMetadata;
27
friend class ObjectStoreMetadata;
28
29
KeyPath() : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
30
31
public:
32
enum KeyPathType { NONEXISTENT, STRING, ARRAY, ENDGUARD };
33
34
void SetType(KeyPathType aType);
35
36
bool AppendStringWithValidation(const nsAString& aString);
37
38
explicit KeyPath(int aDummy) : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
39
40
KeyPath(const KeyPath& aOther) {
41
MOZ_COUNT_CTOR(KeyPath);
42
*this = aOther;
43
}
44
45
~KeyPath() { MOZ_COUNT_DTOR(KeyPath); }
46
47
static nsresult Parse(const nsAString& aString, KeyPath* aKeyPath);
48
49
static nsresult Parse(const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
50
51
static nsresult Parse(const Nullable<OwningStringOrStringSequence>& aValue,
52
KeyPath* aKeyPath);
53
54
nsresult ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
55
56
nsresult ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
57
JS::Value* aOutVal) const;
58
59
typedef nsresult (*ExtractOrCreateKeyCallback)(JSContext* aCx,
60
void* aClosure);
61
62
nsresult ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue,
63
Key& aKey, ExtractOrCreateKeyCallback aCallback,
64
void* aClosure) const;
65
66
inline bool IsValid() const { return mType != NONEXISTENT; }
67
68
inline bool IsArray() const { return mType == ARRAY; }
69
70
inline bool IsString() const { return mType == STRING; }
71
72
inline bool IsEmpty() const {
73
return mType == STRING && mStrings[0].IsEmpty();
74
}
75
76
bool operator==(const KeyPath& aOther) const {
77
return mType == aOther.mType && mStrings == aOther.mStrings;
78
}
79
80
void SerializeToString(nsAString& aString) const;
81
static KeyPath DeserializeFromString(const nsAString& aString);
82
83
nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
84
nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
85
86
bool IsAllowedForObjectStore(bool aAutoIncrement) const;
87
88
KeyPathType mType;
89
90
nsTArray<nsString> mStrings;
91
};
92
93
} // namespace indexedDB
94
} // namespace dom
95
} // namespace mozilla
96
97
#endif // mozilla_dom_indexeddb_keypath_h__