From 375ecaad19401fb618e5fc277dfd872668536232 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 31 Jul 2008 17:16:56 -0700 Subject: [PATCH] Bug 448161. Don't crash when getting computed style for a link that's not in the document --- layout/style/crashtests/448161-1.html | 22 ++++++++++++++++++++++ layout/style/crashtests/448161-2.html | 9 +++++++++ layout/style/crashtests/crashtests.list | 2 ++ layout/style/nsStyleUtil.cpp | 7 +++---- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 layout/style/crashtests/448161-1.html create mode 100644 layout/style/crashtests/448161-2.html diff --git a/layout/style/crashtests/448161-1.html b/layout/style/crashtests/448161-1.html new file mode 100644 index 000000000000..ef200462b5f4 --- /dev/null +++ b/layout/style/crashtests/448161-1.html @@ -0,0 +1,22 @@ + + + + + +5 + + diff --git a/layout/style/crashtests/448161-2.html b/layout/style/crashtests/448161-2.html new file mode 100644 index 000000000000..41dc7800fce7 --- /dev/null +++ b/layout/style/crashtests/448161-2.html @@ -0,0 +1,9 @@ + + + + + diff --git a/layout/style/crashtests/crashtests.list b/layout/style/crashtests/crashtests.list index 23accb66c359..121f32381d1c 100644 --- a/layout/style/crashtests/crashtests.list +++ b/layout/style/crashtests/crashtests.list @@ -18,3 +18,5 @@ load 444237-1.html load 444848-1.html load 447776-1.html load 447783-1.html +load 448161-1.html +load 448161-2.html diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index 88c7e84f0676..e1738c5feca0 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -466,8 +466,8 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, } else { linkState = eLinkState_NotLink; } - if (linkState != eLinkState_NotLink && aForStyling) { - NS_ASSERTION(aContent->GetCurrentDoc(), "Must have document!"); + if (linkState != eLinkState_NotLink && aForStyling && + aContent->IsInDoc()) { aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, hrefURI); } link->SetLinkState(linkState); @@ -500,8 +500,7 @@ PRBool nsStyleUtil::IsLink(nsIContent *aContent, nsCOMPtr absURI; if (aContent->IsLink(getter_AddRefs(absURI))) { *aState = GetLinkStateFromURI(absURI, aContent, aLinkHandler); - if (aForStyling) { - NS_ASSERTION(aContent->GetCurrentDoc(), "Must have document!"); + if (aForStyling && aContent->IsInDoc()) { aContent->GetCurrentDoc()->AddStyleRelevantLink(aContent, absURI); }