Skip to content

Commit

Permalink
Bug 1281800 - The API should return an empty array if maxWidth was pr…
Browse files Browse the repository at this point in the history
…ovided 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(-)
  • Loading branch information
msliu committed Jul 19, 2016
1 parent c3e4d65 commit af9d252
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit af9d252

Please sign in to comment.