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