2012-06-24 17:29:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-06-22 02:27:13 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_indexeddb_keypath_h__
|
|
|
|
#define mozilla_dom_indexeddb_keypath_h__
|
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-12-11 21:07:44 +03:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-12-11 21:07:44 +03:00
|
|
|
|
|
|
|
class OwningStringOrStringSequence;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class IndexMetadata;
|
2012-06-22 02:27:13 +04:00
|
|
|
class Key;
|
2014-09-27 03:21:57 +04:00
|
|
|
class ObjectStoreMetadata;
|
2012-06-22 02:27:13 +04:00
|
|
|
|
|
|
|
class KeyPath {
|
2014-09-27 03:21:57 +04:00
|
|
|
// This private constructor is only to be used by IPDL-generated classes.
|
|
|
|
friend class IndexMetadata;
|
|
|
|
friend class ObjectStoreMetadata;
|
|
|
|
|
|
|
|
KeyPath() : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
|
|
|
|
|
2012-06-22 06:26:57 +04:00
|
|
|
public:
|
2012-06-22 02:27:13 +04:00
|
|
|
enum KeyPathType { NONEXISTENT, STRING, ARRAY, ENDGUARD };
|
|
|
|
|
|
|
|
void SetType(KeyPathType aType);
|
|
|
|
|
2014-12-11 21:07:44 +03:00
|
|
|
bool AppendStringWithValidation(const nsAString& aString);
|
2012-06-22 02:27:13 +04:00
|
|
|
|
|
|
|
explicit KeyPath(int aDummy) : mType(NONEXISTENT) { MOZ_COUNT_CTOR(KeyPath); }
|
|
|
|
|
2020-05-05 17:13:46 +03:00
|
|
|
KeyPath(KeyPath&& aOther) {
|
|
|
|
MOZ_COUNT_CTOR(KeyPath);
|
|
|
|
*this = std::move(aOther);
|
|
|
|
}
|
|
|
|
KeyPath& operator=(KeyPath&&) = default;
|
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
KeyPath(const KeyPath& aOther) {
|
|
|
|
MOZ_COUNT_CTOR(KeyPath);
|
|
|
|
*this = aOther;
|
|
|
|
}
|
2020-05-05 17:13:46 +03:00
|
|
|
KeyPath& operator=(const KeyPath&) = default;
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2020-02-20 14:40:14 +03:00
|
|
|
MOZ_COUNTED_DTOR(KeyPath)
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2014-12-11 21:07:44 +03:00
|
|
|
static nsresult Parse(const nsAString& aString, KeyPath* aKeyPath);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2014-12-11 21:07:44 +03:00
|
|
|
static nsresult Parse(const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
|
2013-07-31 19:48:36 +04:00
|
|
|
|
2014-12-11 21:07:44 +03:00
|
|
|
static nsresult Parse(const Nullable<OwningStringOrStringSequence>& aValue,
|
|
|
|
KeyPath* aKeyPath);
|
2012-06-22 02:27:13 +04:00
|
|
|
|
|
|
|
nsresult ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
|
|
|
|
|
|
|
|
nsresult ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
|
|
|
|
JS::Value* aOutVal) const;
|
|
|
|
|
|
|
|
typedef nsresult (*ExtractOrCreateKeyCallback)(JSContext* aCx,
|
|
|
|
void* aClosure);
|
|
|
|
|
|
|
|
nsresult ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue,
|
|
|
|
Key& aKey, ExtractOrCreateKeyCallback aCallback,
|
|
|
|
void* aClosure) const;
|
|
|
|
|
|
|
|
inline bool IsValid() const { return mType != NONEXISTENT; }
|
|
|
|
|
|
|
|
inline bool IsArray() const { return mType == ARRAY; }
|
|
|
|
|
|
|
|
inline bool IsString() const { return mType == STRING; }
|
|
|
|
|
|
|
|
inline bool IsEmpty() const {
|
|
|
|
return mType == STRING && mStrings[0].IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const KeyPath& aOther) const {
|
|
|
|
return mType == aOther.mType && mStrings == aOther.mStrings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SerializeToString(nsAString& aString) const;
|
|
|
|
static KeyPath DeserializeFromString(const nsAString& aString);
|
|
|
|
|
2013-06-18 14:00:37 +04:00
|
|
|
nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
|
|
|
|
nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
|
2012-06-22 02:27:13 +04:00
|
|
|
|
|
|
|
bool IsAllowedForObjectStore(bool aAutoIncrement) const;
|
|
|
|
|
|
|
|
KeyPathType mType;
|
|
|
|
|
2020-05-05 17:13:46 +03:00
|
|
|
CopyableTArray<nsString> mStrings;
|
2012-06-22 02:27:13 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_keypath_h__
|