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