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: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsXBLProtoImplMethod_h__ |
michael@0 | 7 | #define nsXBLProtoImplMethod_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsIAtom.h" |
michael@0 | 11 | #include "nsString.h" |
michael@0 | 12 | #include "nsString.h" |
michael@0 | 13 | #include "nsXBLMaybeCompiled.h" |
michael@0 | 14 | #include "nsXBLProtoImplMember.h" |
michael@0 | 15 | #include "nsXBLSerialize.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsIContent; |
michael@0 | 18 | |
michael@0 | 19 | struct nsXBLParameter { |
michael@0 | 20 | nsXBLParameter* mNext; |
michael@0 | 21 | char* mName; |
michael@0 | 22 | |
michael@0 | 23 | nsXBLParameter(const nsAString& aName) { |
michael@0 | 24 | MOZ_COUNT_CTOR(nsXBLParameter); |
michael@0 | 25 | mName = ToNewCString(aName); |
michael@0 | 26 | mNext = nullptr; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | ~nsXBLParameter() { |
michael@0 | 30 | MOZ_COUNT_DTOR(nsXBLParameter); |
michael@0 | 31 | nsMemory::Free(mName); |
michael@0 | 32 | NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext); |
michael@0 | 33 | } |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | struct nsXBLUncompiledMethod { |
michael@0 | 37 | nsXBLParameter* mParameters; |
michael@0 | 38 | nsXBLParameter* mLastParameter; |
michael@0 | 39 | nsXBLTextWithLineNumber mBodyText; |
michael@0 | 40 | |
michael@0 | 41 | nsXBLUncompiledMethod() : |
michael@0 | 42 | mParameters(nullptr), |
michael@0 | 43 | mLastParameter(nullptr), |
michael@0 | 44 | mBodyText() |
michael@0 | 45 | { |
michael@0 | 46 | MOZ_COUNT_CTOR(nsXBLUncompiledMethod); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | ~nsXBLUncompiledMethod() { |
michael@0 | 50 | MOZ_COUNT_DTOR(nsXBLUncompiledMethod); |
michael@0 | 51 | delete mParameters; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | int32_t GetParameterCount() { |
michael@0 | 55 | int32_t result = 0; |
michael@0 | 56 | for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext) |
michael@0 | 57 | result++; |
michael@0 | 58 | return result; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | void AppendBodyText(const nsAString& aText) { |
michael@0 | 62 | mBodyText.AppendText(aText); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void AddParameter(const nsAString& aText) { |
michael@0 | 66 | nsXBLParameter* param = new nsXBLParameter(aText); |
michael@0 | 67 | if (!param) |
michael@0 | 68 | return; |
michael@0 | 69 | if (!mParameters) |
michael@0 | 70 | mParameters = param; |
michael@0 | 71 | else |
michael@0 | 72 | mLastParameter->mNext = param; |
michael@0 | 73 | mLastParameter = param; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | void SetLineNumber(uint32_t aLineNumber) { |
michael@0 | 77 | mBodyText.SetLineNumber(aLineNumber); |
michael@0 | 78 | } |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | class nsXBLProtoImplMethod: public nsXBLProtoImplMember |
michael@0 | 82 | { |
michael@0 | 83 | public: |
michael@0 | 84 | nsXBLProtoImplMethod(const char16_t* aName); |
michael@0 | 85 | virtual ~nsXBLProtoImplMethod(); |
michael@0 | 86 | |
michael@0 | 87 | void AppendBodyText(const nsAString& aBody); |
michael@0 | 88 | void AddParameter(const nsAString& aName); |
michael@0 | 89 | |
michael@0 | 90 | void SetLineNumber(uint32_t aLineNumber); |
michael@0 | 91 | |
michael@0 | 92 | virtual nsresult InstallMember(JSContext* aCx, |
michael@0 | 93 | JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE; |
michael@0 | 94 | virtual nsresult CompileMember(const nsCString& aClassStr, |
michael@0 | 95 | JS::Handle<JSObject*> aClassObject) MOZ_OVERRIDE; |
michael@0 | 96 | |
michael@0 | 97 | virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) MOZ_OVERRIDE; |
michael@0 | 98 | |
michael@0 | 99 | nsresult Read(nsIObjectInputStream* aStream); |
michael@0 | 100 | virtual nsresult Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE; |
michael@0 | 101 | |
michael@0 | 102 | bool IsCompiled() const |
michael@0 | 103 | { |
michael@0 | 104 | return mMethod.IsCompiled(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod) |
michael@0 | 108 | { |
michael@0 | 109 | mMethod.SetUncompiled(aUncompiledMethod); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | nsXBLUncompiledMethod* GetUncompiledMethod() const |
michael@0 | 113 | { |
michael@0 | 114 | return mMethod.GetUncompiled(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | protected: |
michael@0 | 118 | void SetCompiledMethod(JSObject* aCompiledMethod) |
michael@0 | 119 | { |
michael@0 | 120 | mMethod.SetJSFunction(aCompiledMethod); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | JSObject* GetCompiledMethod() const |
michael@0 | 124 | { |
michael@0 | 125 | return mMethod.GetJSFunction(); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | JSObject* GetCompiledMethodPreserveColor() const |
michael@0 | 129 | { |
michael@0 | 130 | return mMethod.GetJSFunctionPreserveColor(); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod; |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod { |
michael@0 | 137 | public: |
michael@0 | 138 | nsXBLProtoImplAnonymousMethod(const char16_t* aName) : |
michael@0 | 139 | nsXBLProtoImplMethod(aName) |
michael@0 | 140 | {} |
michael@0 | 141 | |
michael@0 | 142 | nsresult Execute(nsIContent* aBoundElement); |
michael@0 | 143 | |
michael@0 | 144 | // Override InstallMember; these methods never get installed as members on |
michael@0 | 145 | // binding instantiations (though they may hang out in mMembers on the |
michael@0 | 146 | // prototype implementation). |
michael@0 | 147 | virtual nsresult InstallMember(JSContext* aCx, |
michael@0 | 148 | JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE { |
michael@0 | 149 | return NS_OK; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | using nsXBLProtoImplMethod::Write; |
michael@0 | 153 | nsresult Write(nsIObjectOutputStream* aStream, |
michael@0 | 154 | XBLBindingSerializeDetails aType); |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | #endif // nsXBLProtoImplMethod_h__ |