2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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;
|
|
|
|
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit nsXBLParameter(const nsAString& aName) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
2015-03-26 17:01:12 -07:00
|
|
|
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-09-01 17:49:25 -07:00
|
|
|
explicit 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,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) override;
|
2015-03-13 12:05:57 -07:00
|
|
|
virtual nsresult CompileMember(mozilla::dom::AutoJSAPI& jsapi, const nsString& aClassStr,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::Handle<JSObject*> aClassObject) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) override;
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
nsresult Read(nsIObjectInputStream* aStream);
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult Write(nsIObjectOutputStream* aStream) 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-09-01 17:49:25 -07:00
|
|
|
explicit nsXBLProtoImplAnonymousMethod(const char16_t* aName) :
|
2013-08-21 16:45:52 -07:00
|
|
|
nsXBLProtoImplMethod(aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{}
|
|
|
|
|
2014-06-23 16:33:37 -07:00
|
|
|
nsresult Execute(nsIContent* aBoundElement, JSAddonId* aAddonId);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) 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__
|