Bug 1100773 patch 2 - Convert style rule List methods to use fprintf_stderr. r=heycam
authorL. David Baron <dbaron@dbaron.org>
Wed, 26 Nov 2014 22:29:44 -0800
changeset 242143 6eefbe681697e947e88b2ddcd6329f76340c82c2
parent 242142 492dde6698f5cc7ae6a434409086d3829dadb16d
child 242144 3e2da595d50d4da8b43a9e65deac79603dd578f6
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1100773
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1100773 patch 2 - Convert style rule List methods to use fprintf_stderr. r=heycam Note that getting decent logcat output on Android and B2G requires not splitting lines of output across multiple fprintf_stderr calls.
dom/base/nsMappedAttributes.cpp
dom/html/HTMLBodyElement.cpp
layout/style/AnimationCommon.cpp
layout/style/CSSStyleSheet.cpp
layout/style/Declaration.cpp
layout/style/StyleRule.cpp
layout/style/nsCSSRules.cpp
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsStyleContext.cpp
layout/style/nsStyleSet.cpp
--- a/dom/base/nsMappedAttributes.cpp
+++ b/dom/base/nsMappedAttributes.cpp
@@ -182,31 +182,33 @@ nsMappedAttributes::MapRuleInfoInto(nsRu
     (*mRuleMapper)(this, aRuleData);
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsMappedAttributes::List(FILE* out, int32_t aIndent) const
 {
-  nsAutoString buffer;
+  nsAutoCString str;
+  nsAutoString tmp;
   uint32_t i;
 
   for (i = 0; i < mAttrCount; ++i) {
     int32_t indent;
     for (indent = aIndent; indent > 0; --indent) {
-      fputs("  ", out);
+      str.AppendLiteral("  ");
     }
 
-    Attrs()[i].mName.GetQualifiedName(buffer);
-    fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
+    Attrs()[i].mName.GetQualifiedName(tmp);
+    LossyAppendUTF16toASCII(tmp, str);
 
-    Attrs()[i].mValue.ToString(buffer);
-    fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
-    fputs("\n", out);
+    Attrs()[i].mValue.ToString(tmp);
+    LossyAppendUTF16toASCII(tmp, str);
+    str.Append('\n');
+    fprintf_stderr(out, "%s", str.get());
   }
 }
 #endif
 
 void
 nsMappedAttributes::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue)
 {
   Attrs()[aPos].mValue.SwapValueWith(aValue);
--- a/dom/html/HTMLBodyElement.cpp
+++ b/dom/html/HTMLBodyElement.cpp
@@ -166,20 +166,21 @@ BodyRule::MapRuleInfoInto(nsRuleData* aD
     }
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 BodyRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indent;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indent.AppendLiteral("  ");
   }
-  fputs("[body rule] {}\n", out);
+  fprintf_stderr(out, "%s[body rule] {}\n", indent.get());
 }
 #endif
 
 //----------------------------------------------------------------------
 
 HTMLBodyElement::~HTMLBodyElement()
 {
   if (mContentStyleRule) {
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -440,28 +440,32 @@ AnimValuesStyleRule::MapRuleInfoInto(nsR
     }
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
-  fputs("[anim values] { ", out);
+  str.AppendLiteral("[anim values] { ");
   for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
     const PropertyValuePair &pair = mPropertyValuePairs[i];
+    str.Append(nsCSSProps::GetStringValue(pair.mProperty));
+    str.AppendLiteral(": ");
     nsAutoString value;
     StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
-    fprintf(out, "%s: %s; ", nsCSSProps::GetStringValue(pair.mProperty).get(),
-                             NS_ConvertUTF16toUTF8(value).get());
+    AppendUTF16toUTF8(value, str);
+    str.AppendLiteral("; ");
   }
-  fputs("}\n", out);
+  str.AppendLiteral("}\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 } /* end sub-namespace css */
 
 bool
 AnimationPlayerCollection::CanAnimatePropertyOnCompositor(
   const dom::Element *aElement,
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -1550,42 +1550,44 @@ struct ListEnumData {
 
 /* virtual */ void
 CSSStyleSheet::List(FILE* out, int32_t aIndent) const
 {
 
   int32_t index;
 
   // Indent
+  nsAutoCString str;
   for (index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fputs("CSS Style Sheet: ", out);
+  str.AppendLiteral("CSS Style Sheet: ");
   nsAutoCString urlSpec;
   nsresult rv = mInner->mSheetURI->GetSpec(urlSpec);
   if (NS_SUCCEEDED(rv) && !urlSpec.IsEmpty()) {
-    fputs(urlSpec.get(), out);
+    str.Append(urlSpec);
   }
 
   if (mMedia) {
-    fputs(" media: ", out);
+    str.AppendLiteral(" media: ");
     nsAutoString  buffer;
     mMedia->GetText(buffer);
-    fputs(NS_ConvertUTF16toUTF8(buffer).get(), out);
+    AppendUTF16toUTF8(buffer, str);
   }
-  fputs("\n", out);
+  str.Append('\n');
+  fprintf_stderr(out, "%s", str.get());
 
   for (const CSSStyleSheet* child = mInner->mFirstChild;
        child;
        child = child->mNext) {
     child->List(out, aIndent + 1);
   }
 
-  fputs("Rules in source order:\n", out);
+  fprintf_stderr(out, "%s", "Rules in source order:\n");
   ListRules(mInner->mOrderedRules, out, aIndent);
 }
 #endif
 
 void 
 CSSStyleSheet::ClearRuleCascades()
 {
   if (mRuleProcessors) {
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -1352,25 +1352,27 @@ Declaration::ToString(nsAString& aString
     aString.Truncate(aString.Length() - 1);
   }
 }
 
 #ifdef DEBUG
 void
 Declaration::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fputs("{ ", out);
+  str.AppendLiteral("{ ");
   nsAutoString s;
   ToString(s);
-  fputs(NS_ConvertUTF16toUTF8(s).get(), out);
-  fputs("}", out);
+  AppendUTF16toUTF8(s, str);
+  str.AppendLiteral("}\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 bool
 Declaration::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
 {
   aReturn.Truncate();
   if (aIndex < mOrder.Length()) {
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -973,22 +973,23 @@ ImportantRule::MapRuleInfoInto(nsRuleDat
   mDeclaration->MapImportantRuleInfoInto(aRuleData);
 }
 
 #ifdef DEBUG
 /* virtual */ void
 ImportantRule::List(FILE* out, int32_t aIndent) const
 {
   // Indent
+  nsAutoCString str;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fprintf(out, "! Important declaration=%p\n",
-          static_cast<void*>(mDeclaration));
+  str.AppendLiteral("! important rule\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 } // namespace css
 } // namespace mozilla
 
 // --------------------------------------------------------
 
@@ -1468,34 +1469,40 @@ StyleRule::MapRuleInfoInto(nsRuleData* a
                     "somebody forgot to call css::StyleRule::RuleMatched");
   mDeclaration->MapNormalRuleInfoInto(aRuleData);
 }
 
 #ifdef DEBUG
 /* virtual */ void
 StyleRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   // Indent
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
   nsAutoString buffer;
-  if (mSelector)
+  if (mSelector) {
     mSelector->ToString(buffer, GetStyleSheet());
+    AppendUTF16toUTF8(buffer, str);
+    str.Append(' ');
+  }
 
-  buffer.Append(' ');
-  fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
   if (nullptr != mDeclaration) {
-    mDeclaration->List(out);
+    str.AppendLiteral("{ ");
+    mDeclaration->ToString(buffer);
+    AppendUTF16toUTF8(buffer, str);
+    str.Append('}');
   }
   else {
-    fputs("{ null declaration }", out);
+    str.AppendLiteral("{ null declaration }");
   }
-  fputs("\n", out);
+  str.Append('\n');
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 void
 StyleRule::GetCssText(nsAString& aCssText)
 {
   if (mSelector) {
     mSelector->ToString(aCssText, GetStyleSheet());
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -234,24 +234,26 @@ NS_INTERFACE_MAP_BEGIN(CharsetRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(CharsetRule, Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 CharsetRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   // Indent
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fputs("@charset \"", out);
-  fputs(NS_LossyConvertUTF16toASCII(mEncoding).get(), out);
-  fputs("\"\n", out);
+  str.AppendLiteral("@charset \"");
+  AppendUTF16toUTF8(mEncoding, str);
+  str.AppendLiteral("\"\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 /* virtual */ int32_t
 CharsetRule::GetType() const
 {
   return Rule::CHARSET_RULE;
 }
@@ -379,29 +381,31 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(ImportRule, Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 ImportRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   // Indent
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fputs("@import \"", out);
-  fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
-  fputs("\" ", out);
+  str.AppendLiteral("@import \"");
+  AppendUTF16toUTF8(mURLSpec, str);
+  str.AppendLiteral("\" ");
 
   nsAutoString mediaText;
   mMedia->GetText(mediaText);
-  fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
-  fputs("\n", out);
+  AppendUTF16toUTF8(mediaText, str);
+  str.AppendLiteral("\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 /* virtual */ int32_t
 ImportRule::GetType() const
 {
   return Rule::IMPORT_RULE;
 }
@@ -601,26 +605,19 @@ GroupRule::SetStyleSheet(CSSStyleSheet* 
     Rule::SetStyleSheet(aSheet);
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 GroupRule::List(FILE* out, int32_t aIndent) const
 {
-  fputs(" {\n", out);
-
   for (int32_t index = 0, count = mRules.Count(); index < count; ++index) {
     mRules.ObjectAt(index)->List(out, aIndent + 1);
   }
-
-  for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
-  }
-  fputs("}\n", out);
 }
 #endif
 
 void
 GroupRule::AppendStyleRule(Rule* aRule)
 {
   mRules.AppendObject(aRule);
   CSSStyleSheet* sheet = GetStyleSheet();
@@ -810,31 +807,36 @@ MediaRule::SetStyleSheet(CSSStyleSheet* 
 
   GroupRule::SetStyleSheet(aSheet);
 }
 
 #ifdef DEBUG
 /* virtual */ void
 MediaRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
 
-  nsAutoString  buffer;
-
-  fputs("@media ", out);
+  nsAutoCString str(indentStr);
+  str.AppendLiteral("@media ");
 
   if (mMedia) {
     nsAutoString mediaText;
     mMedia->GetText(mediaText);
-    fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
+    AppendUTF16toUTF8(mediaText, str);
   }
 
+  str.AppendLiteral(" {\n");
+  fprintf_stderr(out, "%s", str.get());
+
   GroupRule::List(out, aIndent);
+
+  fprintf_stderr(out, "%s}\n", indentStr.get());
 }
 #endif
 
 /* virtual */ int32_t
 MediaRule::GetType() const
 {
   return Rule::MEDIA_RULE;
 }
@@ -1011,22 +1013,23 @@ NS_INTERFACE_MAP_BEGIN(DocumentRule)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
 
 #ifdef DEBUG
 /* virtual */ void
 DocumentRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
 
   nsAutoCString str;
-  str.AssignLiteral("@-moz-document ");
+  str.AppendLiteral("@-moz-document ");
   for (URL *url = mURLs; url; url = url->next) {
     switch (url->func) {
       case eURL:
         str.AppendLiteral("url(\"");
         break;
       case eURLPrefix:
         str.AppendLiteral("url-prefix(\"");
         break;
@@ -1038,19 +1041,21 @@ DocumentRule::List(FILE* out, int32_t aI
         break;
     }
     nsAutoCString escapedURL(url->url);
     escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
     str.Append(escapedURL);
     str.AppendLiteral("\"), ");
   }
   str.Cut(str.Length() - 2, 1); // remove last ,
-  fputs(str.get(), out);
+  fprintf_stderr(out, "%s%s {\n", indentStr.get(), str.get());
 
   GroupRule::List(out, aIndent);
+
+  fprintf_stderr(out, "%s}\n", indentStr.get());
 }
 #endif
 
 /* virtual */ int32_t
 DocumentRule::GetType() const
 {
   return Rule::DOCUMENT_RULE;
 }
@@ -1270,33 +1275,35 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule)
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule)
 
 #ifdef DEBUG
 /* virtual */ void
 NameSpaceRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
   nsAutoString  buffer;
 
-  fputs("@namespace ", out);
+  str.AppendLiteral("@namespace ");
 
   if (mPrefix) {
     mPrefix->ToString(buffer);
-    fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
-    fputs(" ", out);
+    AppendUTF16toUTF8(buffer, str);
+    str.Append(' ');
   }
 
-  fputs("url(", out);
-  fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
-  fputs(")\n", out);
+  str.AppendLiteral("url(\"");
+  AppendUTF16toUTF8(mURLSpec, str);
+  str.AppendLiteral("\")\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 /* virtual */ int32_t
 NameSpaceRule::GetType() const
 {
   return Rule::NAMESPACE_RULE;
 }
@@ -1720,30 +1727,30 @@ nsCSSFontFaceRule::List(FILE* out, int32
   for (int32_t indent = aIndent; --indent >= 0; ) {
     baseInd.AppendLiteral("  ");
     descInd.AppendLiteral("  ");
   }
   descInd.AppendLiteral("  ");
 
   nsString descStr;
 
-  fprintf(out, "%s@font-face {\n", baseInd.get());
+  fprintf_stderr(out, "%s@font-face {\n", baseInd.get());
   for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
        id < eCSSFontDesc_COUNT;
        id = nsCSSFontDesc(id + 1))
     if (mDecl.mDescriptors.Get(id).GetUnit() != eCSSUnit_Null) {
       if (NS_FAILED(mDecl.GetPropertyValue(id, descStr)))
         descStr.AssignLiteral("#<serialization error>");
       else if (descStr.Length() == 0)
         descStr.AssignLiteral("#<serialization missing>");
-      fprintf(out, "%s%s: %s\n",
-              descInd.get(), nsCSSProps::GetStringValue(id).get(),
-              NS_ConvertUTF16toUTF8(descStr).get());
+      fprintf_stderr(out, "%s%s: %s\n",
+                     descInd.get(), nsCSSProps::GetStringValue(id).get(),
+                     NS_ConvertUTF16toUTF8(descStr).get());
     }
-  fprintf(out, "%s}\n", baseInd.get());
+  fprintf_stderr(out, "%s}\n", baseInd.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSFontFaceRule::GetType() const
 {
   return Rule::FONT_FACE_RULE;
 }
@@ -1926,20 +1933,21 @@ nsCSSFontFeatureValuesRule::List(FILE* o
   for (i = 1; i < (aIndent + 1) * 2 - 1; i++) {
     indent[i] = 0x20;
   }
   indent[0] = 0xa;
   indent[aIndent * 2 + 1] = 0;
   utf8.ReplaceSubstring("\n", indent);
   delete [] indent;
 
+  nsAutoCString indentStr;
   for (i = aIndent; --i >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fprintf(out, "%s\n", utf8.get());
+  fprintf_stderr(out, "%s%s\n", indentStr.get(), utf8.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSFontFeatureValuesRule::GetType() const
 {
   return Rule::FONT_FEATURE_VALUES_RULE;
 }
@@ -2204,26 +2212,29 @@ nsCSSKeyframeRule::MapRuleInfoInto(nsRul
 
   mDeclaration->MapNormalRuleInfoInto(aRuleData);
 }
 
 #ifdef DEBUG
 void
 nsCSSKeyframeRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
   nsAutoString tmp;
   DoGetKeyText(tmp);
-  fputs(NS_ConvertUTF16toUTF8(tmp).get(), out);
-  fputs(" ", out);
-  mDeclaration->List(out, aIndent);
-  fputs("\n", out);
+  AppendUTF16toUTF8(tmp, str);
+  str.AppendLiteral(" { ");
+  mDeclaration->ToString(tmp);
+  AppendUTF16toUTF8(tmp, str);
+  str.AppendLiteral("}\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSKeyframeRule::GetType() const
 {
   return Rule::KEYFRAME_RULE;
 }
@@ -2407,22 +2418,27 @@ NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRul
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframesRule)
 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
 
 #ifdef DEBUG
 void
 nsCSSKeyframesRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
 
-  fprintf(out, "@keyframes %s", NS_ConvertUTF16toUTF8(mName).get());
+  fprintf_stderr(out, "%s@keyframes %s {\n",
+                 indentStr.get(), NS_ConvertUTF16toUTF8(mName).get());
+
   GroupRule::List(out, aIndent);
+
+  fprintf_stderr(out, "%s}\n", indentStr.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSKeyframesRule::GetType() const
 {
   return Rule::KEYFRAMES_RULE;
 }
@@ -2742,23 +2758,27 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END
 
 IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule)
 
 #ifdef DEBUG
 void
 nsCSSPageRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
 
-  fputs("@page ", out);
-  mDeclaration->List(out, aIndent);
-  fputs("\n", out);
+  str.AppendLiteral("@page { ");
+  nsAutoString tmp;
+  mDeclaration->ToString(tmp);
+  AppendUTF16toUTF8(tmp, str);
+  str.AppendLiteral("}\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSPageRule::GetType() const
 {
   return Rule::PAGE_RULE;
 }
@@ -2877,23 +2897,27 @@ CSSSupportsRule::CSSSupportsRule(const C
     mCondition(aCopy.mCondition)
 {
 }
 
 #ifdef DEBUG
 /* virtual */ void
 CSSSupportsRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t indent = aIndent; --indent >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
 
-  fputs("@supports ", out);
-  fputs(NS_ConvertUTF16toUTF8(mCondition).get(), out);
+  fprintf_stderr(out, "%s@supports %s {\n",
+                 indentStr.get(), NS_ConvertUTF16toUTF8(mCondition).get());
+
   css::GroupRule::List(out, aIndent);
+
+  fprintf_stderr(out, "%s}\n", indentStr.get());
 }
 #endif
 
 /* virtual */ int32_t
 CSSSupportsRule::GetType() const
 {
   return Rule::SUPPORTS_RULE;
 }
@@ -3063,20 +3087,21 @@ nsCSSCounterStyleRule::List(FILE* out, i
 {
   nsCString baseInd, descInd;
   for (int32_t indent = aIndent; --indent >= 0; ) {
     baseInd.AppendLiteral("  ");
   }
   descInd = baseInd;
   descInd.AppendLiteral("  ");
 
-  fprintf(out, "%s@counter-style %s (rev.%u) {\n",
-          baseInd.get(), NS_ConvertUTF16toUTF8(mName).get(), mGeneration);
+  fprintf_stderr(out, "%s@counter-style %s (rev.%u) {\n",
+                 baseInd.get(), NS_ConvertUTF16toUTF8(mName).get(),
+                 mGeneration);
   // TODO
-  fprintf(out, "%s}\n", baseInd.get());
+  fprintf_stderr(out, "%s}\n", baseInd.get());
 }
 #endif
 
 /* virtual */ int32_t
 nsCSSCounterStyleRule::GetType() const
 {
   return Rule::COUNTER_STYLE_RULE;
 }
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -50,34 +50,36 @@ nsHTMLStyleSheet::HTMLColorRule::MapRule
       color->SetColorValue(mColor);
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fputs("[html color rule] {}\n", out);
+  fprintf_stderr(out, "%s[html color rule] {}\n", indentStr.get());
 }
 #endif
 
  
 NS_IMPL_ISUPPORTS(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule)
 
 #ifdef DEBUG
 /* virtual */ void
 nsHTMLStyleSheet::GenericTableRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fputs("[generic table rule] {}\n", out);
+  fprintf_stderr(out, "%s[generic table rule] {}\n", indentStr.get());
 }
 #endif
 
 /* virtual */ void
 nsHTMLStyleSheet::TableTHRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
   if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
     nsCSSValue* textAlign = aRuleData->ValueForTextAlign();
@@ -114,22 +116,24 @@ nsHTMLStyleSheet::LangRule::MapRuleInfoI
     }
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsHTMLStyleSheet::LangRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString str;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
-  fputs("[lang rule] { language: \"", out);
-  fputs(NS_ConvertUTF16toUTF8(mLang).get(), out);
-  fputs("\" }\n", out);
+  str.AppendLiteral("[lang rule] { language: \"");
+  AppendUTF16toUTF8(mLang, str);
+  str.AppendLiteral("\" }\n");
+  fprintf_stderr(out, "%s", str.get());
 }
 #endif
 
 // -----------------------------------------------------------
 
 struct MappedAttrTableEntry : public PLDHashEntryHdr {
   nsMappedAttributes *mAttributes;
 };
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -855,47 +855,49 @@ nsStyleContext::Mark()
       child = child->mNextSibling;
     } while (mEmptyChild != child);
   }
 }
 
 #ifdef DEBUG
 void nsStyleContext::List(FILE* out, int32_t aIndent)
 {
+  nsAutoCString str;
   // Indent
   int32_t ix;
   for (ix = aIndent; --ix >= 0; ) {
-    fputs("  ", out);
+    str.AppendLiteral("  ");
   }
-  fprintf(out, "%p(%d) parent=%p ",
-          (void*)this, mRefCnt, (void *)mParent);
+  str.Append(nsPrintfCString("%p(%d) parent=%p ",
+                             (void*)this, mRefCnt, (void *)mParent));
   if (mPseudoTag) {
     nsAutoString  buffer;
     mPseudoTag->ToString(buffer);
-    fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
-    fputs(" ", out);
+    AppendUTF16toUTF8(buffer, str);
+    str.Append(' ');
   }
 
   if (mRuleNode) {
-    fputs("{\n", out);
+    fprintf_stderr(out, "%s{\n", str.get());
+    str.Truncate();
     nsRuleNode* ruleNode = mRuleNode;
     while (ruleNode) {
       nsIStyleRule *styleRule = ruleNode->GetRule();
       if (styleRule) {
         styleRule->List(out, aIndent + 1);
       }
       ruleNode = ruleNode->GetParent();
     }
     for (ix = aIndent; --ix >= 0; ) {
-      fputs("  ", out);
+      str.AppendLiteral("  ");
     }
-    fputs("}\n", out);
+    fprintf_stderr(out, "%s}\n", str.get());
   }
   else {
-    fputs("{}\n", out);
+    fprintf_stderr(out, "%s{}\n", str.get());
   }
 
   if (nullptr != mChild) {
     nsStyleContext* child = mChild;
     do {
       child->List(out, aIndent + 1);
       child = child->mNextSibling;
     } while (mChild != child);
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -48,20 +48,21 @@ NS_IMPL_ISUPPORTS(nsEmptyStyleRule, nsIS
 nsEmptyStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsEmptyStyleRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fputs("[empty style rule] {}\n", out);
+  fprintf_stderr(out, "%s[empty style rule] {}\n", indentStr.get());
 }
 #endif
 
 NS_IMPL_ISUPPORTS(nsInitialStyleRule, nsIStyleRule)
 
 /* virtual */ void
 nsInitialStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
@@ -100,20 +101,21 @@ nsInitialStyleRule::MapRuleInfoInto(nsRu
     }
   }
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsInitialStyleRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fputs("[initial style rule] {}\n", out);
+  fprintf_stderr(out, "%s[initial style rule] {}\n", indentStr.get());
 }
 #endif
 
 NS_IMPL_ISUPPORTS(nsDisableTextZoomStyleRule, nsIStyleRule)
 
 /* virtual */ void
 nsDisableTextZoomStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
 {
@@ -124,20 +126,21 @@ nsDisableTextZoomStyleRule::MapRuleInfoI
   if (value->GetUnit() == eCSSUnit_Null)
     value->SetNoneValue();
 }
 
 #ifdef DEBUG
 /* virtual */ void
 nsDisableTextZoomStyleRule::List(FILE* out, int32_t aIndent) const
 {
+  nsAutoCString indentStr;
   for (int32_t index = aIndent; --index >= 0; ) {
-    fputs("  ", out);
+    indentStr.AppendLiteral("  ");
   }
-  fputs("[disable text zoom style rule] {}\n", out);
+  fprintf_stderr(out, "%s[disable text zoom style rule] {}\n", indentStr.get());
 }
 #endif
 
 static const nsStyleSet::sheetType gCSSSheetTypes[] = {
   // From lowest to highest in cascading order.
   nsStyleSet::eAgentSheet,
   nsStyleSet::eUserSheet,
   nsStyleSet::eDocSheet,