Bug 536789. Null-check the body, since we might not have one. r=dbaron

This commit is contained in:
Boris Zbarsky 2009-12-27 08:48:10 -05:00
parent e76b6c5c78
commit 797cfc02f1
3 changed files with 18 additions and 6 deletions

View File

@ -0,0 +1,11 @@
<!-- Must be in quirks mode -->
<html>
<body>
<script>
var docEl = document.documentElement;
var b = document.body;
docEl.removeChild(b);
docEl.appendChild(document.createElement("table"));
docEl.offsetWidth;
</script>
</html>

View File

@ -49,3 +49,4 @@ load 509155-1.html
load 509156-1.html
load 524252-1.html
load font-face-truncated-src.html
load 536789-1.html

View File

@ -63,7 +63,7 @@
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsStyleConsts.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsCSSAnonBoxes.h"
#include "nsRuleWalker.h"
@ -404,12 +404,12 @@ NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
static nsresult GetBodyColor(nsPresContext* aPresContext, nscolor* aColor)
{
nsIPresShell *shell = aPresContext->PresShell();
nsCOMPtr<nsIDOMHTMLDocument> domdoc = do_QueryInterface(shell->GetDocument());
if (!domdoc)
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(shell->GetDocument());
if (!htmlDoc)
return NS_ERROR_FAILURE;
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
if (!bodyContent)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLElement> body;
domdoc->GetBody(getter_AddRefs(body));
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
nsIFrame *bodyFrame = bodyContent->GetPrimaryFrame();
if (!bodyFrame)
return NS_ERROR_FAILURE;