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(-)
This commit is contained in:
vincentliu 2016-07-19 10:52:50 +08:00
Родитель 9c1f8e2f3b
Коммит acbc420513
1 изменённых файлов: 6 добавлений и 7 удалений

Просмотреть файл

@ -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;