dom/xbl/nsXBLProtoImpl.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:eb901451ea9c
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef nsXBLProtoImpl_h__
7 #define nsXBLProtoImpl_h__
8
9 #include "nsMemory.h"
10 #include "nsXBLPrototypeHandler.h"
11 #include "nsXBLProtoImplMember.h"
12 #include "nsXBLProtoImplField.h"
13 #include "nsXBLBinding.h"
14
15 class nsXBLPrototypeBinding;
16 class nsXBLProtoImplAnonymousMethod;
17
18 class nsXBLProtoImpl MOZ_FINAL
19 {
20 public:
21 nsXBLProtoImpl()
22 : mPrecompiledMemberHolder(nullptr),
23 mMembers(nullptr),
24 mFields(nullptr),
25 mConstructor(nullptr),
26 mDestructor(nullptr)
27 {
28 MOZ_COUNT_CTOR(nsXBLProtoImpl);
29 }
30 ~nsXBLProtoImpl()
31 {
32 MOZ_COUNT_DTOR(nsXBLProtoImpl);
33 // Note: the constructor and destructor are in mMembers, so we'll
34 // clean them up automatically.
35 delete mMembers;
36 delete mFields;
37 }
38
39
40 nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding);
41
42 private:
43 nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding,
44 nsIContent* aBoundElement,
45 JS::MutableHandle<JSObject*> aTargetClassObject,
46 bool* aTargetIsNew);
47
48 public:
49 nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding);
50
51 bool LookupMember(JSContext* aCx, nsString& aName, JS::Handle<jsid> aNameAsId,
52 JS::MutableHandle<JSPropertyDescriptor> aDesc,
53 JS::Handle<JSObject*> aClassObject);
54
55 void SetMemberList(nsXBLProtoImplMember* aMemberList)
56 {
57 delete mMembers;
58 mMembers = aMemberList;
59 }
60
61 void SetFieldList(nsXBLProtoImplField* aFieldList)
62 {
63 delete mFields;
64 mFields = aFieldList;
65 }
66
67 void Trace(const TraceCallbacks& aCallbacks, void *aClosure);
68 void UnlinkJSObjects();
69
70 nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
71
72 // Resolve all the fields for this implementation on the object |obj| False
73 // return means a JS exception was set.
74 bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
75
76 // Undefine all our fields from object |obj| (which should be a
77 // JSObject for a bound element).
78 void UndefineFields(JSContext* cx, JS::Handle<JSObject*> obj) const;
79
80 bool CompiledMembers() const {
81 return mPrecompiledMemberHolder != nullptr;
82 }
83
84 nsresult Read(nsIObjectInputStream* aStream,
85 nsXBLPrototypeBinding* aBinding);
86 nsresult Write(nsIObjectOutputStream* aStream,
87 nsXBLPrototypeBinding* aBinding);
88
89 protected:
90 // used by Read to add each member
91 nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember,
92 nsXBLProtoImplMember* aPreviousMember)
93 {
94 if (aPreviousMember)
95 aPreviousMember->SetNext(aMember);
96 else
97 mMembers = aMember;
98 return aMember;
99 }
100
101 void DestroyMembers();
102
103 public:
104 nsCString mClassName; // The name of the class.
105
106 protected:
107 JSObject* mPrecompiledMemberHolder; // The class object for the binding. We'll use this to pre-compile properties
108 // and methods for the binding.
109
110 nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list.
111
112 nsXBLProtoImplField* mFields; // Our fields
113
114 public:
115 nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor.
116 nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor.
117 };
118
119 nsresult
120 NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding,
121 const char16_t* aClassName,
122 nsXBLProtoImpl** aResult);
123
124 #endif // nsXBLProtoImpl_h__

mercurial