Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_dom_indexeddb_keypath_h__ |
michael@0 | 8 | #define mozilla_dom_indexeddb_keypath_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/dom/indexedDB/IndexedDatabase.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "mozilla/dom/BindingDeclarations.h" |
michael@0 | 13 | |
michael@0 | 14 | BEGIN_INDEXEDDB_NAMESPACE |
michael@0 | 15 | |
michael@0 | 16 | class Key; |
michael@0 | 17 | |
michael@0 | 18 | class KeyPath |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | enum KeyPathType { |
michael@0 | 22 | NONEXISTENT, |
michael@0 | 23 | STRING, |
michael@0 | 24 | ARRAY, |
michael@0 | 25 | ENDGUARD |
michael@0 | 26 | }; |
michael@0 | 27 | |
michael@0 | 28 | void SetType(KeyPathType aType); |
michael@0 | 29 | |
michael@0 | 30 | // This does not set exceptions. |
michael@0 | 31 | bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString); |
michael@0 | 32 | |
michael@0 | 33 | explicit KeyPath(int aDummy) |
michael@0 | 34 | : mType(NONEXISTENT) |
michael@0 | 35 | { |
michael@0 | 36 | MOZ_COUNT_CTOR(KeyPath); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | KeyPath(const KeyPath& aOther) |
michael@0 | 40 | { |
michael@0 | 41 | MOZ_COUNT_CTOR(KeyPath); |
michael@0 | 42 | *this = aOther; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | ~KeyPath() |
michael@0 | 46 | { |
michael@0 | 47 | MOZ_COUNT_DTOR(KeyPath); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | static nsresult |
michael@0 | 51 | Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath); |
michael@0 | 52 | |
michael@0 | 53 | static nsresult |
michael@0 | 54 | Parse(JSContext* aCx, const Sequence<nsString>& aStrings, KeyPath* aKeyPath); |
michael@0 | 55 | |
michael@0 | 56 | static nsresult |
michael@0 | 57 | Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath); |
michael@0 | 58 | |
michael@0 | 59 | nsresult |
michael@0 | 60 | ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const; |
michael@0 | 61 | |
michael@0 | 62 | nsresult |
michael@0 | 63 | ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue, |
michael@0 | 64 | JS::Value* aOutVal) const; |
michael@0 | 65 | |
michael@0 | 66 | typedef nsresult |
michael@0 | 67 | (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure); |
michael@0 | 68 | |
michael@0 | 69 | nsresult |
michael@0 | 70 | ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey, |
michael@0 | 71 | ExtractOrCreateKeyCallback aCallback, |
michael@0 | 72 | void* aClosure) const; |
michael@0 | 73 | |
michael@0 | 74 | inline bool IsValid() const { |
michael@0 | 75 | return mType != NONEXISTENT; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | inline bool IsArray() const { |
michael@0 | 79 | return mType == ARRAY; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | inline bool IsString() const { |
michael@0 | 83 | return mType == STRING; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | inline bool IsEmpty() const { |
michael@0 | 87 | return mType == STRING && mStrings[0].IsEmpty(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | bool operator==(const KeyPath& aOther) const |
michael@0 | 91 | { |
michael@0 | 92 | return mType == aOther.mType && mStrings == aOther.mStrings; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | void SerializeToString(nsAString& aString) const; |
michael@0 | 96 | static KeyPath DeserializeFromString(const nsAString& aString); |
michael@0 | 97 | |
michael@0 | 98 | nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const; |
michael@0 | 99 | nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const; |
michael@0 | 100 | |
michael@0 | 101 | bool IsAllowedForObjectStore(bool aAutoIncrement) const; |
michael@0 | 102 | |
michael@0 | 103 | KeyPathType mType; |
michael@0 | 104 | |
michael@0 | 105 | nsTArray<nsString> mStrings; |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | END_INDEXEDDB_NAMESPACE |
michael@0 | 109 | |
michael@0 | 110 | #endif /* mozilla_dom_indexeddb_keypath_h__ */ |