1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xbl/nsXBLProtoImpl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsXBLProtoImpl_h__ 1.10 +#define nsXBLProtoImpl_h__ 1.11 + 1.12 +#include "nsMemory.h" 1.13 +#include "nsXBLPrototypeHandler.h" 1.14 +#include "nsXBLProtoImplMember.h" 1.15 +#include "nsXBLProtoImplField.h" 1.16 +#include "nsXBLBinding.h" 1.17 + 1.18 +class nsXBLPrototypeBinding; 1.19 +class nsXBLProtoImplAnonymousMethod; 1.20 + 1.21 +class nsXBLProtoImpl MOZ_FINAL 1.22 +{ 1.23 +public: 1.24 + nsXBLProtoImpl() 1.25 + : mPrecompiledMemberHolder(nullptr), 1.26 + mMembers(nullptr), 1.27 + mFields(nullptr), 1.28 + mConstructor(nullptr), 1.29 + mDestructor(nullptr) 1.30 + { 1.31 + MOZ_COUNT_CTOR(nsXBLProtoImpl); 1.32 + } 1.33 + ~nsXBLProtoImpl() 1.34 + { 1.35 + MOZ_COUNT_DTOR(nsXBLProtoImpl); 1.36 + // Note: the constructor and destructor are in mMembers, so we'll 1.37 + // clean them up automatically. 1.38 + delete mMembers; 1.39 + delete mFields; 1.40 + } 1.41 + 1.42 + 1.43 + nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding); 1.44 + 1.45 +private: 1.46 + nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, 1.47 + nsIContent* aBoundElement, 1.48 + JS::MutableHandle<JSObject*> aTargetClassObject, 1.49 + bool* aTargetIsNew); 1.50 + 1.51 +public: 1.52 + nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding); 1.53 + 1.54 + bool LookupMember(JSContext* aCx, nsString& aName, JS::Handle<jsid> aNameAsId, 1.55 + JS::MutableHandle<JSPropertyDescriptor> aDesc, 1.56 + JS::Handle<JSObject*> aClassObject); 1.57 + 1.58 + void SetMemberList(nsXBLProtoImplMember* aMemberList) 1.59 + { 1.60 + delete mMembers; 1.61 + mMembers = aMemberList; 1.62 + } 1.63 + 1.64 + void SetFieldList(nsXBLProtoImplField* aFieldList) 1.65 + { 1.66 + delete mFields; 1.67 + mFields = aFieldList; 1.68 + } 1.69 + 1.70 + void Trace(const TraceCallbacks& aCallbacks, void *aClosure); 1.71 + void UnlinkJSObjects(); 1.72 + 1.73 + nsXBLProtoImplField* FindField(const nsString& aFieldName) const; 1.74 + 1.75 + // Resolve all the fields for this implementation on the object |obj| False 1.76 + // return means a JS exception was set. 1.77 + bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const; 1.78 + 1.79 + // Undefine all our fields from object |obj| (which should be a 1.80 + // JSObject for a bound element). 1.81 + void UndefineFields(JSContext* cx, JS::Handle<JSObject*> obj) const; 1.82 + 1.83 + bool CompiledMembers() const { 1.84 + return mPrecompiledMemberHolder != nullptr; 1.85 + } 1.86 + 1.87 + nsresult Read(nsIObjectInputStream* aStream, 1.88 + nsXBLPrototypeBinding* aBinding); 1.89 + nsresult Write(nsIObjectOutputStream* aStream, 1.90 + nsXBLPrototypeBinding* aBinding); 1.91 + 1.92 +protected: 1.93 + // used by Read to add each member 1.94 + nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember, 1.95 + nsXBLProtoImplMember* aPreviousMember) 1.96 + { 1.97 + if (aPreviousMember) 1.98 + aPreviousMember->SetNext(aMember); 1.99 + else 1.100 + mMembers = aMember; 1.101 + return aMember; 1.102 + } 1.103 + 1.104 + void DestroyMembers(); 1.105 + 1.106 +public: 1.107 + nsCString mClassName; // The name of the class. 1.108 + 1.109 +protected: 1.110 + JSObject* mPrecompiledMemberHolder; // The class object for the binding. We'll use this to pre-compile properties 1.111 + // and methods for the binding. 1.112 + 1.113 + nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list. 1.114 + 1.115 + nsXBLProtoImplField* mFields; // Our fields 1.116 + 1.117 +public: 1.118 + nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor. 1.119 + nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor. 1.120 +}; 1.121 + 1.122 +nsresult 1.123 +NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding, 1.124 + const char16_t* aClassName, 1.125 + nsXBLProtoImpl** aResult); 1.126 + 1.127 +#endif // nsXBLProtoImpl_h__