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"
13 #include "nsXBLMaybeCompiled.h"
14 #include "nsXBLProtoImplMember.h"
15 #include "nsXBLSerialize.h"
19 struct nsXBLParameter
{
20 nsXBLParameter
* mNext
;
23 explicit nsXBLParameter(const nsAString
& aName
) {
24 MOZ_COUNT_CTOR(nsXBLParameter
);
25 mName
= ToNewCString(aName
);
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() :
43 mLastParameter(nullptr),
46 MOZ_COUNT_CTOR(nsXBLUncompiledMethod
);
49 ~nsXBLUncompiledMethod() {
50 MOZ_COUNT_DTOR(nsXBLUncompiledMethod
);
54 int32_t GetParameterCount() {
56 for (nsXBLParameter
* curr
= mParameters
; curr
; curr
=curr
->mNext
)
61 void AppendBodyText(const nsAString
& aText
) {
62 mBodyText
.AppendText(aText
);
65 void AddParameter(const nsAString
& aText
) {
66 nsXBLParameter
* param
= new nsXBLParameter(aText
);
72 mLastParameter
->mNext
= param
;
73 mLastParameter
= param
;
76 void SetLineNumber(uint32_t aLineNumber
) {
77 mBodyText
.SetLineNumber(aLineNumber
);
81 class nsXBLProtoImplMethod
: public nsXBLProtoImplMember
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();
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
{
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
{
152 using nsXBLProtoImplMethod::Write
;
153 nsresult
Write(nsIObjectOutputStream
* aStream
,
154 XBLBindingSerializeDetails aType
);
157 #endif // nsXBLProtoImplMethod_h__