michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXBLProtoImpl_h__ michael@0: #define nsXBLProtoImpl_h__ michael@0: michael@0: #include "nsMemory.h" michael@0: #include "nsXBLPrototypeHandler.h" michael@0: #include "nsXBLProtoImplMember.h" michael@0: #include "nsXBLProtoImplField.h" michael@0: #include "nsXBLBinding.h" michael@0: michael@0: class nsXBLPrototypeBinding; michael@0: class nsXBLProtoImplAnonymousMethod; michael@0: michael@0: class nsXBLProtoImpl MOZ_FINAL michael@0: { michael@0: public: michael@0: nsXBLProtoImpl() michael@0: : mPrecompiledMemberHolder(nullptr), michael@0: mMembers(nullptr), michael@0: mFields(nullptr), michael@0: mConstructor(nullptr), michael@0: mDestructor(nullptr) michael@0: { michael@0: MOZ_COUNT_CTOR(nsXBLProtoImpl); michael@0: } michael@0: ~nsXBLProtoImpl() michael@0: { michael@0: MOZ_COUNT_DTOR(nsXBLProtoImpl); michael@0: // Note: the constructor and destructor are in mMembers, so we'll michael@0: // clean them up automatically. michael@0: delete mMembers; michael@0: delete mFields; michael@0: } michael@0: michael@0: michael@0: nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding); michael@0: michael@0: private: michael@0: nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, michael@0: nsIContent* aBoundElement, michael@0: JS::MutableHandle aTargetClassObject, michael@0: bool* aTargetIsNew); michael@0: michael@0: public: michael@0: nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding); michael@0: michael@0: bool LookupMember(JSContext* aCx, nsString& aName, JS::Handle aNameAsId, michael@0: JS::MutableHandle aDesc, michael@0: JS::Handle aClassObject); michael@0: michael@0: void SetMemberList(nsXBLProtoImplMember* aMemberList) michael@0: { michael@0: delete mMembers; michael@0: mMembers = aMemberList; michael@0: } michael@0: michael@0: void SetFieldList(nsXBLProtoImplField* aFieldList) michael@0: { michael@0: delete mFields; michael@0: mFields = aFieldList; michael@0: } michael@0: michael@0: void Trace(const TraceCallbacks& aCallbacks, void *aClosure); michael@0: void UnlinkJSObjects(); michael@0: michael@0: nsXBLProtoImplField* FindField(const nsString& aFieldName) const; michael@0: michael@0: // Resolve all the fields for this implementation on the object |obj| False michael@0: // return means a JS exception was set. michael@0: bool ResolveAllFields(JSContext *cx, JS::Handle obj) const; michael@0: michael@0: // Undefine all our fields from object |obj| (which should be a michael@0: // JSObject for a bound element). michael@0: void UndefineFields(JSContext* cx, JS::Handle obj) const; michael@0: michael@0: bool CompiledMembers() const { michael@0: return mPrecompiledMemberHolder != nullptr; michael@0: } michael@0: michael@0: nsresult Read(nsIObjectInputStream* aStream, michael@0: nsXBLPrototypeBinding* aBinding); michael@0: nsresult Write(nsIObjectOutputStream* aStream, michael@0: nsXBLPrototypeBinding* aBinding); michael@0: michael@0: protected: michael@0: // used by Read to add each member michael@0: nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember, michael@0: nsXBLProtoImplMember* aPreviousMember) michael@0: { michael@0: if (aPreviousMember) michael@0: aPreviousMember->SetNext(aMember); michael@0: else michael@0: mMembers = aMember; michael@0: return aMember; michael@0: } michael@0: michael@0: void DestroyMembers(); michael@0: michael@0: public: michael@0: nsCString mClassName; // The name of the class. michael@0: michael@0: protected: michael@0: JSObject* mPrecompiledMemberHolder; // The class object for the binding. We'll use this to pre-compile properties michael@0: // and methods for the binding. michael@0: michael@0: nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list. michael@0: michael@0: nsXBLProtoImplField* mFields; // Our fields michael@0: michael@0: public: michael@0: nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor. michael@0: nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor. michael@0: }; michael@0: michael@0: nsresult michael@0: NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding, michael@0: const char16_t* aClassName, michael@0: nsXBLProtoImpl** aResult); michael@0: michael@0: #endif // nsXBLProtoImpl_h__