diff --git a/dom/base/nsViewportInfo.cpp b/dom/base/nsViewportInfo.cpp index 6c86b7f0a92c..8c01dafdedac 100644 --- a/dom/base/nsViewportInfo.cpp +++ b/dom/base/nsViewportInfo.cpp @@ -11,6 +11,11 @@ using namespace mozilla; void nsViewportInfo::ConstrainViewportValues() { + // Non-positive zoom factors can produce NaN or negative viewport sizes, + // so we better be sure our constraints will produce positive zoom factors. + MOZ_ASSERT(mMinZoom > CSSToScreenScale(0.0f), "zoom factor must be positive"); + MOZ_ASSERT(mMaxZoom > CSSToScreenScale(0.0f), "zoom factor must be positive"); + if (mDefaultZoom > mMaxZoom) { mDefaultZoomValid = false; mDefaultZoom = mMaxZoom; diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp index 1010cd3ad1e0..97c70ad677a4 100644 --- a/layout/base/MobileViewportManager.cpp +++ b/layout/base/MobileViewportManager.cpp @@ -219,6 +219,10 @@ void MobileViewportManager::UpdateResolution( CSSToLayoutDeviceScale cssToDev = mContext->CSSToDevPixelScale(); LayoutDeviceToLayerScale res(mContext->GetResolution()); CSSToScreenScale zoom = ResolutionToZoom(res, cssToDev); + // Non-positive zoom factors can produce NaN or negative viewport sizes, + // so we better be sure we've got a positive zoom factor. + MOZ_ASSERT(zoom > CSSToScreenScale(0.0f), "zoom factor must be positive"); + Maybe newZoom; ScreenIntSize compositionSize = GetCompositionSize(aDisplaySize); @@ -391,6 +395,10 @@ void MobileViewportManager::UpdateResolution( // If the zoom has changed, update the pres shell resolution accordingly. if (newZoom) { + // Non-positive zoom factors can produce NaN or negative viewport sizes, + // so we better be sure we've got a positive zoom factor. + MOZ_ASSERT(*newZoom > CSSToScreenScale(0.0f), + "zoom factor must be positive"); LayoutDeviceToLayerScale resolution = ZoomToResolution(*newZoom, cssToDev); MVM_LOG("%p: setting resolution %f\n", this, resolution.scale); mContext->SetResolutionAndScaleTo(resolution.scale);