From 8a61cca04b4cf3e926d7c8b6cf36bd42cac5e5ce Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Wed, 19 Mar 2014 13:05:03 -0400 Subject: [PATCH] Bug 950076 - Propagate OOM errors to innerHTML getters. r=jst --- content/base/public/nsContentUtils.h | 5 +++-- content/base/src/nsContentUtils.cpp | 4 ++-- content/html/content/src/HTMLElement.cpp | 4 +++- content/html/content/src/HTMLScriptElement.cpp | 4 +++- content/html/content/src/HTMLStyleElement.cpp | 4 +++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index f1973b7a2c4..d2c407f2401 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -1240,9 +1240,10 @@ public: * @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. diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index c1917a99c60..8c5e5c6d3b6 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -6587,11 +6587,11 @@ nsContentUtils::DOMWindowDumpEnabled() #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 diff --git a/content/html/content/src/HTMLElement.cpp b/content/html/content/src/HTMLElement.cpp index cebcd71615d..f9defac70e3 100644 --- a/content/html/content/src/HTMLElement.cpp +++ b/content/html/content/src/HTMLElement.cpp @@ -49,7 +49,9 @@ HTMLElement::GetInnerHTML(nsAString& aInnerHTML) */ 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; } diff --git a/content/html/content/src/HTMLScriptElement.cpp b/content/html/content/src/HTMLScriptElement.cpp index e9570c45edc..6621035a944 100644 --- a/content/html/content/src/HTMLScriptElement.cpp +++ b/content/html/content/src/HTMLScriptElement.cpp @@ -227,7 +227,9 @@ HTMLScriptElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, 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; } diff --git a/content/html/content/src/HTMLStyleElement.cpp b/content/html/content/src/HTMLStyleElement.cpp index 5d6a01527d9..fb06bfa7f2e 100644 --- a/content/html/content/src/HTMLStyleElement.cpp +++ b/content/html/content/src/HTMLStyleElement.cpp @@ -204,7 +204,9 @@ HTMLStyleElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, 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; }