diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 0954b2170cbf..5b707b4a7aec 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -857,15 +857,19 @@ nsRect Element::GetClientAreaRect() { nsIFrame* frame; if (nsIScrollableFrame* sf = GetScrollFrame(&frame)) { - MOZ_ASSERT(frame); nsRect scrollPort = sf->GetScrollPortRect(); - nsIFrame* scrollableAsFrame = do_QueryFrame(sf); - // We want the offset to be relative to `frame`, not `sf`... Except for the - // root scroll frame, which is an ancestor of frame rather than a descendant - // and thus this wouldn't particularly make sense. - if (frame != scrollableAsFrame && !sf->IsRootScrollFrameOfDocument()) { - scrollPort.MoveBy(scrollableAsFrame->GetOffsetTo(frame)); + + if (!sf->IsRootScrollFrameOfDocument()) { + MOZ_ASSERT(frame); + nsIFrame* scrollableAsFrame = do_QueryFrame(sf); + // We want the offset to be relative to `frame`, not `sf`... Except for + // the root scroll frame, which is an ancestor of frame rather than a + // descendant and thus this wouldn't particularly make sense. + if (frame != scrollableAsFrame) { + scrollPort.MoveBy(scrollableAsFrame->GetOffsetTo(frame)); + } } + // The scroll port value might be expanded to the minimum scale size, we // should limit the size to the ICB in such cases. scrollPort.SizeTo(sf->GetLayoutSize()); diff --git a/testing/web-platform/tests/css/cssom-view/client-props-root-display-none-crash.html b/testing/web-platform/tests/css/cssom-view/client-props-root-display-none-crash.html new file mode 100644 index 000000000000..19ad465a5d00 --- /dev/null +++ b/testing/web-platform/tests/css/cssom-view/client-props-root-display-none-crash.html @@ -0,0 +1,11 @@ + +