2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXBLProtoImplMethod_h__
|
|
|
|
#define nsXBLProtoImplMethod_h__
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsString.h"
|
2013-06-18 03:00:38 -07:00
|
|
|
#include "nsXBLMaybeCompiled.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXBLProtoImplMember.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
#include "nsXBLSerialize.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsIContent;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct nsXBLParameter {
|
|
|
|
nsXBLParameter* mNext;
|
|
|
|
char* mName;
|
|
|
|
|
|
|
|
nsXBLParameter(const nsAString& aName) {
|
|
|
|
MOZ_COUNT_CTOR(nsXBLParameter);
|
|
|
|
mName = ToNewCString(aName);
|
2012-07-30 07:20:58 -07:00
|
|
|
mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~nsXBLParameter() {
|
|
|
|
MOZ_COUNT_DTOR(nsXBLParameter);
|
|
|
|
nsMemory::Free(mName);
|
2008-12-15 03:33:56 -08:00
|
|
|
NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsXBLUncompiledMethod {
|
|
|
|
nsXBLParameter* mParameters;
|
|
|
|
nsXBLParameter* mLastParameter;
|
|
|
|
nsXBLTextWithLineNumber mBodyText;
|
|
|
|
|
|
|
|
nsXBLUncompiledMethod() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mParameters(nullptr),
|
|
|
|
mLastParameter(nullptr),
|
2007-03-22 10:30:00 -07:00
|
|
|
mBodyText()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsXBLUncompiledMethod() {
|
|
|
|
MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
|
|
|
|
delete mParameters;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetParameterCount() {
|
|
|
|
int32_t result = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
|
|
|
|
result++;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendBodyText(const nsAString& aText) {
|
|
|
|
mBodyText.AppendText(aText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddParameter(const nsAString& aText) {
|
|
|
|
nsXBLParameter* param = new nsXBLParameter(aText);
|
|
|
|
if (!param)
|
|
|
|
return;
|
|
|
|
if (!mParameters)
|
|
|
|
mParameters = param;
|
|
|
|
else
|
|
|
|
mLastParameter->mNext = param;
|
|
|
|
mLastParameter = param;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetLineNumber(uint32_t aLineNumber) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mBodyText.SetLineNumber(aLineNumber);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsXBLProtoImplMethod: public nsXBLProtoImplMember
|
|
|
|
{
|
|
|
|
public:
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLProtoImplMethod(const char16_t* aName);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsXBLProtoImplMethod();
|
|
|
|
|
|
|
|
void AppendBodyText(const nsAString& aBody);
|
|
|
|
void AddParameter(const nsAString& aName);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetLineNumber(uint32_t aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
virtual nsresult InstallMember(JSContext* aCx,
|
2013-05-29 13:43:41 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE;
|
2013-08-09 09:25:13 -07:00
|
|
|
virtual nsresult CompileMember(const nsCString& aClassStr,
|
2013-05-29 13:43:41 -07:00
|
|
|
JS::Handle<JSObject*> aClassObject) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) MOZ_OVERRIDE;
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
nsresult Read(nsIObjectInputStream* aStream);
|
|
|
|
virtual nsresult Write(nsIObjectOutputStream* aStream) MOZ_OVERRIDE;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsCompiled() const
|
2008-02-12 08:02:41 -08:00
|
|
|
{
|
2013-06-18 03:00:38 -07:00
|
|
|
return mMethod.IsCompiled();
|
2008-02-12 08:02:41 -08:00
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
|
|
|
|
{
|
2013-06-18 03:00:38 -07:00
|
|
|
mMethod.SetUncompiled(aUncompiledMethod);
|
2008-02-12 08:02:41 -08:00
|
|
|
}
|
2013-06-18 03:00:38 -07:00
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
nsXBLUncompiledMethod* GetUncompiledMethod() const
|
|
|
|
{
|
2013-06-18 03:00:38 -07:00
|
|
|
return mMethod.GetUncompiled();
|
2008-02-12 08:02:41 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2013-06-18 03:00:38 -07:00
|
|
|
void SetCompiledMethod(JSObject* aCompiledMethod)
|
|
|
|
{
|
|
|
|
mMethod.SetJSFunction(aCompiledMethod);
|
|
|
|
}
|
2008-02-12 08:02:41 -08:00
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
JSObject* GetCompiledMethod() const
|
|
|
|
{
|
|
|
|
return mMethod.GetJSFunction();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-21 13:19:46 -08:00
|
|
|
JSObject* GetCompiledMethodPreserveColor() const
|
|
|
|
{
|
|
|
|
return mMethod.GetJSFunctionPreserveColor();
|
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
|
|
|
|
public:
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLProtoImplAnonymousMethod(const char16_t* aName) :
|
2013-08-21 16:45:52 -07:00
|
|
|
nsXBLProtoImplMethod(aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
nsresult Execute(nsIContent* aBoundElement);
|
|
|
|
|
|
|
|
// Override InstallMember; these methods never get installed as members on
|
|
|
|
// binding instantiations (though they may hang out in mMembers on the
|
|
|
|
// prototype implementation).
|
2013-02-08 06:24:21 -08:00
|
|
|
virtual nsresult InstallMember(JSContext* aCx,
|
2013-05-29 13:43:41 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) MOZ_OVERRIDE {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2011-11-15 23:50:18 -08:00
|
|
|
using nsXBLProtoImplMethod::Write;
|
2013-08-09 09:25:13 -07:00
|
|
|
nsresult Write(nsIObjectOutputStream* aStream,
|
2011-11-03 13:39:08 -07:00
|
|
|
XBLBindingSerializeDetails aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLProtoImplMethod_h__
|