1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xbl/nsXBLProtoImplMethod.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsXBLProtoImplMethod_h__ 1.10 +#define nsXBLProtoImplMethod_h__ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsIAtom.h" 1.14 +#include "nsString.h" 1.15 +#include "nsString.h" 1.16 +#include "nsXBLMaybeCompiled.h" 1.17 +#include "nsXBLProtoImplMember.h" 1.18 +#include "nsXBLSerialize.h" 1.19 + 1.20 +class nsIContent; 1.21 + 1.22 +struct nsXBLParameter { 1.23 + nsXBLParameter* mNext; 1.24 + char* mName; 1.25 + 1.26 + nsXBLParameter(const nsAString& aName) { 1.27 + MOZ_COUNT_CTOR(nsXBLParameter); 1.28 + mName = ToNewCString(aName); 1.29 + mNext = nullptr; 1.30 + } 1.31 + 1.32 + ~nsXBLParameter() { 1.33 + MOZ_COUNT_DTOR(nsXBLParameter); 1.34 + nsMemory::Free(mName); 1.35 + NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext); 1.36 + } 1.37 +}; 1.38 + 1.39 +struct nsXBLUncompiledMethod { 1.40 + nsXBLParameter* mParameters; 1.41 + nsXBLParameter* mLastParameter; 1.42 + nsXBLTextWithLineNumber mBodyText; 1.43 + 1.44 + nsXBLUncompiledMethod() : 1.45 + mParameters(nullptr), 1.46 + mLastParameter(nullptr), 1.47 + mBodyText() 1.48 + { 1.49 + MOZ_COUNT_CTOR(nsXBLUncompiledMethod); 1.50 + } 1.51 + 1.52 + ~nsXBLUncompiledMethod() { 1.53 + MOZ_COUNT_DTOR(nsXBLUncompiledMethod); 1.54 + delete mParameters; 1.55 + } 1.56 + 1.57 + int32_t GetParameterCount() { 1.58 + int32_t result = 0; 1.59 + for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext) 1.60 + result++; 1.61 + return result; 1.62 + } 1.63 + 1.64 + void AppendBodyText(const nsAString& aText) { 1.65 + mBodyText.AppendText(aText); 1.66 + } 1.67 + 1.68 + void AddParameter(const nsAString& aText) { 1.69 + nsXBLParameter* param = new nsXBLParameter(aText); 1.70 + if (!param) 1.71 + return; 1.72 + if (!mParameters) 1.73 + mParameters = param; 1.74 + else 1.75 + mLastParameter->mNext = param; 1.76 + mLastParameter = param; 1.77 + } 1.78 + 1.79 + void SetLineNumber(uint32_t aLineNumber) { 1.80 + mBodyText.SetLineNumber(aLineNumber); 1.81 + } 1.82 +}; 1.83 + 1.84 +class nsXBLProtoImplMethod: public nsXBLProtoImplMember 1.85 +{ 1.86 +public: 1.87 + nsXBLProtoImplMethod(const char16_t* aName); 1.88 + virtual ~nsXBLProtoImplMethod(); 1.89 + 1.90 + void AppendBodyText(const nsAString& aBody); 1.91 + void AddParameter(const nsAString& aName); 1.92 + 1.93 + void SetLineNumber(uint32_t aLineNumber); 1.94 + 1.95 + virtual nsresult InstallMember(JSContext* aCx, 1.96 + JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE; 1.97 + virtual nsresult CompileMember(const nsCString& aClassStr, 1.98 + JS::Handle<JSObject*> aClassObject) MOZ_OVERRIDE; 1.99 + 1.100 + virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) MOZ_OVERRIDE; 1.101 + 1.102 + nsresult Read(nsIObjectInputStream* aStream); 1.103 + virtual nsresult Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE; 1.104 + 1.105 + bool IsCompiled() const 1.106 + { 1.107 + return mMethod.IsCompiled(); 1.108 + } 1.109 + 1.110 + void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod) 1.111 + { 1.112 + mMethod.SetUncompiled(aUncompiledMethod); 1.113 + } 1.114 + 1.115 + nsXBLUncompiledMethod* GetUncompiledMethod() const 1.116 + { 1.117 + return mMethod.GetUncompiled(); 1.118 + } 1.119 + 1.120 +protected: 1.121 + void SetCompiledMethod(JSObject* aCompiledMethod) 1.122 + { 1.123 + mMethod.SetJSFunction(aCompiledMethod); 1.124 + } 1.125 + 1.126 + JSObject* GetCompiledMethod() const 1.127 + { 1.128 + return mMethod.GetJSFunction(); 1.129 + } 1.130 + 1.131 + JSObject* GetCompiledMethodPreserveColor() const 1.132 + { 1.133 + return mMethod.GetJSFunctionPreserveColor(); 1.134 + } 1.135 + 1.136 + JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod; 1.137 +}; 1.138 + 1.139 +class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod { 1.140 +public: 1.141 + nsXBLProtoImplAnonymousMethod(const char16_t* aName) : 1.142 + nsXBLProtoImplMethod(aName) 1.143 + {} 1.144 + 1.145 + nsresult Execute(nsIContent* aBoundElement); 1.146 + 1.147 + // Override InstallMember; these methods never get installed as members on 1.148 + // binding instantiations (though they may hang out in mMembers on the 1.149 + // prototype implementation). 1.150 + virtual nsresult InstallMember(JSContext* aCx, 1.151 + JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE { 1.152 + return NS_OK; 1.153 + } 1.154 + 1.155 + using nsXBLProtoImplMethod::Write; 1.156 + nsresult Write(nsIObjectOutputStream* aStream, 1.157 + XBLBindingSerializeDetails aType); 1.158 +}; 1.159 + 1.160 +#endif // nsXBLProtoImplMethod_h__