Bug 1234707: Make nsDOMCSSValueList::AppendCSSValue() take an already_AddRefed arg (instead of a raw pointer, usually with refcount of 0). r=heycam
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 23 Dec 2015 16:25:43 -0800
changeset 299735 64671f01cb7bcd1c7113b464933f8f0d78b0a758
parent 299734 200ab9a3b18aa2d0ad6fa2834f5191b009671232
child 299736 79e7505bce80ff259d5540c0b07bac7e7f25935d
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1234707
milestone46.0a1
Bug 1234707: Make nsDOMCSSValueList::AppendCSSValue() take an already_AddRefed arg (instead of a raw pointer, usually with refcount of 0). r=heycam
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsDOMCSSValueList.cpp
layout/style/nsDOMCSSValueList.h
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -1082,18 +1082,17 @@ nsComputedDOMStyle::DoGetContent()
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword__moz_alt_content);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
   for (uint32_t i = 0, i_end = content->ContentCount(); i < i_end; ++i) {
-    nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
     const nsStyleContentData &data = content->ContentAt(i);
     switch (data.mType) {
       case eStyleContentType_String:
         {
           nsString str;
           nsStyleUtil::AppendEscapedCSSString(
             nsDependentString(data.mContent.mString), str);
@@ -1166,16 +1165,17 @@ nsComputedDOMStyle::DoGetContent()
       case eStyleContentType_NoCloseQuote:
         val->SetIdent(eCSSKeyword_no_close_quote);
         break;
       case eStyleContentType_AltContent:
       default:
         NS_NOTREACHED("unexpected type");
         break;
     }
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetCounterIncrement()
 {
@@ -1185,27 +1185,27 @@ nsComputedDOMStyle::DoGetCounterIncremen
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_none);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
   for (uint32_t i = 0, i_end = content->CounterIncrementCount(); i < i_end; ++i) {
-    nsROCSSPrimitiveValue* name = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(name);
-
-    nsROCSSPrimitiveValue* value = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(value);
+    RefPtr<nsROCSSPrimitiveValue> name = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
 
     const nsStyleCounterData *data = content->GetCounterIncrementAt(i);
     nsAutoString escaped;
     nsStyleUtil::AppendEscapedCSSIdent(data->mCounter, escaped);
     name->SetString(escaped);
     value->SetNumber(data->mValue); // XXX This should really be integer
+
+    valueList->AppendCSSValue(name.forget());
+    valueList->AppendCSSValue(value.forget());
   }
 
   return valueList;
 }
 
 /* Convert the stored representation into a list of two values and then hand
  * it back.
  */
@@ -1217,32 +1217,32 @@ nsComputedDOMStyle::DoGetTransformOrigin
    */
 
   /* Store things as a value list */
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
   /* Now, get the values. */
   const nsStyleDisplay* display = StyleDisplay();
 
-  nsROCSSPrimitiveValue* width = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> width = new nsROCSSPrimitiveValue;
   SetValueToCoord(width, display->mTransformOrigin[0], false,
                   &nsComputedDOMStyle::GetFrameBoundsWidthForTransform);
-  valueList->AppendCSSValue(width);
-
-  nsROCSSPrimitiveValue* height = new nsROCSSPrimitiveValue;
+  valueList->AppendCSSValue(width.forget());
+
+  RefPtr<nsROCSSPrimitiveValue> height = new nsROCSSPrimitiveValue;
   SetValueToCoord(height, display->mTransformOrigin[1], false,
                   &nsComputedDOMStyle::GetFrameBoundsHeightForTransform);
-  valueList->AppendCSSValue(height);
+  valueList->AppendCSSValue(height.forget());
 
   if (display->mTransformOrigin[2].GetUnit() != eStyleUnit_Coord ||
       display->mTransformOrigin[2].GetCoordValue() != 0) {
-    nsROCSSPrimitiveValue* depth = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> depth = new nsROCSSPrimitiveValue;
     SetValueToCoord(depth, display->mTransformOrigin[2], false,
                     nullptr);
-    valueList->AppendCSSValue(depth);
+    valueList->AppendCSSValue(depth.forget());
   }
 
   return valueList;
 }
 
 /* Convert the stored representation into a list of two values and then hand
  * it back.
  */
@@ -1254,25 +1254,25 @@ nsComputedDOMStyle::DoGetPerspectiveOrig
    */
 
   /* Store things as a value list */
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
   /* Now, get the values. */
   const nsStyleDisplay* display = StyleDisplay();
 
-  nsROCSSPrimitiveValue* width = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> width = new nsROCSSPrimitiveValue;
   SetValueToCoord(width, display->mPerspectiveOrigin[0], false,
                   &nsComputedDOMStyle::GetFrameBoundsWidthForTransform);
-  valueList->AppendCSSValue(width);
-
-  nsROCSSPrimitiveValue* height = new nsROCSSPrimitiveValue;
+  valueList->AppendCSSValue(width.forget());
+
+  RefPtr<nsROCSSPrimitiveValue> height = new nsROCSSPrimitiveValue;
   SetValueToCoord(height, display->mPerspectiveOrigin[1], false,
                   &nsComputedDOMStyle::GetFrameBoundsHeightForTransform);
-  valueList->AppendCSSValue(height);
+  valueList->AppendCSSValue(height.forget());
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetPerspective()
 {
     nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
@@ -1427,27 +1427,27 @@ nsComputedDOMStyle::DoGetCounterReset()
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_none);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
   for (uint32_t i = 0, i_end = content->CounterResetCount(); i < i_end; ++i) {
-    nsROCSSPrimitiveValue* name = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(name);
-
-    nsROCSSPrimitiveValue* value = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(value);
+    RefPtr<nsROCSSPrimitiveValue> name = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
 
     const nsStyleCounterData *data = content->GetCounterResetAt(i);
     nsAutoString escaped;
     nsStyleUtil::AppendEscapedCSSIdent(data->mCounter, escaped);
     name->SetString(escaped);
     value->SetNumber(data->mValue); // XXX This should really be integer
+
+    valueList->AppendCSSValue(name.forget());
+    valueList->AppendCSSValue(value.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetQuotes()
 {
@@ -1457,28 +1457,28 @@ nsComputedDOMStyle::DoGetQuotes()
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_none);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
   for (uint32_t i = 0, i_end = quotes->QuotesCount(); i < i_end; ++i) {
-    nsROCSSPrimitiveValue* openVal = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(openVal);
-
-    nsROCSSPrimitiveValue* closeVal = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(closeVal);
+    RefPtr<nsROCSSPrimitiveValue> openVal = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> closeVal = new nsROCSSPrimitiveValue;
 
     nsString s;
     nsStyleUtil::AppendEscapedCSSString(*quotes->OpenQuoteAt(i), s);
     openVal->SetString(s);
     s.Truncate();
     nsStyleUtil::AppendEscapedCSSString(*quotes->CloseQuoteAt(i), s);
     closeVal->SetString(s);
+
+    valueList->AppendCSSValue(openVal.forget());
+    valueList->AppendCSSValue(closeVal.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetFontFamily()
 {
@@ -1797,20 +1797,20 @@ nsComputedDOMStyle::GetBackgroundList(ui
                                       uint32_t nsStyleBackground::* aCount,
                                       const KTableEntry aTable[])
 {
   const nsStyleBackground* bg = StyleBackground();
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = bg->*aCount; i < i_end; ++i) {
-    nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     val->SetIdent(nsCSSProps::ValueToKeywordEnum(bg->mLayers[i].*aMember,
                                                  aTable));
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundAttachment()
 {
@@ -2046,25 +2046,25 @@ nsComputedDOMStyle::GetCSSGradientString
 void
 nsComputedDOMStyle::GetImageRectString(nsIURI* aURI,
                                        const nsStyleSides& aCropRect,
                                        nsString& aString)
 {
   RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
 
   // <uri>
-  nsROCSSPrimitiveValue *valURI = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(valURI);
+  RefPtr<nsROCSSPrimitiveValue> valURI = new nsROCSSPrimitiveValue;
   valURI->SetURI(aURI);
+  valueList->AppendCSSValue(valURI.forget());
 
   // <top>, <right>, <bottom>, <left>
   NS_FOR_CSS_SIDES(side) {
-    nsROCSSPrimitiveValue *valSide = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(valSide);
+    RefPtr<nsROCSSPrimitiveValue> valSide = new nsROCSSPrimitiveValue;
     SetValueToCoord(valSide, aCropRect.Get(side), false);
+    valueList->AppendCSSValue(valSide.forget());
   }
 
   nsAutoString argumentString;
   valueList->GetCssText(argumentString);
 
   aString = NS_LITERAL_STRING("-moz-image-rect(") +
             argumentString +
             NS_LITERAL_STRING(")");
@@ -2122,21 +2122,21 @@ nsComputedDOMStyle::SetValueToStyleImage
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundImage()
 {
   const nsStyleBackground* bg = StyleBackground();
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = bg->mImageCount; i < i_end; ++i) {
-    nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
     const nsStyleImage& image = bg->mLayers[i].mImage;
     SetValueToStyleImage(image, val);
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundBlendMode()
 {
@@ -2169,55 +2169,51 @@ nsComputedDOMStyle::SetValueToPositionCo
   }
 }
 
 void
 nsComputedDOMStyle::SetValueToPosition(
     const nsStyleBackground::Position& aPosition,
     nsDOMCSSValueList* aValueList)
 {
-  nsROCSSPrimitiveValue* valX = new nsROCSSPrimitiveValue;
-  aValueList->AppendCSSValue(valX);
+  RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
   SetValueToPositionCoord(aPosition.mXPosition, valX);
-
-  nsROCSSPrimitiveValue* valY = new nsROCSSPrimitiveValue;
-  aValueList->AppendCSSValue(valY);
+  aValueList->AppendCSSValue(valX.forget());
+
+  RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
   SetValueToPositionCoord(aPosition.mYPosition, valY);
+  aValueList->AppendCSSValue(valY.forget());
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundPosition()
 {
   const nsStyleBackground* bg = StyleBackground();
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = bg->mPositionCount; i < i_end; ++i) {
-    nsDOMCSSValueList *itemList = GetROCSSValueList(false);
-    valueList->AppendCSSValue(itemList);
-
+    RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
     SetValueToPosition(bg->mLayers[i].mPosition, itemList);
+    valueList->AppendCSSValue(itemList.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundRepeat()
 {
   const nsStyleBackground* bg = StyleBackground();
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = bg->mRepeatCount; i < i_end; ++i) {
-    nsDOMCSSValueList *itemList = GetROCSSValueList(false);
-    valueList->AppendCSSValue(itemList);
-
-    nsROCSSPrimitiveValue *valX = new nsROCSSPrimitiveValue;
-    itemList->AppendCSSValue(valX);
+    RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
+    RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
 
     const uint8_t& xRepeat = bg->mLayers[i].mRepeat.mXRepeat;
     const uint8_t& yRepeat = bg->mLayers[i].mRepeat.mYRepeat;
 
     bool hasContraction = true;
     unsigned contraction;
     if (xRepeat == yRepeat) {
       contraction = xRepeat;
@@ -2226,28 +2222,33 @@ nsComputedDOMStyle::DoGetBackgroundRepea
       contraction = NS_STYLE_BG_REPEAT_REPEAT_X;
     } else if (xRepeat == NS_STYLE_BG_REPEAT_NO_REPEAT &&
                yRepeat == NS_STYLE_BG_REPEAT_REPEAT) {
       contraction = NS_STYLE_BG_REPEAT_REPEAT_Y;
     } else {
       hasContraction = false;
     }
 
+    RefPtr<nsROCSSPrimitiveValue> valY;
     if (hasContraction) {
       valX->SetIdent(nsCSSProps::ValueToKeywordEnum(contraction,
                                          nsCSSProps::kBackgroundRepeatKTable));
     } else {
-      nsROCSSPrimitiveValue *valY = new nsROCSSPrimitiveValue;
-      itemList->AppendCSSValue(valY);
+      valY = new nsROCSSPrimitiveValue;
       
       valX->SetIdent(nsCSSProps::ValueToKeywordEnum(xRepeat,
                                           nsCSSProps::kBackgroundRepeatKTable));
       valY->SetIdent(nsCSSProps::ValueToKeywordEnum(yRepeat,
                                           nsCSSProps::kBackgroundRepeatKTable));
     }
+    itemList->AppendCSSValue(valX.forget());
+    if (valY) {
+      itemList->AppendCSSValue(valY.forget());
+    }
+    valueList->AppendCSSValue(itemList.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBackgroundSize()
 {
@@ -2261,29 +2262,26 @@ nsComputedDOMStyle::DoGetBackgroundSize(
     switch (size.mWidthType) {
       case nsStyleBackground::Size::eContain:
       case nsStyleBackground::Size::eCover: {
         MOZ_ASSERT(size.mWidthType == size.mHeightType,
                    "unsynced types");
         nsCSSKeyword keyword = size.mWidthType == nsStyleBackground::Size::eContain
                              ? eCSSKeyword_contain
                              : eCSSKeyword_cover;
-        nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-        valueList->AppendCSSValue(val);
+        RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
         val->SetIdent(keyword);
+        valueList->AppendCSSValue(val.forget());
         break;
       }
       default: {
-        nsDOMCSSValueList *itemList = GetROCSSValueList(false);
-        valueList->AppendCSSValue(itemList);
-
-        nsROCSSPrimitiveValue* valX = new nsROCSSPrimitiveValue;
-        itemList->AppendCSSValue(valX);
-        nsROCSSPrimitiveValue* valY = new nsROCSSPrimitiveValue;
-        itemList->AppendCSSValue(valY);
+        RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
+
+        RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
 
         if (size.mWidthType == nsStyleBackground::Size::eAuto) {
           valX->SetIdent(eCSSKeyword_auto);
         } else {
           MOZ_ASSERT(size.mWidthType ==
                        nsStyleBackground::Size::eLengthPercentage,
                      "bad mWidthType");
           if (!size.mWidth.mHasPercent &&
@@ -2316,16 +2314,19 @@ nsComputedDOMStyle::DoGetBackgroundSize(
           } else if (size.mHeight.mLength == 0 &&
                      // negative values must have come from calc()
                      size.mHeight.mPercent >= 0.0f) {
             valY->SetPercent(size.mHeight.mPercent);
           } else {
             SetValueToCalc(&size.mHeight, valY);
           }
         }
+        itemList->AppendCSSValue(valX.forget());
+        itemList->AppendCSSValue(valY.forget());
+        valueList->AppendCSSValue(itemList.forget());
         break;
       }
     }
   }
 
   return valueList;
 }
 
@@ -2341,19 +2342,19 @@ nsComputedDOMStyle::DoGetGridTemplateAre
   }
 
   MOZ_ASSERT(!areas->mTemplates.IsEmpty(),
              "Unexpected empty array in GridTemplateAreasValue");
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
   for (uint32_t i = 0; i < areas->mTemplates.Length(); i++) {
     nsAutoString str;
     nsStyleUtil::AppendEscapedCSSString(areas->mTemplates[i], str);
-    nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     val->SetString(str);
-    valueList->AppendCSSValue(val);
+    valueList->AppendCSSValue(val.forget());
   }
   return valueList;
 }
 
 void
 nsComputedDOMStyle::AppendGridLineNames(nsString& aResult,
                                         const nsTArray<nsString>& aLineNames)
 {
@@ -2370,48 +2371,48 @@ nsComputedDOMStyle::AppendGridLineNames(
 
 void
 nsComputedDOMStyle::AppendGridLineNames(nsDOMCSSValueList* aValueList,
                                         const nsTArray<nsString>& aLineNames)
 {
   if (aLineNames.IsEmpty()) {
     return;
   }
-  nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   nsAutoString lineNamesString;
   lineNamesString.Assign('[');
   AppendGridLineNames(lineNamesString, aLineNames);
   lineNamesString.Append(']');
   val->SetString(lineNamesString);
-  aValueList->AppendCSSValue(val);
+  aValueList->AppendCSSValue(val.forget());
 }
 
 void
 nsComputedDOMStyle::AppendGridLineNames(nsDOMCSSValueList* aValueList,
                                         const nsTArray<nsString>& aLineNames1,
                                         const nsTArray<nsString>& aLineNames2)
 {
   if (aLineNames1.IsEmpty() && aLineNames2.IsEmpty()) {
     return;
   }
-  nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   nsAutoString lineNamesString;
   lineNamesString.Assign('[');
   if (!aLineNames1.IsEmpty()) {
     AppendGridLineNames(lineNamesString, aLineNames1);
   }
   if (!aLineNames2.IsEmpty()) {
     if (!aLineNames1.IsEmpty()) {
       lineNamesString.Append(' ');
     }
     AppendGridLineNames(lineNamesString, aLineNames2);
   }
   lineNamesString.Append(']');
   val->SetString(lineNamesString);
-  aValueList->AppendCSSValue(val);
+  aValueList->AppendCSSValue(val.forget());
 }
 
 CSSValue*
 nsComputedDOMStyle::GetGridTrackSize(const nsStyleCoord& aMinValue,
                                      const nsStyleCoord& aMaxValue)
 {
   if (aMinValue == aMaxValue) {
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
@@ -2447,34 +2448,34 @@ nsComputedDOMStyle::GetGridTemplateColum
 {
   if (aTrackList.mIsSubgrid) {
     // XXX TODO: add support for repeat(auto-fill) for 'subgrid' (bug 1234311)
     NS_ASSERTION(aTrackList.mMinTrackSizingFunctions.IsEmpty() &&
                  aTrackList.mMaxTrackSizingFunctions.IsEmpty(),
                  "Unexpected sizing functions with subgrid");
     nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
-    nsROCSSPrimitiveValue* subgridKeyword = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> subgridKeyword = new nsROCSSPrimitiveValue;
     subgridKeyword->SetIdent(eCSSKeyword_subgrid);
-    valueList->AppendCSSValue(subgridKeyword);
+    valueList->AppendCSSValue(subgridKeyword.forget());
 
     for (uint32_t i = 0; i < aTrackList.mLineNameLists.Length(); i++) {
       if (MOZ_UNLIKELY(aTrackList.IsRepeatAutoIndex(i))) {
         MOZ_ASSERT(aTrackList.mIsAutoFill, "subgrid can only have 'auto-fill'");
         MOZ_ASSERT(!aTrackList.mRepeatAutoLineNameListBefore.IsEmpty(),
                    "The syntax is <line-names>+ so this shouldn't be empty");
         MOZ_ASSERT(aTrackList.mRepeatAutoLineNameListAfter.IsEmpty(),
                    "mRepeatAutoLineNameListAfter isn't used for subgrid");
-        nsROCSSPrimitiveValue* start = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> start = new nsROCSSPrimitiveValue;
         start->SetString(NS_LITERAL_STRING("repeat(auto-fill,"));
-        valueList->AppendCSSValue(start);
+        valueList->AppendCSSValue(start.forget());
         AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListBefore);
-        nsROCSSPrimitiveValue* end = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> end = new nsROCSSPrimitiveValue;
         end->SetString(NS_LITERAL_STRING(")"));
-        valueList->AppendCSSValue(end);
+        valueList->AppendCSSValue(end.forget());
       }
       AppendGridLineNames(valueList, aTrackList.mLineNameLists[i]);
     }
     return valueList;
   }
 
   uint32_t numSizes = aTrackList.mMinTrackSizingFunctions.Length();
   MOZ_ASSERT(aTrackList.mMaxTrackSizingFunctions.Length() == numSizes,
@@ -2544,50 +2545,62 @@ nsComputedDOMStyle::GetGridTemplateColum
         }
       } else {
         const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[i];
         AppendGridLineNames(valueList, lineNames);
       }
       if (uint32_t(i) == numTracks) {
         break;
       }
-      nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
+      RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
       val->SetAppUnits((*aTrackSizes)[i]);
-      valueList->AppendCSSValue(val);
+      valueList->AppendCSSValue(val.forget());
     }
   } else {
     // We don't have a frame.  So, we'll just return a serialization of
     // the tracks from the style (without resolved sizes).
     for (uint32_t i = 0;; i++) {
       const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[i];
       if (!lineNames.IsEmpty()) {
         AppendGridLineNames(valueList, lineNames);
       }
       if (i == numSizes) {
         break;
       }
       if (MOZ_UNLIKELY(aTrackList.IsRepeatAutoIndex(i))) {
-        nsROCSSPrimitiveValue* start = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> start = new nsROCSSPrimitiveValue;
         start->SetString(aTrackList.mIsAutoFill ? NS_LITERAL_STRING("repeat(auto-fill,")
                                                 : NS_LITERAL_STRING("repeat(auto-fit,"));
-        valueList->AppendCSSValue(start);
+        valueList->AppendCSSValue(start.forget());
         if (!aTrackList.mRepeatAutoLineNameListBefore.IsEmpty()) {
           AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListBefore);
         }
-        valueList->AppendCSSValue(GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
-                                                   aTrackList.mMaxTrackSizingFunctions[i]));
+
+        // XXXdholbert The |tmpTrackSize| RefPtr variable below can go away once
+        // we fix bug 1234676 and can make GetGridTrackSize return an
+        // already_AddRefed value.
+        RefPtr<CSSValue> tmpTrackSize =
+          GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
+                           aTrackList.mMaxTrackSizingFunctions[i]);
+
+        valueList->AppendCSSValue(tmpTrackSize.forget());
         if (!aTrackList.mRepeatAutoLineNameListAfter.IsEmpty()) {
           AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListAfter);
         }
-        nsROCSSPrimitiveValue* end = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> end = new nsROCSSPrimitiveValue;
         end->SetString(NS_LITERAL_STRING(")"));
-        valueList->AppendCSSValue(end);
+        valueList->AppendCSSValue(end.forget());
       } else {
-        valueList->AppendCSSValue(GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
-                                                   aTrackList.mMaxTrackSizingFunctions[i]));
+        // XXXdholbert The |tmpTrackSize| RefPtr variable below can go away once
+        // we fix bug 1234676 and make GetGridTrackSize return an
+        // already_AddRefed value.
+        RefPtr<CSSValue> tmpTrackSize =
+          GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
+                           aTrackList.mMaxTrackSizingFunctions[i]);
+        valueList->AppendCSSValue(tmpTrackSize.forget());
       }
     }
   }
 
   return valueList;
 }
 
 CSSValue*
@@ -2655,33 +2668,33 @@ nsComputedDOMStyle::GetGridLine(const ns
     nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_auto);
     return val;
   }
 
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
   if (aGridLine.mHasSpan) {
-    nsROCSSPrimitiveValue* span = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> span = new nsROCSSPrimitiveValue;
     span->SetIdent(eCSSKeyword_span);
-    valueList->AppendCSSValue(span);
+    valueList->AppendCSSValue(span.forget());
   }
 
   if (aGridLine.mInteger != 0) {
-    nsROCSSPrimitiveValue* integer = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> integer = new nsROCSSPrimitiveValue;
     integer->SetNumber(aGridLine.mInteger);
-    valueList->AppendCSSValue(integer);
+    valueList->AppendCSSValue(integer.forget());
   }
 
   if (!aGridLine.mLineName.IsEmpty()) {
-    nsROCSSPrimitiveValue* lineName = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> lineName = new nsROCSSPrimitiveValue;
     nsString escapedLineName;
     nsStyleUtil::AppendEscapedCSSIdent(aGridLine.mLineName, escapedLineName);
     lineName->SetString(escapedLineName);
-    valueList->AppendCSSValue(lineName);
+    valueList->AppendCSSValue(lineName.forget());
   }
 
   NS_ASSERTION(valueList->Length() > 0,
                "Should have appended at least one value");
   return valueList;
 }
 
 CSSValue*
@@ -2758,26 +2771,26 @@ nsComputedDOMStyle::DoGetBorderCollapse(
   return val;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBorderSpacing()
 {
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
-  nsROCSSPrimitiveValue* xSpacing = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(xSpacing);
-
-  nsROCSSPrimitiveValue* ySpacing = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(ySpacing);
+  RefPtr<nsROCSSPrimitiveValue> xSpacing = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> ySpacing = new nsROCSSPrimitiveValue;
 
   const nsStyleTableBorder *border = StyleTableBorder();
   xSpacing->SetAppUnits(border->mBorderSpacingCol);
   ySpacing->SetAppUnits(border->mBorderSpacingRow);
 
+  valueList->AppendCSSValue(xSpacing.forget());
+  valueList->AppendCSSValue(ySpacing.forget());
+
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetCaptionSide()
 {
   nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
   val->SetIdent(
@@ -3064,19 +3077,19 @@ nsComputedDOMStyle::DoGetScrollSnapCoord
   if (sd->mScrollSnapCoordinate.IsEmpty()) {
     // Having no snap coordinates is interpreted as "none"
     nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_none);
     return val;
   } else {
     nsDOMCSSValueList* valueList = GetROCSSValueList(true);
     for (size_t i = 0, i_end = sd->mScrollSnapCoordinate.Length(); i < i_end; ++i) {
-      nsDOMCSSValueList* itemList = GetROCSSValueList(false);
-      valueList->AppendCSSValue(itemList);
+      RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
       SetValueToPosition(sd->mScrollSnapCoordinate[i], itemList);
+      valueList->AppendCSSValue(itemList.forget());
     }
     return valueList;
   }
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetOutlineWidth()
 {
@@ -3198,25 +3211,25 @@ nsComputedDOMStyle::GetEllipseRadii(cons
 
     SetValueToCoord(val, radiusX, true);
 
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
-  nsROCSSPrimitiveValue *valX = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(valX);
-
-  nsROCSSPrimitiveValue *valY = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(valY);
+  RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
 
   SetValueToCoord(valX, radiusX, true);
   SetValueToCoord(valY, radiusY, true);
 
+  valueList->AppendCSSValue(valX.forget());
+  valueList->AppendCSSValue(valY.forget());
+
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::GetCSSShadowArray(nsCSSShadowArray* aArray,
                                       const nscolor& aDefaultColor,
                                       bool aIsBoxShadow)
 {
@@ -3249,45 +3262,45 @@ nsComputedDOMStyle::GetCSSShadowArray(ns
     shadowValuesLength = ArrayLength(shadowValuesNoSpread);
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (nsCSSShadowItem *item = aArray->ShadowAt(0),
                    *item_end = item + aArray->Length();
        item < item_end; ++item) {
-    nsDOMCSSValueList *itemList = GetROCSSValueList(false);
-    valueList->AppendCSSValue(itemList);
+    RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
 
     // Color is either the specified shadow color or the foreground color
-    nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
-    itemList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     nscolor shadowColor;
     if (item->mHasColor) {
       shadowColor = item->mColor;
     } else {
       shadowColor = aDefaultColor;
     }
     SetToRGBAColor(val, shadowColor);
+    itemList->AppendCSSValue(val.forget());
 
     // Set the offsets, blur radius, and spread if available
     for (uint32_t i = 0; i < shadowValuesLength; ++i) {
       val = new nsROCSSPrimitiveValue;
-      itemList->AppendCSSValue(val);
       val->SetAppUnits(item->*(shadowValues[i]));
+      itemList->AppendCSSValue(val.forget());
     }
 
     if (item->mInset && aIsBoxShadow) {
       // This is an inset box-shadow
       val = new nsROCSSPrimitiveValue;
-      itemList->AppendCSSValue(val);
       val->SetIdent(
         nsCSSProps::ValueToKeywordEnum(NS_STYLE_BOX_SHADOW_INSET,
                                        nsCSSProps::kBoxShadowTypeKTable));
+      itemList->AppendCSSValue(val.forget());
     }
+    valueList->AppendCSSValue(itemList.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBoxDecorationBreak()
 {
@@ -3465,22 +3478,29 @@ nsComputedDOMStyle::CreateTextAlignValue
                                          const KTableEntry aTable[])
 {
   nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
   val->SetIdent(nsCSSProps::ValueToKeywordEnum(aAlign, aTable));
   if (!aAlignTrue) {
     return val;
   }
 
-  nsROCSSPrimitiveValue* first = new nsROCSSPrimitiveValue;
+  // XXXdholbert Really we should store |val| in a RefPtr right away, and our
+  // return-type should be already_AddRefed. See bug 1234676.  For now, we only
+  // put it in a RefPtr (for the benefit of AppendCSSValue) after we know we're
+  // not returning it directly.
+  RefPtr<nsROCSSPrimitiveValue> refcountedVal = val;
+  val = nullptr; // (to avoid accidental reuse/misuse)
+
+  RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
   first->SetIdent(eCSSKeyword_true);
 
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
-  valueList->AppendCSSValue(first);
-  valueList->AppendCSSValue(val);
+  valueList->AppendCSSValue(first.forget());
+  valueList->AppendCSSValue(refcountedVal.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextAlign()
 {
   const nsStyleText* style = StyleText();
   return CreateTextAlignValue(style->mTextAlign, style->mTextAlignTrue,
@@ -3528,22 +3548,27 @@ nsComputedDOMStyle::DoGetTextDecoration(
   textReset->GetDecorationColor(color, isForegroundColor);
 
   if (isInitialStyle && isForegroundColor) {
     return DoGetTextDecorationLine();
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
-  valueList->AppendCSSValue(DoGetTextDecorationLine());
+  // XXXdholbert The |tmp| RefPtr variable below can go away once we fix bug
+  // 1234676 and make the DoGet* functions return an already_AddRefed value.
+  RefPtr<CSSValue> tmp = DoGetTextDecorationLine();
+  valueList->AppendCSSValue(tmp.forget());
   if (!isInitialStyle) {
-    valueList->AppendCSSValue(DoGetTextDecorationStyle());
+    tmp = DoGetTextDecorationStyle();
+    valueList->AppendCSSValue(tmp.forget());
   }
   if (!isForegroundColor) {
-    valueList->AppendCSSValue(DoGetTextDecorationColor());
+    tmp = DoGetTextDecorationColor();
+    valueList->AppendCSSValue(tmp.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextDecorationColor()
 {
@@ -3610,29 +3635,29 @@ nsComputedDOMStyle::DoGetTextEmphasisCol
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextEmphasisPosition()
 {
   auto position = StyleText()->mTextEmphasisPosition;
 
   MOZ_ASSERT(!(position & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER) !=
              !(position & NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER));
-  nsROCSSPrimitiveValue* first = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
   first->SetIdent((position & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER) ?
                   eCSSKeyword_over : eCSSKeyword_under);
 
   MOZ_ASSERT(!(position & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT) !=
              !(position & NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT));
-  nsROCSSPrimitiveValue* second = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> second = new nsROCSSPrimitiveValue;
   second->SetIdent((position & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT) ?
                    eCSSKeyword_left : eCSSKeyword_right);
 
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
-  valueList->AppendCSSValue(first);
-  valueList->AppendCSSValue(second);
+  valueList->AppendCSSValue(first.forget());
+  valueList->AppendCSSValue(second.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextEmphasisStyle()
 {
   auto style = StyleText()->mTextEmphasisStyle;
   if (style == NS_STYLE_TEXT_EMPHASIS_STYLE_NONE) {
@@ -3644,34 +3669,34 @@ nsComputedDOMStyle::DoGetTextEmphasisSty
     nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
     nsString tmp;
     nsStyleUtil::AppendEscapedCSSString(
       StyleText()->mTextEmphasisStyleString, tmp);
     val->SetString(tmp);
     return val;
   }
 
-  nsROCSSPrimitiveValue* fillVal = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> fillVal = new nsROCSSPrimitiveValue;
   if ((style & NS_STYLE_TEXT_EMPHASIS_STYLE_FILL_MASK) ==
       NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED) {
     fillVal->SetIdent(eCSSKeyword_filled);
   } else {
     MOZ_ASSERT((style & NS_STYLE_TEXT_EMPHASIS_STYLE_FILL_MASK) ==
                NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN);
     fillVal->SetIdent(eCSSKeyword_open);
   }
 
-  nsROCSSPrimitiveValue* shapeVal = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> shapeVal = new nsROCSSPrimitiveValue;
   shapeVal->SetIdent(nsCSSProps::ValueToKeywordEnum(
     style & NS_STYLE_TEXT_EMPHASIS_STYLE_SHAPE_MASK,
     nsCSSProps::kTextEmphasisStyleShapeKTable));
 
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
-  valueList->AppendCSSValue(fillVal);
-  valueList->AppendCSSValue(shapeVal);
+  valueList->AppendCSSValue(fillVal.forget());
+  valueList->AppendCSSValue(shapeVal.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextIndent()
 {
   nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
   SetValueToCoord(val, StyleText()->mTextIndent, false,
@@ -3688,45 +3713,45 @@ nsComputedDOMStyle::DoGetTextOrientation
                                    nsCSSProps::kTextOrientationKTable));
   return val;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextOverflow()
 {
   const nsStyleTextReset *style = StyleTextReset();
-  nsROCSSPrimitiveValue *first = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
   const nsStyleTextOverflowSide *side = style->mTextOverflow.GetFirstValue();
   if (side->mType == NS_STYLE_TEXT_OVERFLOW_STRING) {
     nsString str;
     nsStyleUtil::AppendEscapedCSSString(side->mString, str);
     first->SetString(str);
   } else {
     first->SetIdent(
       nsCSSProps::ValueToKeywordEnum(side->mType,
                                      nsCSSProps::kTextOverflowKTable));
   }
   side = style->mTextOverflow.GetSecondValue();
   if (!side) {
     return first;
   }
-  nsROCSSPrimitiveValue *second = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> second = new nsROCSSPrimitiveValue;
   if (side->mType == NS_STYLE_TEXT_OVERFLOW_STRING) {
     nsString str;
     nsStyleUtil::AppendEscapedCSSString(side->mString, str);
     second->SetString(str);
   } else {
     second->SetIdent(
       nsCSSProps::ValueToKeywordEnum(side->mType,
                                      nsCSSProps::kTextOverflowKTable));
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
-  valueList->AppendCSSValue(first);
-  valueList->AppendCSSValue(second);
+  valueList->AppendCSSValue(first.forget());
+  valueList->AppendCSSValue(second.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTextShadow()
 {
   return GetCSSShadowArray(StyleText()->mTextShadow,
                            StyleColor()->mColor,
@@ -3902,41 +3927,42 @@ nsComputedDOMStyle::DoGetCursor()
 {
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   const nsStyleUserInterface *ui = StyleUserInterface();
 
   for (nsCursorImage *item = ui->mCursorArray,
          *item_end = ui->mCursorArray + ui->mCursorArrayLength;
        item < item_end; ++item) {
-    nsDOMCSSValueList *itemList = GetROCSSValueList(false);
-    valueList->AppendCSSValue(itemList);
+    RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
 
     nsCOMPtr<nsIURI> uri;
     item->GetImage()->GetURI(getter_AddRefs(uri));
 
-    nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
-    itemList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     val->SetURI(uri);
+    itemList->AppendCSSValue(val.forget());
 
     if (item->mHaveHotspot) {
-      nsROCSSPrimitiveValue *valX = new nsROCSSPrimitiveValue;
-      itemList->AppendCSSValue(valX);
-      nsROCSSPrimitiveValue *valY = new nsROCSSPrimitiveValue;
-      itemList->AppendCSSValue(valY);
+      RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
+      RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
 
       valX->SetNumber(item->mHotspotX);
       valY->SetNumber(item->mHotspotY);
+
+      itemList->AppendCSSValue(valX.forget());
+      itemList->AppendCSSValue(valY.forget());
     }
-  }
-
-  nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
+    valueList->AppendCSSValue(itemList.forget());
+  }
+
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   val->SetIdent(nsCSSProps::ValueToKeywordEnum(ui->mCursor,
                                                nsCSSProps::kCursorKTable));
-  valueList->AppendCSSValue(val);
+  valueList->AppendCSSValue(val.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAppearance()
 {
   nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
   val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mAppearance,
@@ -4026,83 +4052,83 @@ nsComputedDOMStyle::DoGetBorderImageSour
 CSSValue*
 nsComputedDOMStyle::DoGetBorderImageSlice()
 {
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
   const nsStyleBorder* border = StyleBorder();
   // Four slice numbers.
   NS_FOR_CSS_SIDES (side) {
-    nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     SetValueToCoord(val, border->mBorderImageSlice.Get(side), true, nullptr);
+    valueList->AppendCSSValue(val.forget());
   }
 
   // Fill keyword.
   if (NS_STYLE_BORDER_IMAGE_SLICE_FILL == border->mBorderImageFill) {
-    nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_fill);
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBorderImageWidth()
 {
   const nsStyleBorder* border = StyleBorder();
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
   NS_FOR_CSS_SIDES (side) {
-    nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     SetValueToCoord(val, border->mBorderImageWidth.Get(side),
                     true, nullptr);
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBorderImageOutset()
 {
   nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
   const nsStyleBorder* border = StyleBorder();
   // four slice numbers
   NS_FOR_CSS_SIDES (side) {
-    nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(val);
+    RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     SetValueToCoord(val, border->mBorderImageOutset.Get(side),
                     true, nullptr);
+    valueList->AppendCSSValue(val.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetBorderImageRepeat()
 {
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
 
   const nsStyleBorder* border = StyleBorder();
 
   // horizontal repeat
-  nsROCSSPrimitiveValue* valX = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(valX);
+  RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
   valX->SetIdent(
     nsCSSProps::ValueToKeywordEnum(border->mBorderImageRepeatH,
                                    nsCSSProps::kBorderImageRepeatKTable));
+  valueList->AppendCSSValue(valX.forget());
 
   // vertical repeat
-  nsROCSSPrimitiveValue* valY = new nsROCSSPrimitiveValue;
-  valueList->AppendCSSValue(valY);
+  RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
   valY->SetIdent(
     nsCSSProps::ValueToKeywordEnum(border->mBorderImageRepeatV,
                                    nsCSSProps::kBorderImageRepeatKTable));
+  valueList->AppendCSSValue(valY.forget());
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetFlexBasis()
 {
   nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
 
@@ -4435,19 +4461,19 @@ nsComputedDOMStyle::DoGetWillChange()
     nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_auto);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
   for (size_t i = 0; i < willChange.Length(); i++) {
     const nsString& willChangeIdentifier = willChange[i];
-    nsROCSSPrimitiveValue* property = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(property);
+    RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
     property->SetString(willChangeIdentifier);
+    valueList->AppendCSSValue(property.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetOverflow()
 {
@@ -5000,21 +5026,21 @@ nsComputedDOMStyle::GetBorderColorsFor(m
   const nsStyleBorder *border = StyleBorder();
 
   if (border->mBorderColors) {
     nsBorderColors* borderColors = border->mBorderColors[aSide];
     if (borderColors) {
       nsDOMCSSValueList *valueList = GetROCSSValueList(false);
 
       do {
-        nsROCSSPrimitiveValue *primitive = new nsROCSSPrimitiveValue;
+        RefPtr<nsROCSSPrimitiveValue> primitive = new nsROCSSPrimitiveValue;
 
         SetToRGBAColor(primitive, borderColors->mColor);
 
-        valueList->AppendCSSValue(primitive);
+        valueList->AppendCSSValue(primitive.forget());
         borderColors = borderColors->mNext;
       } while (borderColors);
 
       return valueList;
     }
   }
 
   nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue;
@@ -5388,23 +5414,30 @@ nsComputedDOMStyle::GetSVGPaintFor(bool 
     case eStyleSVGPaintType_Color:
     {
       SetToRGBAColor(val, paint->mPaint.mColor);
       break;
     }
     case eStyleSVGPaintType_Server:
     {
       nsDOMCSSValueList *valueList = GetROCSSValueList(false);
-      valueList->AppendCSSValue(val);
-
-      nsROCSSPrimitiveValue* fallback = new nsROCSSPrimitiveValue;
-      valueList->AppendCSSValue(fallback);
-
-      val->SetURI(paint->mPaint.mPaintServer);
+      RefPtr<nsROCSSPrimitiveValue> fallback = new nsROCSSPrimitiveValue;
+
+      // XXXdholbert Really we should store |val| in a RefPtr right away, and
+      // our return-type should be already_AddRefed. See bug 1234676.  For now,
+      // we only put it in a RefPtr (for the benefit of AppendCSSValue) after
+      // we know we're not returning it directly.
+      RefPtr<nsROCSSPrimitiveValue> refcountedVal = val;
+      val = nullptr; // (to avoid accidental reuse/misuse)
+
+      refcountedVal->SetURI(paint->mPaint.mPaintServer);
       SetToRGBAColor(fallback, paint->mFallbackColor);
+
+      valueList->AppendCSSValue(refcountedVal.forget());
+      valueList->AppendCSSValue(fallback.forget());
       return valueList;
     }
     case eStyleSVGPaintType_ContextFill:
     {
       val->SetIdent(eCSSKeyword_context_fill);
       break;
     }
     case eStyleSVGPaintType_ContextStroke:
@@ -5483,20 +5516,19 @@ nsComputedDOMStyle::DoGetStrokeDasharray
     nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
     val->SetIdent(eCSSKeyword_none);
     return val;
   }
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0; i < svg->mStrokeDasharrayLength; i++) {
-    nsROCSSPrimitiveValue* dash = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(dash);
-
+    RefPtr<nsROCSSPrimitiveValue> dash = new nsROCSSPrimitiveValue;
     SetValueToCoord(dash, svg->mStrokeDasharray[i], true);
+    valueList->AppendCSSValue(dash.forget());
   }
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetStrokeDashoffset()
 {
@@ -5836,33 +5868,33 @@ nsComputedDOMStyle::CreatePrimitiveValue
           shapeFunctionString.Append(radiiString);
         }
         break;
       }
       default:
         NS_NOTREACHED("unexpected type");
     }
     shapeFunctionString.Append(')');
-    nsROCSSPrimitiveValue* functionValue = new nsROCSSPrimitiveValue;
+    RefPtr<nsROCSSPrimitiveValue> functionValue = new nsROCSSPrimitiveValue;
     functionValue->SetString(shapeFunctionString);
-    valueList->AppendCSSValue(functionValue);
+    valueList->AppendCSSValue(functionValue.forget());
   }
 
   if (aSizingBox == NS_STYLE_CLIP_SHAPE_SIZING_NOBOX) {
     return valueList;
   }
 
   nsAutoString boxString;
   AppendASCIItoUTF16(
     nsCSSProps::ValueToKeyword(aSizingBox,
                                nsCSSProps::kClipShapeSizingKTable),
                                boxString);
-  nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   val->SetString(boxString);
-  valueList->AppendCSSValue(val);
+  valueList->AppendCSSValue(val.forget());
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetClipPath()
 {
   const nsStyleSVGReset* svg = StyleSVGReset();
@@ -5894,25 +5926,25 @@ nsComputedDOMStyle::SetCssTextToCoord(ns
                                       const nsStyleCoord& aCoord)
 {
   RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
   bool clampNegativeCalc = true;
   SetValueToCoord(value, aCoord, clampNegativeCalc);
   value->GetCssText(aCssText);
 }
 
-CSSValue*
+already_AddRefed<CSSValue>
 nsComputedDOMStyle::CreatePrimitiveValueForStyleFilter(
   const nsStyleFilter& aStyleFilter)
 {
-  nsROCSSPrimitiveValue* value = new nsROCSSPrimitiveValue;
+  RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
   // Handle url().
   if (aStyleFilter.GetType() == NS_STYLE_FILTER_URL) {
     value->SetURI(aStyleFilter.GetURL());
-    return value;
+    return value.forget();
   }
 
   // Filter function name and opening parenthesis.
   nsAutoString filterFunctionString;
   AppendASCIItoUTF16(
     nsCSSProps::ValueToKeyword(aStyleFilter.GetType(),
                                nsCSSProps::kFilterFunctionKTable),
                                filterFunctionString);
@@ -5932,34 +5964,34 @@ nsComputedDOMStyle::CreatePrimitiveValue
     SetCssTextToCoord(argumentString, aStyleFilter.GetFilterParameter());
   }
   filterFunctionString.Append(argumentString);
 
   // Filter function closing parenthesis.
   filterFunctionString.Append(')');
 
   value->SetString(filterFunctionString);
-  return value;
+  return value.forget();
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetFilter()
 {
   const nsTArray<nsStyleFilter>& filters = StyleSVGReset()->mFilters;
 
   if (filters.IsEmpty()) {
     nsROCSSPrimitiveValue* value = new nsROCSSPrimitiveValue;
     value->SetIdent(eCSSKeyword_none);
     return value;
   }
 
   nsDOMCSSValueList* valueList = GetROCSSValueList(false);
   for(uint32_t i = 0; i < filters.Length(); i++) {
-    CSSValue* value = CreatePrimitiveValueForStyleFilter(filters[i]);
-    valueList->AppendCSSValue(value);
+    RefPtr<CSSValue> value = CreatePrimitiveValueForStyleFilter(filters[i]);
+    valueList->AppendCSSValue(value.forget());
   }
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetMask()
 {
   nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
@@ -6002,19 +6034,19 @@ nsComputedDOMStyle::DoGetTransitionDelay
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mTransitionDelayCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleTransition *transition = &display->mTransitions[i];
-    nsROCSSPrimitiveValue* delay = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(delay);
+    RefPtr<nsROCSSPrimitiveValue> delay = new nsROCSSPrimitiveValue;
     delay->SetTime((float)transition->GetDelay() / (float)PR_MSEC_PER_SEC);
+    valueList->AppendCSSValue(delay.forget());
   } while (++i < display->mTransitionDelayCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTransitionDuration()
 {
@@ -6022,20 +6054,20 @@ nsComputedDOMStyle::DoGetTransitionDurat
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mTransitionDurationCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleTransition *transition = &display->mTransitions[i];
-    nsROCSSPrimitiveValue* duration = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(duration);
+    RefPtr<nsROCSSPrimitiveValue> duration = new nsROCSSPrimitiveValue;
 
     duration->SetTime((float)transition->GetDuration() / (float)PR_MSEC_PER_SEC);
+    valueList->AppendCSSValue(duration.forget());
   } while (++i < display->mTransitionDurationCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTransitionProperty()
 {
@@ -6043,44 +6075,44 @@ nsComputedDOMStyle::DoGetTransitionPrope
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mTransitionPropertyCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleTransition *transition = &display->mTransitions[i];
-    nsROCSSPrimitiveValue* property = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(property);
+    RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
     nsCSSProperty cssprop = transition->GetProperty();
     if (cssprop == eCSSPropertyExtra_all_properties)
       property->SetIdent(eCSSKeyword_all);
     else if (cssprop == eCSSPropertyExtra_no_properties)
       property->SetIdent(eCSSKeyword_none);
     else if (cssprop == eCSSProperty_UNKNOWN ||
              cssprop == eCSSPropertyExtra_variable)
     {
       nsAutoString escaped;
       nsStyleUtil::AppendEscapedCSSIdent(
         nsDependentAtomString(transition->GetUnknownProperty()), escaped);
       property->SetString(escaped); // really want SetIdent
     }
     else
       property->SetString(nsCSSProps::GetStringValue(cssprop));
+
+    valueList->AppendCSSValue(property.forget());
   } while (++i < display->mTransitionPropertyCount);
 
   return valueList;
 }
 
 void
 nsComputedDOMStyle::AppendTimingFunction(nsDOMCSSValueList *aValueList,
                                          const nsTimingFunction& aTimingFunction)
 {
-  nsROCSSPrimitiveValue* timingFunction = new nsROCSSPrimitiveValue;
-  aValueList->AppendCSSValue(timingFunction);
+  RefPtr<nsROCSSPrimitiveValue> timingFunction = new nsROCSSPrimitiveValue;
 
   nsAutoString tmp;
   switch (aTimingFunction.mType) {
     case nsTimingFunction::Type::CubicBezier:
       nsStyleUtil::AppendCubicBezierTimingFunction(aTimingFunction.mFunc.mX1,
                                                    aTimingFunction.mFunc.mY1,
                                                    aTimingFunction.mFunc.mX2,
                                                    aTimingFunction.mFunc.mY2,
@@ -6094,16 +6126,17 @@ nsComputedDOMStyle::AppendTimingFunction
                                              tmp);
       break;
     default:
       nsStyleUtil::AppendCubicBezierKeywordTimingFunction(aTimingFunction.mType,
                                                           tmp);
       break;
   }
   timingFunction->SetString(tmp);
+  aValueList->AppendCSSValue(timingFunction.forget());
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetTransitionTimingFunction()
 {
   const nsStyleDisplay* display = StyleDisplay();
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
@@ -6126,27 +6159,27 @@ nsComputedDOMStyle::DoGetAnimationName()
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationNameCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* property = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(property);
+    RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
 
     const nsString& name = animation->GetName();
     if (name.IsEmpty()) {
       property->SetIdent(eCSSKeyword_none);
     } else {
       nsAutoString escaped;
       nsStyleUtil::AppendEscapedCSSIdent(animation->GetName(), escaped);
       property->SetString(escaped); // really want SetIdent
     }
+    valueList->AppendCSSValue(property.forget());
   } while (++i < display->mAnimationNameCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationDelay()
 {
@@ -6154,19 +6187,19 @@ nsComputedDOMStyle::DoGetAnimationDelay(
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationDelayCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* delay = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(delay);
+    RefPtr<nsROCSSPrimitiveValue> delay = new nsROCSSPrimitiveValue;
     delay->SetTime((float)animation->GetDelay() / (float)PR_MSEC_PER_SEC);
+    valueList->AppendCSSValue(delay.forget());
   } while (++i < display->mAnimationDelayCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationDuration()
 {
@@ -6174,20 +6207,20 @@ nsComputedDOMStyle::DoGetAnimationDurati
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationDurationCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* duration = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(duration);
+    RefPtr<nsROCSSPrimitiveValue> duration = new nsROCSSPrimitiveValue;
 
     duration->SetTime((float)animation->GetDuration() / (float)PR_MSEC_PER_SEC);
+    valueList->AppendCSSValue(duration.forget());
   } while (++i < display->mAnimationDurationCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationTimingFunction()
 {
@@ -6213,22 +6246,23 @@ nsComputedDOMStyle::DoGetAnimationDirect
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationDirectionCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* direction = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(direction);
+    RefPtr<nsROCSSPrimitiveValue> direction = new nsROCSSPrimitiveValue;
     direction->SetIdent(
       nsCSSProps::ValueToKeywordEnum(
         static_cast<int32_t>(animation->GetDirection()),
         nsCSSProps::kAnimationDirectionKTable));
+
+    valueList->AppendCSSValue(direction.forget());
   } while (++i < display->mAnimationDirectionCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationFillMode()
 {
@@ -6236,22 +6270,23 @@ nsComputedDOMStyle::DoGetAnimationFillMo
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationFillModeCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* fillMode = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(fillMode);
+    RefPtr<nsROCSSPrimitiveValue> fillMode = new nsROCSSPrimitiveValue;
     fillMode->SetIdent(
       nsCSSProps::ValueToKeywordEnum(
         static_cast<int32_t>(animation->GetFillMode()),
         nsCSSProps::kAnimationFillModeKTable));
+
+    valueList->AppendCSSValue(fillMode.forget());
   } while (++i < display->mAnimationFillModeCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationIterationCount()
 {
@@ -6259,33 +6294,33 @@ nsComputedDOMStyle::DoGetAnimationIterat
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationIterationCountCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* iterationCount = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(iterationCount);
+    RefPtr<nsROCSSPrimitiveValue> iterationCount = new nsROCSSPrimitiveValue;
 
     float f = animation->GetIterationCount();
     /* Need a nasty hack here to work around an optimizer bug in gcc
        4.2 on Mac, which somehow gets confused when directly comparing
        a float to the return value of NS_IEEEPositiveInfinity when
        building 32-bit builds. */
 #ifdef XP_MACOSX
     volatile
 #endif
       float inf = NS_IEEEPositiveInfinity();
     if (f == inf) {
       iterationCount->SetIdent(eCSSKeyword_infinite);
     } else {
       iterationCount->SetNumber(f);
     }
+    valueList->AppendCSSValue(iterationCount.forget());
   } while (++i < display->mAnimationIterationCountCount);
 
   return valueList;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAnimationPlayState()
 {
@@ -6293,21 +6328,21 @@ nsComputedDOMStyle::DoGetAnimationPlaySt
 
   nsDOMCSSValueList *valueList = GetROCSSValueList(true);
 
   MOZ_ASSERT(display->mAnimationPlayStateCount > 0,
              "first item must be explicit");
   uint32_t i = 0;
   do {
     const StyleAnimation *animation = &display->mAnimations[i];
-    nsROCSSPrimitiveValue* playState = new nsROCSSPrimitiveValue;
-    valueList->AppendCSSValue(playState);
+    RefPtr<nsROCSSPrimitiveValue> playState = new nsROCSSPrimitiveValue;
     playState->SetIdent(
       nsCSSProps::ValueToKeywordEnum(animation->GetPlayState(),
                                      nsCSSProps::kAnimationPlayStateKTable));
+    valueList->AppendCSSValue(playState.forget());
   } while (++i < display->mAnimationPlayStateCount);
 
   return valueList;
 }
 
 static void
 MarkComputedStyleMapDirty(const char* aPref, void* aData)
 {
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -602,17 +602,17 @@ private:
   bool GetScrollFrameContentHeight(nscoord& aHeight);
   bool GetFrameBoundsWidthForTransform(nscoord &aWidth);
   bool GetFrameBoundsHeightForTransform(nscoord &aHeight);
   bool GetFrameBorderRectWidth(nscoord& aWidth);
   bool GetFrameBorderRectHeight(nscoord& aHeight);
 
   /* Helper functions for computing the filter property style. */
   void SetCssTextToCoord(nsAString& aCssText, const nsStyleCoord& aCoord);
-  mozilla::dom::CSSValue* CreatePrimitiveValueForStyleFilter(
+  already_AddRefed<mozilla::dom::CSSValue> CreatePrimitiveValueForStyleFilter(
     const nsStyleFilter& aStyleFilter);
 
   // Helper function for computing basic shape styles.
   mozilla::dom::CSSValue* CreatePrimitiveValueForClipPath(
     const nsStyleBasicShape* aStyleBasicShape, uint8_t aSizingBox);
   void BoxValuesToString(nsAString& aString,
                          const nsTArray<nsStyleCoord>& aBoxValues);
   void BasicShapeRadiiToString(nsAString& aCssText,
--- a/layout/style/nsDOMCSSValueList.cpp
+++ b/layout/style/nsDOMCSSValueList.cpp
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 /* DOM object representing lists of values in DOM computed style */
 
 #include "nsDOMCSSValueList.h"
 #include "mozilla/dom/CSSValueListBinding.h"
+#include "mozilla/Move.h"
 #include "nsAutoPtr.h"
 
 using namespace mozilla;
 
 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
   : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
 {
 }
@@ -34,19 +35,20 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ns
 
 JSObject*
 nsDOMCSSValueList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
 {
   return dom::CSSValueListBinding::Wrap(cx, this, aGivenProto);
 }
 
 void
-nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue)
+nsDOMCSSValueList::AppendCSSValue(already_AddRefed<CSSValue> aValue)
 {
-  mCSSValues.AppendElement(aValue);
+  RefPtr<CSSValue> val = aValue;
+  mCSSValues.AppendElement(Move(val));
 }
 
 // nsIDOMCSSValue
 
 NS_IMETHODIMP
 nsDOMCSSValueList::GetCssText(nsAString& aCssText)
 {
   aCssText.Truncate();
--- a/layout/style/nsDOMCSSValueList.h
+++ b/layout/style/nsDOMCSSValueList.h
@@ -22,17 +22,17 @@ public:
   NS_DECL_NSIDOMCSSVALUE
 
   // nsDOMCSSValueList
   nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly);
 
   /**
    * Adds a value to this list.
    */
-  void AppendCSSValue(CSSValue* aValue);
+  void AppendCSSValue(already_AddRefed<CSSValue> aValue);
 
   virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv)
     override final;
   virtual void SetCssText(const nsAString& aText,
                           mozilla::ErrorResult& aRv) override final;
   virtual uint16_t CssValueType() const override final;
 
   CSSValue* IndexedGetter(uint32_t aIdx, bool& aFound) const