gecko/dom/indexedDB/KeyPath.h
Ben Turner b3c31c0c49 Bug 994190 - 'Modify main-thread IndexedDB to use PBackground', r=khuey.
--HG--
rename : dom/indexedDB/ipc/SerializationHelpers.h => dom/indexedDB/SerializationHelpers.h
rename : dom/indexedDB/ipc/unit/head.js => dom/indexedDB/test/unit/xpcshell-head-child-process.js
rename : dom/indexedDB/test/unit/head.js => dom/indexedDB/test/unit/xpcshell-head-parent-process.js
rename : dom/ipc/Blob.h => dom/ipc/BlobParent.h
rename : dom/ipc/FileDescriptorSetChild.cpp => ipc/glue/FileDescriptorSetChild.cpp
rename : dom/ipc/FileDescriptorSetChild.h => ipc/glue/FileDescriptorSetChild.h
rename : dom/ipc/FileDescriptorSetParent.cpp => ipc/glue/FileDescriptorSetParent.cpp
rename : dom/ipc/FileDescriptorSetParent.h => ipc/glue/FileDescriptorSetParent.h
rename : dom/ipc/PFileDescriptorSet.ipdl => ipc/glue/PFileDescriptorSet.ipdl
2014-09-13 12:12:19 -04:00

125 lines
2.9 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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__
#include "mozilla/dom/BindingDeclarations.h"
namespace mozilla {
namespace dom {
namespace indexedDB {
class IndexMetadata;
class Key;
class ObjectStoreMetadata;
class KeyPath
{
// 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);
}
public:
enum KeyPathType {
NONEXISTENT,
STRING,
ARRAY,
ENDGUARD
};
void SetType(KeyPathType aType);
// This does not set exceptions.
bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString);
explicit KeyPath(int aDummy)
: mType(NONEXISTENT)
{
MOZ_COUNT_CTOR(KeyPath);
}
KeyPath(const KeyPath& aOther)
{
MOZ_COUNT_CTOR(KeyPath);
*this = aOther;
}
~KeyPath()
{
MOZ_COUNT_DTOR(KeyPath);
}
static nsresult
Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath);
static nsresult
Parse(JSContext* aCx, const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
static nsresult
Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath);
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);
nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
bool IsAllowedForObjectStore(bool aAutoIncrement) const;
KeyPathType mType;
nsTArray<nsString> mStrings;
};
} // namespace indexedDB
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_indexeddb_keypath_h__