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 nsXBLProtoImpl_h__
|
|
|
|
#define nsXBLProtoImpl_h__
|
|
|
|
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsXBLPrototypeHandler.h"
|
|
|
|
#include "nsXBLProtoImplMember.h"
|
2007-09-28 06:45:01 -07:00
|
|
|
#include "nsXBLProtoImplField.h"
|
2013-02-08 06:24:20 -08:00
|
|
|
#include "nsXBLBinding.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIXPConnectJSObjectHolder;
|
2007-09-28 06:45:01 -07:00
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
class nsXBLProtoImplAnonymousMethod;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsXBLProtoImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXBLProtoImpl()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mClassObject(nullptr),
|
|
|
|
mMembers(nullptr),
|
|
|
|
mFields(nullptr),
|
|
|
|
mConstructor(nullptr),
|
|
|
|
mDestructor(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsXBLProtoImpl);
|
2007-04-23 07:21:53 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsXBLProtoImpl()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXBLProtoImpl);
|
|
|
|
// Note: the constructor and destructor are in mMembers, so we'll
|
|
|
|
// clean them up automatically.
|
2007-09-28 06:45:01 -07:00
|
|
|
delete mMembers;
|
|
|
|
delete mFields;
|
2007-04-23 07:21:53 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 06:24:20 -08:00
|
|
|
nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, nsIScriptContext* aContext,
|
|
|
|
nsIContent* aBoundElement,
|
|
|
|
nsIXPConnectJSObjectHolder** aScriptObjectHolder,
|
2013-04-05 06:21:03 -07:00
|
|
|
JS::MutableHandle<JSObject*> aTargetClassObject,
|
2013-02-08 06:24:20 -08:00
|
|
|
bool* aTargetIsNew);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding);
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
bool LookupMember(JSContext* aCx, nsString& aName, JS::HandleId aNameAsId,
|
|
|
|
JSPropertyDescriptor* aDesc, JSObject* aClassObject);
|
|
|
|
|
2007-09-28 06:45:01 -07:00
|
|
|
void SetMemberList(nsXBLProtoImplMember* aMemberList)
|
|
|
|
{
|
|
|
|
delete mMembers;
|
|
|
|
mMembers = aMemberList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFieldList(nsXBLProtoImplField* aFieldList)
|
|
|
|
{
|
|
|
|
delete mFields;
|
|
|
|
mFields = aFieldList;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-27 04:50:49 -07:00
|
|
|
void Trace(const TraceCallbacks& aCallbacks, void *aClosure);
|
2008-01-29 18:05:43 -08:00
|
|
|
void UnlinkJSObjects();
|
2007-09-28 06:45:01 -07:00
|
|
|
|
|
|
|
nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
|
|
|
|
|
|
|
|
// Resolve all the fields for this implementation on the object |obj| False
|
|
|
|
// return means a JS exception was set.
|
2013-04-05 06:21:03 -07:00
|
|
|
bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2007-10-19 21:22:43 -07:00
|
|
|
// Undefine all our fields from object |obj| (which should be a
|
|
|
|
// JSObject for a bound element).
|
2013-04-05 06:21:03 -07:00
|
|
|
void UndefineFields(JSContext* cx, JS::Handle<JSObject*> obj) const;
|
2007-10-19 21:22:43 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CompiledMembers() const {
|
2012-07-30 07:20:58 -07:00
|
|
|
return mClassObject != nullptr;
|
2007-10-05 18:23:09 -07:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult Read(nsIScriptContext* aContext,
|
|
|
|
nsIObjectInputStream* aStream,
|
|
|
|
nsXBLPrototypeBinding* aBinding,
|
|
|
|
nsIScriptGlobalObject* aGlobal);
|
|
|
|
nsresult Write(nsIScriptContext* aContext,
|
|
|
|
nsIObjectOutputStream* aStream,
|
|
|
|
nsXBLPrototypeBinding* aBinding);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2011-11-03 13:39:08 -07:00
|
|
|
// used by Read to add each member
|
|
|
|
nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember,
|
|
|
|
nsXBLProtoImplMember* aPreviousMember)
|
|
|
|
{
|
|
|
|
if (aPreviousMember)
|
|
|
|
aPreviousMember->SetNext(aMember);
|
|
|
|
else
|
|
|
|
mMembers = aMember;
|
|
|
|
return aMember;
|
|
|
|
}
|
|
|
|
|
2008-02-12 08:02:41 -08:00
|
|
|
void DestroyMembers();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
nsCString mClassName; // The name of the class.
|
|
|
|
|
|
|
|
protected:
|
2011-11-15 23:50:20 -08:00
|
|
|
JSObject* mClassObject; // The class object for the binding. We'll use this to pre-compile properties
|
|
|
|
// and methods for the binding.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list.
|
2007-09-28 06:45:01 -07:00
|
|
|
|
|
|
|
nsXBLProtoImplField* mFields; // Our fields
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor.
|
|
|
|
nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor.
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding,
|
|
|
|
const PRUnichar* aClassName,
|
|
|
|
nsXBLProtoImpl** aResult);
|
|
|
|
|
|
|
|
#endif // nsXBLProtoImpl_h__
|