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