diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 9141d12ebbb..27d9814dee2 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -861,18 +861,20 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame) if (!aAnchorFrame) { if (mAnchorContent) { nsCOMPtr document = mAnchorContent->GetDocument(); - nsIPresShell *shell = document->GetPrimaryShell(); - if (!shell) - return NS_ERROR_FAILURE; - - aAnchorFrame = shell->GetPrimaryFrameFor(mAnchorContent); - } - else { - aAnchorFrame = presContext->PresShell()->FrameManager()->GetRootFrame(); + if (document) { + nsIPresShell *shell = document->GetPrimaryShell(); + if (!shell) + return NS_ERROR_FAILURE; + + aAnchorFrame = shell->GetPrimaryFrameFor(mAnchorContent); + } } - if (!aAnchorFrame) - return NS_OK; + if (!aAnchorFrame) { + aAnchorFrame = presContext->PresShell()->FrameManager()->GetRootFrame(); + if (!aAnchorFrame) + return NS_OK; + } } if (aAnchorFrame->GetContent()) {