Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/indexedDB/KeyPath.h
Line
Count
Source (jump to first uncovered line)
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
{
26
  // This private constructor is only to be used by IPDL-generated classes.
27
  friend class IndexMetadata;
28
  friend class ObjectStoreMetadata;
29
30
  KeyPath()
31
  : mType(NONEXISTENT)
32
  {
33
    MOZ_COUNT_CTOR(KeyPath);
34
  }
35
36
public:
37
  enum KeyPathType {
38
    NONEXISTENT,
39
    STRING,
40
    ARRAY,
41
    ENDGUARD
42
  };
43
44
  void SetType(KeyPathType aType);
45
46
  bool AppendStringWithValidation(const nsAString& aString);
47
48
  explicit KeyPath(int aDummy)
49
  : mType(NONEXISTENT)
50
0
  {
51
0
    MOZ_COUNT_CTOR(KeyPath);
52
0
  }
53
54
  KeyPath(const KeyPath& aOther)
55
0
  {
56
0
    MOZ_COUNT_CTOR(KeyPath);
57
0
    *this = aOther;
58
0
  }
59
60
  ~KeyPath()
61
  {
62
    MOZ_COUNT_DTOR(KeyPath);
63
  }
64
65
  static nsresult
66
  Parse(const nsAString& aString, KeyPath* aKeyPath);
67
68
  static nsresult
69
  Parse(const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
70
71
  static nsresult
72
  Parse(const Nullable<OwningStringOrStringSequence>& aValue, KeyPath* aKeyPath);
73
74
  nsresult
75
  ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
76
77
  nsresult
78
  ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
79
                    JS::Value* aOutVal) const;
80
81
  typedef nsresult
82
  (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure);
83
84
  nsresult
85
  ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey,
86
                     ExtractOrCreateKeyCallback aCallback,
87
                     void* aClosure) const;
88
89
0
  inline bool IsValid() const {
90
0
    return mType != NONEXISTENT;
91
0
  }
92
93
0
  inline bool IsArray() const {
94
0
    return mType == ARRAY;
95
0
  }
96
97
0
  inline bool IsString() const {
98
0
    return mType == STRING;
99
0
  }
100
101
0
  inline bool IsEmpty() const {
102
0
    return mType == STRING && mStrings[0].IsEmpty();
103
0
  }
104
105
  bool operator==(const KeyPath& aOther) const
106
  {
107
    return mType == aOther.mType && mStrings == aOther.mStrings;
108
  }
109
110
  void SerializeToString(nsAString& aString) const;
111
  static KeyPath DeserializeFromString(const nsAString& aString);
112
113
  nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
114
  nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
115
116
  bool IsAllowedForObjectStore(bool aAutoIncrement) const;
117
118
  KeyPathType mType;
119
120
  nsTArray<nsString> mStrings;
121
};
122
123
} // namespace indexedDB
124
} // namespace dom
125
} // namespace mozilla
126
127
#endif // mozilla_dom_indexeddb_keypath_h__