nsXBLProtoImpl.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* -*- Mode: C++; tab-width: 8; 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. #ifndef nsXBLProtoImpl_h__
  6. #define nsXBLProtoImpl_h__
  7. #include "nsMemory.h"
  8. #include "nsXBLPrototypeHandler.h"
  9. #include "nsXBLProtoImplMember.h"
  10. #include "nsXBLProtoImplField.h"
  11. #include "nsXBLBinding.h"
  12. class nsXBLPrototypeBinding;
  13. class nsXBLProtoImplAnonymousMethod;
  14. class nsXBLProtoImpl final
  15. {
  16. public:
  17. nsXBLProtoImpl()
  18. : mPrecompiledMemberHolder(nullptr),
  19. mMembers(nullptr),
  20. mFields(nullptr),
  21. mConstructor(nullptr),
  22. mDestructor(nullptr)
  23. {
  24. MOZ_COUNT_CTOR(nsXBLProtoImpl);
  25. }
  26. ~nsXBLProtoImpl()
  27. {
  28. MOZ_COUNT_DTOR(nsXBLProtoImpl);
  29. // Note: the constructor and destructor are in mMembers, so we'll
  30. // clean them up automatically.
  31. delete mMembers;
  32. delete mFields;
  33. }
  34. nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding);
  35. private:
  36. nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding,
  37. nsIContent* aBoundElement,
  38. JS::MutableHandle<JSObject*> aTargetClassObject,
  39. bool* aTargetIsNew);
  40. public:
  41. nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding);
  42. bool LookupMember(JSContext* aCx, nsString& aName, JS::Handle<jsid> aNameAsId,
  43. JS::MutableHandle<JS::PropertyDescriptor> aDesc,
  44. JS::Handle<JSObject*> aClassObject);
  45. void SetMemberList(nsXBLProtoImplMember* aMemberList)
  46. {
  47. delete mMembers;
  48. mMembers = aMemberList;
  49. }
  50. void SetFieldList(nsXBLProtoImplField* aFieldList)
  51. {
  52. delete mFields;
  53. mFields = aFieldList;
  54. }
  55. void Trace(const TraceCallbacks& aCallbacks, void *aClosure);
  56. void UnlinkJSObjects();
  57. nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
  58. // Resolve all the fields for this implementation on the object |obj| False
  59. // return means a JS exception was set.
  60. bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const;
  61. // Undefine all our fields from object |obj| (which should be a
  62. // JSObject for a bound element).
  63. void UndefineFields(JSContext* cx, JS::Handle<JSObject*> obj) const;
  64. bool CompiledMembers() const {
  65. return mPrecompiledMemberHolder != nullptr;
  66. }
  67. nsresult Read(nsIObjectInputStream* aStream,
  68. nsXBLPrototypeBinding* aBinding);
  69. nsresult Write(nsIObjectOutputStream* aStream,
  70. nsXBLPrototypeBinding* aBinding);
  71. protected:
  72. // used by Read to add each member
  73. nsXBLProtoImplMember* AddMember(nsXBLProtoImplMember* aMember,
  74. nsXBLProtoImplMember* aPreviousMember)
  75. {
  76. if (aPreviousMember)
  77. aPreviousMember->SetNext(aMember);
  78. else
  79. mMembers = aMember;
  80. return aMember;
  81. }
  82. void DestroyMembers();
  83. public:
  84. nsString mClassName; // The name of the class.
  85. protected:
  86. JSObject* mPrecompiledMemberHolder; // The class object for the binding. We'll use this to pre-compile properties
  87. // and methods for the binding.
  88. nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list.
  89. nsXBLProtoImplField* mFields; // Our fields
  90. public:
  91. nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor.
  92. nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor.
  93. };
  94. void
  95. NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding,
  96. const char16_t* aClassName,
  97. nsXBLProtoImpl** aResult);
  98. #endif // nsXBLProtoImpl_h__