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__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#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:
|
|
|
|
nsXBLProtoImplMethod(const PRUnichar* aName);
|
|
|
|
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 14:56:10 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsresult CompileMember(nsIScriptContext* aContext,
|
|
|
|
const nsCString& aClassStr,
|
2013-05-29 14:56:10 -07:00
|
|
|
JS::Handle<JSObject*> aClassObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 14:56:10 -07:00
|
|
|
virtual void Trace(const TraceCallbacks& aCallbacks, void *aClosure);
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult Read(nsIScriptContext* aContext, nsIObjectInputStream* aStream);
|
2013-05-29 14:56:10 -07:00
|
|
|
virtual nsresult Write(nsIScriptContext* aContext, nsIObjectOutputStream* aStream);
|
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
|
|
|
{
|
|
|
|
return !(mUncompiledMethod & BIT_UNCOMPILED);
|
|
|
|
}
|
|
|
|
void SetUncompiledMethod(nsXBLUncompiledMethod* aUncompiledMethod)
|
|
|
|
{
|
2012-09-14 13:09:52 -07:00
|
|
|
mUncompiledMethod = uintptr_t(aUncompiledMethod) | BIT_UNCOMPILED;
|
2008-02-12 08:02:41 -08:00
|
|
|
}
|
|
|
|
nsXBLUncompiledMethod* GetUncompiledMethod() const
|
|
|
|
{
|
2012-09-14 13:09:52 -07:00
|
|
|
uintptr_t unmasked = mUncompiledMethod & ~BIT_UNCOMPILED;
|
2008-02-12 08:02:41 -08:00
|
|
|
return reinterpret_cast<nsXBLUncompiledMethod*>(unmasked);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2008-02-12 08:02:41 -08:00
|
|
|
enum { BIT_UNCOMPILED = 1 << 0 };
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
union {
|
2012-09-14 13:09:52 -07:00
|
|
|
uintptr_t mUncompiledMethod; // An object that represents the method before being compiled.
|
2008-02-12 08:02:41 -08:00
|
|
|
JSObject* mJSMethodObject; // The JS object for the method (after compilation)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-10-05 18:23:09 -07:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsCompiled;
|
2007-10-05 18:23:09 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod {
|
|
|
|
public:
|
|
|
|
nsXBLProtoImplAnonymousMethod() :
|
|
|
|
nsXBLProtoImplMethod(EmptyString().get())
|
|
|
|
{}
|
|
|
|
|
|
|
|
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 14:56:10 -07:00
|
|
|
JS::Handle<JSObject*> aTargetClassObject) {
|
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;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult Write(nsIScriptContext* aContext,
|
|
|
|
nsIObjectOutputStream* aStream,
|
|
|
|
XBLBindingSerializeDetails aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXBLProtoImplMethod_h__
|