IDBWrapperCache.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "IDBWrapperCache.h"
  6. #include "mozilla/HoldDropJSObjects.h"
  7. #include "nsCOMPtr.h"
  8. #include "nsIScriptGlobalObject.h"
  9. #include "nsPIDOMWindow.h"
  10. namespace mozilla {
  11. namespace dom {
  12. NS_IMPL_CYCLE_COLLECTION_CLASS(IDBWrapperCache)
  13. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBWrapperCache,
  14. DOMEventTargetHelper)
  15. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
  16. NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBWrapperCache,
  17. DOMEventTargetHelper)
  18. if (tmp->mScriptOwner) {
  19. tmp->mScriptOwner = nullptr;
  20. mozilla::DropJSObjects(tmp);
  21. }
  22. NS_IMPL_CYCLE_COLLECTION_UNLINK_END
  23. NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBWrapperCache,
  24. DOMEventTargetHelper)
  25. // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
  26. // DOMEventTargetHelper does it for us.
  27. NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
  28. NS_IMPL_CYCLE_COLLECTION_TRACE_END
  29. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBWrapperCache)
  30. NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
  31. NS_IMPL_ADDREF_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
  32. NS_IMPL_RELEASE_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
  33. IDBWrapperCache::IDBWrapperCache(DOMEventTargetHelper* aOwner)
  34. : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
  35. { }
  36. IDBWrapperCache::IDBWrapperCache(nsPIDOMWindowInner* aOwner)
  37. : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
  38. { }
  39. IDBWrapperCache::~IDBWrapperCache()
  40. {
  41. mScriptOwner = nullptr;
  42. ReleaseWrapper(this);
  43. mozilla::DropJSObjects(this);
  44. }
  45. void
  46. IDBWrapperCache::SetScriptOwner(JSObject* aScriptOwner)
  47. {
  48. MOZ_ASSERT(aScriptOwner);
  49. mScriptOwner = aScriptOwner;
  50. mozilla::HoldJSObjects(this);
  51. }
  52. #ifdef DEBUG
  53. void
  54. IDBWrapperCache::AssertIsRooted() const
  55. {
  56. MOZ_ASSERT(IsJSHolder(const_cast<IDBWrapperCache*>(this)),
  57. "Why aren't we rooted?!");
  58. }
  59. #endif
  60. } // namespace dom
  61. } // namespace mozilla