diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index fc5607468b6..8faacd8a8ae 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1578,10 +1578,12 @@ nsHTMLDocument::GetURL(nsAString& aURL)
}
nsIContent*
-nsHTMLDocument::GetBody()
+nsHTMLDocument::GetBody(nsresult *aResult)
{
Element* body = GetBodyElement();
+ *aResult = NS_OK;
+
if (body) {
// There is a body element, return that as the body.
return body;
@@ -1599,20 +1601,24 @@ nsHTMLDocument::GetBody()
NS_LITERAL_STRING("frameset"));
}
- return nodeList ? nodeList->GetNodeAt(0) : nsnull;
+ if (!nodeList) {
+ *aResult = NS_ERROR_OUT_OF_MEMORY;
+
+ return nsnull;
+ }
+
+ return nodeList->GetNodeAt(0);
}
NS_IMETHODIMP
nsHTMLDocument::GetBody(nsIDOMHTMLElement** aBody)
{
- nsIContent *body = GetBody();
- if (!body) {
- *aBody = nsnull;
+ *aBody = nsnull;
- return NS_ERROR_OUT_OF_MEMORY;
- }
+ nsresult rv;
+ nsIContent *body = GetBody(&rv);
- return CallQueryInterface(body, aBody);
+ return body ? CallQueryInterface(body, aBody) : rv;
}
NS_IMETHODIMP
diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h
index 6aec5d4f7b5..ead314f6dc6 100644
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -160,7 +160,7 @@ public:
nsIDOMNodeList **_retval);
virtual nsresult GetDocumentAllResult(const nsAString& aID,
nsISupports** aResult);
- nsIContent *GetBody();
+ nsIContent *GetBody(nsresult *aResult);
already_AddRefed GetElementsByName(const nsAString & aName)
{
nsString* elementNameData = new nsString(aName);
diff --git a/js/src/xpconnect/src/dom_quickstubs.qsconf b/js/src/xpconnect/src/dom_quickstubs.qsconf
index da49b3a49a6..bddf697d0a0 100644
--- a/js/src/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/src/xpconnect/src/dom_quickstubs.qsconf
@@ -648,8 +648,7 @@ customMethodCalls = {
},
'nsIDOMHTMLDocument_GetBody': {
'thisType': 'nsHTMLDocument',
- 'code': ' nsIContent *result = self->GetBody();',
- 'canFail': False
+ 'code': ' nsIContent *result = self->GetBody(&rv);'
},
'nsIDOMHTMLDocument_GetElementsByName': {
'thisType': 'nsHTMLDocument',