From acbc420513c665660a74b53cc65b052776f69bf3 Mon Sep 17 00:00:00 2001 From: vincentliu Date: Tue, 19 Jul 2016 10:52:50 +0800 Subject: [PATCH] Bug 1281800 - The API should return an empty array if maxWidth was provided but is less than or equal to zero or equal to NaN. r=jrmuizel --- dom/canvas/CanvasRenderingContext2D.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- dom/canvas/CanvasRenderingContext2D.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index aea815ebc126..1321140c7d49 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -3910,13 +3910,6 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText, { nsresult rv; - // spec isn't clear on what should happen if aMaxWidth <= 0, so - // treat it as an invalid argument - // technically, 0 should be an invalid value as well, but 0 is the default - // arg, and there is no way to tell if the default was used - if (aMaxWidth.WasPassed() && aMaxWidth.Value() < 0) - return NS_ERROR_INVALID_ARG; - if (!mCanvasElement && !mDocShell) { NS_WARNING("Canvas element must be non-null or a docshell must be provided"); return NS_ERROR_FAILURE; @@ -3932,6 +3925,12 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText, nsAutoString textToDraw(aRawText); TextReplaceWhitespaceCharacters(textToDraw); + // According to spec, the API should return an empty array if maxWidth was provided + // but is less than or equal to zero or equal to NaN. + if (aMaxWidth.WasPassed() && (aMaxWidth.Value() <= 0 || IsNaN(aMaxWidth.Value()))) { + textToDraw.Truncate(); + } + // for now, default to ltr if not in doc bool isRTL = false;