Bug 1680751 - Change KeyPathType to an enum class. r=ttung,dom-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D110346
This commit is contained in:
Dylan Franken 2021-03-31 18:28:40 +00:00
Родитель 113408d081
Коммит 6b80a97364
3 изменённых файлов: 15 добавлений и 13 удалений

Просмотреть файл

@ -258,7 +258,7 @@ nsresult GetJSValFromKeyPathString(
// static
Result<KeyPath, nsresult> KeyPath::Parse(const nsAString& aString) {
KeyPath keyPath(0);
keyPath.SetType(STRING);
keyPath.SetType(KeyPathType::String);
if (!keyPath.AppendStringWithValidation(aString)) {
return Err(NS_ERROR_FAILURE);
@ -270,7 +270,7 @@ Result<KeyPath, nsresult> KeyPath::Parse(const nsAString& aString) {
// static
Result<KeyPath, nsresult> KeyPath::Parse(const Sequence<nsString>& aStrings) {
KeyPath keyPath(0);
keyPath.SetType(ARRAY);
keyPath.SetType(KeyPathType::Array);
for (uint32_t i = 0; i < aStrings.Length(); ++i) {
if (!keyPath.AppendStringWithValidation(aStrings[i])) {
@ -453,7 +453,7 @@ KeyPath KeyPath::DeserializeFromString(const nsAString& aString) {
KeyPath keyPath(0);
if (!aString.IsEmpty() && aString.First() == ',') {
keyPath.SetType(ARRAY);
keyPath.SetType(KeyPathType::Array);
// We use a comma in the beginning to indicate that it's an array of
// key paths. This is to be able to tell a string-keypath from an
@ -475,7 +475,7 @@ KeyPath KeyPath::DeserializeFromString(const nsAString& aString) {
return keyPath;
}
keyPath.SetType(STRING);
keyPath.SetType(KeyPathType::String);
keyPath.mStrings.AppendElement(aString);
return keyPath;

Просмотреть файл

@ -41,16 +41,18 @@ class KeyPath {
friend class IndexMetadata;
friend class ObjectStoreMetadata;
KeyPath() : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
KeyPath() : mType(KeyPathType::NonExistent) { MOZ_COUNT_CTOR(KeyPath); }
public:
enum KeyPathType { NONEXISTENT, STRING, ARRAY, ENDGUARD };
enum class KeyPathType { NonExistent, String, Array, EndGuard };
void SetType(KeyPathType aType);
bool AppendStringWithValidation(const nsAString& aString);
explicit KeyPath(int aDummy) : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
explicit KeyPath(int aDummy) : mType(KeyPathType::NonExistent) {
MOZ_COUNT_CTOR(KeyPath);
}
KeyPath(KeyPath&& aOther) {
MOZ_COUNT_CTOR(KeyPath);
@ -85,14 +87,14 @@ class KeyPath {
Key& aKey, ExtractOrCreateKeyCallback aCallback,
void* aClosure) const;
inline bool IsValid() const { return mType != NONEXISTENT; }
inline bool IsValid() const { return mType != KeyPathType::NonExistent; }
inline bool IsArray() const { return mType == ARRAY; }
inline bool IsArray() const { return mType == KeyPathType::Array; }
inline bool IsString() const { return mType == STRING; }
inline bool IsString() const { return mType == KeyPathType::String; }
inline bool IsEmpty() const {
return mType == STRING && mStrings[0].IsEmpty();
return mType == KeyPathType::String && mStrings[0].IsEmpty();
}
bool operator==(const KeyPath& aOther) const {

Просмотреть файл

@ -46,8 +46,8 @@ template <>
struct ParamTraits<mozilla::dom::indexedDB::KeyPath::KeyPathType>
: public ContiguousEnumSerializer<
mozilla::dom::indexedDB::KeyPath::KeyPathType,
mozilla::dom::indexedDB::KeyPath::NONEXISTENT,
mozilla::dom::indexedDB::KeyPath::ENDGUARD> {};
mozilla::dom::indexedDB::KeyPath::KeyPathType::NonExistent,
mozilla::dom::indexedDB::KeyPath::KeyPathType::EndGuard> {};
template <>
struct ParamTraits<mozilla::dom::indexedDB::KeyPath> {