Bug 950076 - Propagate OOM errors to innerHTML getters. r=jst
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Wed, 19 Mar 2014 13:05:03 -0400
changeset 193255 b7da9111c2e9607ed96fd3c3c95df25f04fe3e5b
parent 193254 9fc71a41bee5c261b4650b06dc0ff2b694dbb32d
child 193256 4b55547f3b36a8decc06e524ae47c31cf2ef0579
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs950076
milestone31.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 950076 - Propagate OOM errors to innerHTML getters. r=jst
content/base/public/nsContentUtils.h
content/base/src/nsContentUtils.cpp
content/html/content/src/HTMLElement.cpp
content/html/content/src/HTMLScriptElement.cpp
content/html/content/src/HTMLStyleElement.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1235,19 +1235,20 @@ public:
    * NOTE! No serialization takes place and <br> elements
    * are not converted into newlines. Only textnodes and cdata nodes are
    * added to the result.
    *
    * @param aNode Node to get textual contents of.
    * @param aDeep If true child elements of aNode are recursivly descended
    *              into to find text children.
    * @param aResult the result. Out param.
+   * @return false on out of memory errors, true otherwise.
    */
-  static void GetNodeTextContent(nsINode* aNode, bool aDeep,
-                                 nsAString& aResult);
+  static bool GetNodeTextContent(nsINode* aNode, bool aDeep,
+                                 nsAString& aResult) NS_WARN_UNUSED_RESULT;
 
   /**
    * Same as GetNodeTextContents but appends the result rather than sets it.
    */
   static bool AppendNodeTextContent(nsINode* aNode, bool aDeep,
                                     nsAString& aResult, const mozilla::fallible_t&);
 
   /**
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -6582,21 +6582,21 @@ nsContentUtils::DOMWindowDumpEnabled()
   // enable output from dump() or not, in debug builds it's always
   // enabled.
   return nsContentUtils::sDOMWindowDumpEnabled;
 #else
   return true;
 #endif
 }
 
-void
+bool
 nsContentUtils::GetNodeTextContent(nsINode* aNode, bool aDeep, nsAString& aResult)
 {
   aResult.Truncate();
-  AppendNodeTextContent(aNode, aDeep, aResult, mozilla::fallible_t());
+  return AppendNodeTextContent(aNode, aDeep, aResult, mozilla::fallible_t());
 }
 
 void
 nsContentUtils::DestroyMatchString(void* aData)
 {
   if (aData) {
     nsString* matchString = static_cast<nsString*>(aData);
     delete matchString;
--- a/content/html/content/src/HTMLElement.cpp
+++ b/content/html/content/src/HTMLElement.cpp
@@ -44,17 +44,19 @@ HTMLElement::GetInnerHTML(nsAString& aIn
    * nsGenericHTMLElement::GetInnerHTML escapes < and > characters (at least).
    * .innerHTML should return the HTML code for xmp and plaintext element.
    *
    * This code is a workaround until we implement a HTML5 Serializer
    * with this behavior.
    */
   if (mNodeInfo->Equals(nsGkAtoms::xmp) ||
       mNodeInfo->Equals(nsGkAtoms::plaintext)) {
-    nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
+    if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML)) {
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
     return NS_OK;
   }
 
   return nsGenericHTMLElement::GetInnerHTML(aInnerHTML);
 }
 
 JSObject*
 HTMLElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
--- a/content/html/content/src/HTMLScriptElement.cpp
+++ b/content/html/content/src/HTMLScriptElement.cpp
@@ -222,17 +222,19 @@ HTMLScriptElement::AfterSetAttr(int32_t 
   }
   return nsGenericHTMLElement::AfterSetAttr(aNamespaceID, aName, aValue,
                                             aNotify);
 }
 
 NS_IMETHODIMP
 HTMLScriptElement::GetInnerHTML(nsAString& aInnerHTML)
 {
-  nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
+  if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
   return NS_OK;
 }
 
 void
 HTMLScriptElement::SetInnerHTML(const nsAString& aInnerHTML,
                                 ErrorResult& aError)
 {
   aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
--- a/content/html/content/src/HTMLStyleElement.cpp
+++ b/content/html/content/src/HTMLStyleElement.cpp
@@ -199,17 +199,19 @@ HTMLStyleElement::UnsetAttr(int32_t aNam
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML)
 {
-  nsContentUtils::GetNodeTextContent(this, false, aInnerHTML);
+  if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
   return NS_OK;
 }
 
 void
 HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
                                ErrorResult& aError)
 {
   SetEnableUpdates(false);