Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / xbl / nsXBLProtoImplMethod.h
blobb42432b0d40a5cf4a31b68f316129c8228215fbe
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsXBLProtoImplMethod_h__
7 #define nsXBLProtoImplMethod_h__
9 #include "mozilla/Attributes.h"
10 #include "nsIAtom.h"
11 #include "nsString.h"
12 #include "nsString.h"
13 #include "nsXBLMaybeCompiled.h"
14 #include "nsXBLProtoImplMember.h"
15 #include "nsXBLSerialize.h"
17 class nsIContent;
19 struct nsXBLParameter {
20 nsXBLParameter* mNext;
21 char* mName;
23 explicit nsXBLParameter(const nsAString& aName) {
24 MOZ_COUNT_CTOR(nsXBLParameter);
25 mName = ToNewCString(aName);
26 mNext = nullptr;
29 ~nsXBLParameter() {
30 MOZ_COUNT_DTOR(nsXBLParameter);
31 nsMemory::Free(mName);
32 NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext);
36 struct nsXBLUncompiledMethod {
37 nsXBLParameter* mParameters;
38 nsXBLParameter* mLastParameter;
39 nsXBLTextWithLineNumber mBodyText;
41 nsXBLUncompiledMethod() :
42 mParameters(nullptr),
43 mLastParameter(nullptr),
44 mBodyText()
46 MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
49 ~nsXBLUncompiledMethod() {
50 MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
51 delete mParameters;
54 int32_t GetParameterCount() {
55 int32_t result = 0;
56 for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
57 result++;
58 return result;
61 void AppendBodyText(const nsAString& aText) {
62 mBodyText.AppendText(aText);
65 void AddParameter(const nsAString& aText) {
66 nsXBLParameter* param = new nsXBLParameter(aText);
67 if (!param)
68 return;
69 if (!mParameters)
70 mParameters = param;
71 else
72 mLastParameter->mNext = param;
73 mLastParameter = param;
76 void SetLineNumber(uint32_t aLineNumber) {
77 mBodyText.SetLineNumber(aLineNumber);
81 class nsXBLProtoImplMethod: public nsXBLProtoImplMember
83 public:
84 explicit nsXBLProtoImplMethod(const char16_t* aName);
85 virtual ~nsXBLProtoImplMethod();
87 void AppendBodyText(const nsAString& aBody);
88 void AddParameter(const nsAString& aName);
90 void SetLineNumber(uint32_t aLineNumber);
92 virtual nsresult InstallMember(JSContext* aCx,
93 JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE;
94 virtual nsresult CompileMember(const nsCString& aClassStr,
95 JS::Handle<JSObject*> aClassObject) MOZ_OVERRIDE;
97 virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) MOZ_OVERRIDE;
99 nsresult Read(nsIObjectInputStream* aStream);
100 virtual nsresult Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE;
102 bool IsCompiled() const
104 return mMethod.IsCompiled();
107 void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
109 mMethod.SetUncompiled(aUncompiledMethod);
112 nsXBLUncompiledMethod* GetUncompiledMethod() const
114 return mMethod.GetUncompiled();
117 protected:
118 void SetCompiledMethod(JSObject* aCompiledMethod)
120 mMethod.SetJSFunction(aCompiledMethod);
123 JSObject* GetCompiledMethod() const
125 return mMethod.GetJSFunction();
128 JSObject* GetCompiledMethodPreserveColor() const
130 return mMethod.GetJSFunctionPreserveColor();
133 JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod;
136 class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
137 public:
138 explicit nsXBLProtoImplAnonymousMethod(const char16_t* aName) :
139 nsXBLProtoImplMethod(aName)
142 nsresult Execute(nsIContent* aBoundElement, JSAddonId* aAddonId);
144 // Override InstallMember; these methods never get installed as members on
145 // binding instantiations (though they may hang out in mMembers on the
146 // prototype implementation).
147 virtual nsresult InstallMember(JSContext* aCx,
148 JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE {
149 return NS_OK;
152 using nsXBLProtoImplMethod::Write;
153 nsresult Write(nsIObjectOutputStream* aStream,
154 XBLBindingSerializeDetails aType);
157 #endif // nsXBLProtoImplMethod_h__