Bug 448161. Don't crash when getting computed style for a link that's not in the document

This commit is contained in:
Boris Zbarsky 2008-07-31 17:16:56 -07:00
parent afcaac529f
commit 4a8827b86c
4 changed files with 36 additions and 4 deletions

View File

@ -0,0 +1,22 @@
<html class="reftest-wait">
<head>
<script type="text/javascript">
function boom()
{
var r = document.createRange();
r.setStart(document.body, 0);
r.setEnd(document.getElementById("g"), 0);
r.deleteContents();
// Give spell-check a chance to run
setTimeout(function() { document.documentElement.className = ""; },
50);
}
</script>
</head>
<body onload="boom();" contenteditable="true"><span><span contenteditable="true"><a href="http://www.mozilla.org/">5</a></span></span><span id="g"></span></body>
</html>

View File

@ -0,0 +1,9 @@
<html>
<body>
<script>
var node = document.createElement("a");
node.href = "http://www.mozilla.org";
document.defaultView.getComputedStyle(node, "").color
</script>
</body>
</html>

View File

@ -18,3 +18,5 @@ load 444237-1.html
load 444848-1.html load 444848-1.html
load 447776-1.html load 447776-1.html
load 447783-1.html load 447783-1.html
load 448161-1.html
load 448161-2.html

View File

@ -466,8 +466,8 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag,
} else { } else {
linkState = eLinkState_NotLink; linkState = eLinkState_NotLink;
} }
if (linkState != eLinkState_NotLink && aForStyling) { if (linkState != eLinkState_NotLink && aForStyling &&
NS_ASSERTION(aContent->GetCurrentDoc(), "Must have document!"); aContent->IsInDoc()) {
aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, hrefURI); aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, hrefURI);
} }
link->SetLinkState(linkState); link->SetLinkState(linkState);
@ -500,8 +500,7 @@ PRBool nsStyleUtil::IsLink(nsIContent *aContent,
nsCOMPtr<nsIURI> absURI; nsCOMPtr<nsIURI> absURI;
if (aContent->IsLink(getter_AddRefs(absURI))) { if (aContent->IsLink(getter_AddRefs(absURI))) {
*aState = GetLinkStateFromURI(absURI, aContent, aLinkHandler); *aState = GetLinkStateFromURI(absURI, aContent, aLinkHandler);
if (aForStyling) { if (aForStyling && aContent->IsInDoc()) {
NS_ASSERTION(aContent->GetCurrentDoc(), "Must have document!");
aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, absURI); aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, absURI);
} }