Bug 1183484 - Cycle collect FontFaceSetIterator. r=bzbarsky, a=lmandel
authorCameron McCormack <cam@mcc.id.au>
Thu, 16 Jul 2015 17:35:17 +1000
changeset 275380 c8ade2012d88b6d9544c0e57572188f77625dd29
parent 275379 9190dedf78a2e06e218ee262e872da8c0f24541e
child 275381 a7706082d5aa661ffdefa95ca4d5799f0dd8dfa7
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, lmandel
bugs1183484
milestone40.0
Bug 1183484 - Cycle collect FontFaceSetIterator. r=bzbarsky, a=lmandel
layout/style/FontFaceSet.cpp
layout/style/FontFaceSet.h
layout/style/FontFaceSetIterator.cpp
layout/style/FontFaceSetIterator.h
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -347,26 +347,28 @@ FontFaceSet::Size()
   mPresContext->FlushUserFontSet();
 
   // Web IDL objects can only expose array index properties up to INT32_MAX.
 
   size_t total = mRuleFaces.Length() + mNonRuleFaces.Length();
   return std::min<size_t>(total, INT32_MAX);
 }
 
-FontFaceSetIterator*
+already_AddRefed<FontFaceSetIterator>
 FontFaceSet::Entries()
 {
-  return new FontFaceSetIterator(this, true);
+  nsRefPtr<FontFaceSetIterator> it = new FontFaceSetIterator(this, true);
+  return it.forget();
 }
 
-FontFaceSetIterator*
+already_AddRefed<FontFaceSetIterator>
 FontFaceSet::Values()
 {
-  return new FontFaceSetIterator(this, false);
+  nsRefPtr<FontFaceSetIterator> it = new FontFaceSetIterator(this, false);
+  return it.forget();
 }
 
 void
 FontFaceSet::ForEach(JSContext* aCx,
                      FontFaceSetForEachCallback& aCallback,
                      JS::Handle<JS::Value> aThisArg,
                      ErrorResult& aRv)
 {
--- a/layout/style/FontFaceSet.h
+++ b/layout/style/FontFaceSet.h
@@ -173,18 +173,18 @@ public:
   mozilla::dom::Promise* GetReady(mozilla::ErrorResult& aRv);
   mozilla::dom::FontFaceSetLoadStatus Status();
 
   FontFaceSet* Add(FontFace& aFontFace, mozilla::ErrorResult& aRv);
   void Clear();
   bool Delete(FontFace& aFontFace, mozilla::ErrorResult& aRv);
   bool Has(FontFace& aFontFace);
   uint32_t Size();
-  mozilla::dom::FontFaceSetIterator* Entries();
-  mozilla::dom::FontFaceSetIterator* Values();
+  already_AddRefed<mozilla::dom::FontFaceSetIterator> Entries();
+  already_AddRefed<mozilla::dom::FontFaceSetIterator> Values();
   void ForEach(JSContext* aCx, FontFaceSetForEachCallback& aCallback,
                JS::Handle<JS::Value> aThisArg,
                mozilla::ErrorResult& aRv);
 
 private:
   ~FontFaceSet();
 
   /**
--- a/layout/style/FontFaceSetIterator.cpp
+++ b/layout/style/FontFaceSetIterator.cpp
@@ -3,16 +3,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/FontFaceSetIterator.h"
 
 namespace mozilla {
 namespace dom {
 
+NS_IMPL_CYCLE_COLLECTION(FontFaceSetIterator, mFontFaceSet)
+
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(FontFaceSetIterator, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(FontFaceSetIterator, Release)
+
 FontFaceSetIterator::FontFaceSetIterator(FontFaceSet* aFontFaceSet,
                                          bool aIsKeyAndValue)
   : mFontFaceSet(aFontFaceSet)
   , mNextIndex(0)
   , mIsKeyAndValue(aIsKeyAndValue)
 {
   MOZ_COUNT_CTOR(FontFaceSetIterator);
 }
--- a/layout/style/FontFaceSetIterator.h
+++ b/layout/style/FontFaceSetIterator.h
@@ -7,32 +7,36 @@
 #define mozilla_dom_FontFaceSetIterator_h
 
 #include "mozilla/dom/FontFaceSetBinding.h"
 #include "mozilla/dom/NonRefcountedDOMObject.h"
 
 namespace mozilla {
 namespace dom {
 
-class FontFaceSetIterator final : public NonRefcountedDOMObject
+class FontFaceSetIterator final
 {
 public:
   FontFaceSetIterator(mozilla::dom::FontFaceSet* aFontFaceSet,
                       bool aIsKeyAndValue);
-  ~FontFaceSetIterator();
+
+  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(FontFaceSetIterator)
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(FontFaceSetIterator)
 
   bool WrapObject(JSContext* aCx,
                   JS::Handle<JSObject*> aGivenProto,
                   JS::MutableHandle<JSObject*> aReflector);
 
   // WebIDL
   void Next(JSContext* aCx, FontFaceSetIteratorResult& aResult,
             mozilla::ErrorResult& aRv);
 
 private:
+  ~FontFaceSetIterator();
+
   nsRefPtr<FontFaceSet> mFontFaceSet;
   uint32_t mNextIndex;
   bool mIsKeyAndValue;
 };
 
 } // namespace dom
 } // namespace mozilla