2015-05-03 22:32:37 +03: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 15:12:37 +04: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/. */
|
2001-11-13 07:09:56 +03:00
|
|
|
|
|
|
|
#ifndef nsXBLProtoImplMethod_h__
|
|
|
|
#define nsXBLProtoImplMethod_h__
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2001-11-13 07:09:56 +03:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsString.h"
|
2013-06-18 14:00:38 +04:00
|
|
|
#include "nsXBLMaybeCompiled.h"
|
2001-11-13 07:09:56 +03:00
|
|
|
#include "nsXBLProtoImplMember.h"
|
2011-11-04 00:39:08 +04:00
|
|
|
#include "nsXBLSerialize.h"
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2013-03-22 04:05:20 +04:00
|
|
|
class nsIContent;
|
|
|
|
|
2001-11-13 07:09:56 +03:00
|
|
|
struct nsXBLParameter {
|
|
|
|
nsXBLParameter* mNext;
|
|
|
|
char* mName;
|
|
|
|
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsXBLParameter(const nsAString& aName) {
|
2001-11-13 07:09:56 +03:00
|
|
|
MOZ_COUNT_CTOR(nsXBLParameter);
|
|
|
|
mName = ToNewCString(aName);
|
2012-07-30 18:20:58 +04:00
|
|
|
mNext = nullptr;
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~nsXBLParameter() {
|
|
|
|
MOZ_COUNT_DTOR(nsXBLParameter);
|
2015-03-27 03:01:12 +03:00
|
|
|
free(mName);
|
2008-12-15 14:33:56 +03:00
|
|
|
NS_CONTENT_DELETE_LIST_MEMBER(nsXBLParameter, this, mNext);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsXBLUncompiledMethod {
|
|
|
|
nsXBLParameter* mParameters;
|
|
|
|
nsXBLParameter* mLastParameter;
|
2003-06-24 05:20:40 +04:00
|
|
|
nsXBLTextWithLineNumber mBodyText;
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2003-06-24 05:20:40 +04:00
|
|
|
nsXBLUncompiledMethod() :
|
2012-07-30 18:20:58 +04:00
|
|
|
mParameters(nullptr),
|
|
|
|
mLastParameter(nullptr),
|
2003-06-24 05:20:40 +04:00
|
|
|
mBodyText()
|
|
|
|
{
|
2001-11-13 07:09:56 +03:00
|
|
|
MOZ_COUNT_CTOR(nsXBLUncompiledMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsXBLUncompiledMethod() {
|
|
|
|
MOZ_COUNT_DTOR(nsXBLUncompiledMethod);
|
|
|
|
delete mParameters;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetParameterCount() {
|
|
|
|
int32_t result = 0;
|
2001-11-13 07:09:56 +03:00
|
|
|
for (nsXBLParameter* curr = mParameters; curr; curr=curr->mNext)
|
|
|
|
result++;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:46:13 +03:00
|
|
|
void AppendBodyText(const nsAString& aText) {
|
2003-06-24 05:20:40 +04:00
|
|
|
mBodyText.AppendText(aText);
|
2001-11-13 07:09:56 +03:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:46:13 +03:00
|
|
|
void AddParameter(const nsAString& aText) {
|
2001-11-13 07:09:56 +03:00
|
|
|
nsXBLParameter* param = new nsXBLParameter(aText);
|
|
|
|
if (!param)
|
|
|
|
return;
|
|
|
|
if (!mParameters)
|
|
|
|
mParameters = param;
|
|
|
|
else
|
|
|
|
mLastParameter->mNext = param;
|
|
|
|
mLastParameter = param;
|
|
|
|
}
|
2003-06-24 05:20:40 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetLineNumber(uint32_t aLineNumber) {
|
2003-06-24 05:20:40 +04:00
|
|
|
mBodyText.SetLineNumber(aLineNumber);
|
|
|
|
}
|
2001-11-13 07:09:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsXBLProtoImplMethod: public nsXBLProtoImplMember
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsXBLProtoImplMethod(const char16_t* aName);
|
2001-11-13 07:09:56 +03:00
|
|
|
virtual ~nsXBLProtoImplMethod();
|
|
|
|
|
2002-03-24 01:46:13 +03:00
|
|
|
void AppendBodyText(const nsAString& aBody);
|
|
|
|
void AddParameter(const nsAString& aName);
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetLineNumber(uint32_t aLineNumber);
|
2003-06-24 05:20:40 +04:00
|
|
|
|
2013-02-08 18:24:21 +04:00
|
|
|
virtual nsresult InstallMember(JSContext* aCx,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) override;
|
2015-03-13 22:05:57 +03:00
|
|
|
virtual nsresult CompileMember(mozilla::dom::AutoJSAPI& jsapi, const nsString& aClassStr,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::Handle<JSObject*> aClassObject) override;
|
2001-11-13 07:09:56 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure) override;
|
2007-05-24 18:10:02 +04:00
|
|
|
|
2013-08-09 20:25:13 +04:00
|
|
|
nsresult Read(nsIObjectInputStream* aStream);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Write(nsIObjectOutputStream* aStream) override;
|
2011-11-04 00:39:08 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCompiled() const
|
2008-02-12 19:02:41 +03:00
|
|
|
{
|
2013-06-18 14:00:38 +04:00
|
|
|
return mMethod.IsCompiled();
|
2008-02-12 19:02:41 +03:00
|
|
|
}
|
2013-06-18 14:00:38 +04:00
|
|
|
|
2008-02-12 19:02:41 +03:00
|
|
|
void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
|
|
|
|
{
|
2013-06-18 14:00:38 +04:00
|
|
|
mMethod.SetUncompiled(aUncompiledMethod);
|
2008-02-12 19:02:41 +03:00
|
|
|
}
|
2013-06-18 14:00:38 +04:00
|
|
|
|
2008-02-12 19:02:41 +03:00
|
|
|
nsXBLUncompiledMethod* GetUncompiledMethod() const
|
|
|
|
{
|
2013-06-18 14:00:38 +04:00
|
|
|
return mMethod.GetUncompiled();
|
2008-02-12 19:02:41 +03:00
|
|
|
}
|
|
|
|
|
2001-11-13 07:09:56 +03:00
|
|
|
protected:
|
2013-06-18 14:00:38 +04:00
|
|
|
void SetCompiledMethod(JSObject* aCompiledMethod)
|
|
|
|
{
|
|
|
|
mMethod.SetJSFunction(aCompiledMethod);
|
|
|
|
}
|
2008-02-12 19:02:41 +03:00
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
JSObject* GetCompiledMethod() const
|
|
|
|
{
|
|
|
|
return mMethod.GetJSFunction();
|
|
|
|
}
|
2005-02-06 23:34:15 +03:00
|
|
|
|
2013-11-22 01:19:46 +04:00
|
|
|
JSObject* GetCompiledMethodPreserveColor() const
|
|
|
|
{
|
|
|
|
return mMethod.GetJSFunctionPreserveColor();
|
|
|
|
}
|
|
|
|
|
2013-06-18 14:00:38 +04:00
|
|
|
JS::Heap<nsXBLMaybeCompiled<nsXBLUncompiledMethod> > mMethod;
|
2001-11-13 07:09:56 +03:00
|
|
|
};
|
|
|
|
|
2004-09-10 19:29:19 +04:00
|
|
|
class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsXBLProtoImplAnonymousMethod(const char16_t* aName) :
|
2013-08-22 03:45:52 +04:00
|
|
|
nsXBLProtoImplMethod(aName)
|
2004-09-10 19:29:19 +04:00
|
|
|
{}
|
|
|
|
|
2014-06-24 03:33:37 +04:00
|
|
|
nsresult Execute(nsIContent* aBoundElement, JSAddonId* aAddonId);
|
2004-09-10 19:29:19 +04: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 18:24:21 +04:00
|
|
|
virtual nsresult InstallMember(JSContext* aCx,
|
2015-03-21 19:28:04 +03:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) override {
|
2004-09-10 19:29:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-04 00:39:08 +04:00
|
|
|
|
2011-11-16 11:50:18 +04:00
|
|
|
using nsXBLProtoImplMethod::Write;
|
2013-08-09 20:25:13 +04:00
|
|
|
nsresult Write(nsIObjectOutputStream* aStream,
|
2011-11-04 00:39:08 +04:00
|
|
|
XBLBindingSerializeDetails aType);
|
2004-09-10 19:29:19 +04:00
|
|
|
};
|
|
|
|
|
2001-11-13 07:09:56 +03:00
|
|
|
#endif // nsXBLProtoImplMethod_h__
|