Bug 1006656. Ignore setLineDash calls with negative dash values. r=roc

--HG--
extra : rebase_source : 21c356a82618402f1665331348f5be42a640a465
This commit is contained in:
David Caldwell 2014-05-23 12:07:24 +12:00
parent 2fd388829d
commit 09ad4ae5fd
3 changed files with 51 additions and 2 deletions

View File

@ -3127,10 +3127,14 @@ CanvasRenderingContext2D::SetMozDashOffset(double mozDashOffset)
void
CanvasRenderingContext2D::SetLineDash(const Sequence<double>& aSegments)
{
FallibleTArray<mozilla::gfx::Float>& dash = CurrentState().dash;
dash.Clear();
FallibleTArray<mozilla::gfx::Float> dash;
for (uint32_t x = 0; x < aSegments.Length(); x++) {
if (aSegments[x] < 0.0) {
// Pattern elements must be finite "numbers" >= 0, with "finite"
// taken care of by WebIDL
return;
}
dash.AppendElement(aSegments[x]);
}
if (aSegments.Length() % 2) { // If the number of elements is odd, concatenate again
@ -3138,6 +3142,8 @@ CanvasRenderingContext2D::SetLineDash(const Sequence<double>& aSegments)
dash.AppendElement(aSegments[x]);
}
}
CurrentState().dash = dash;
}
void

View File

@ -215,3 +215,4 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk')
[test_windingRuleUndefined.html]
[test_2d.fillText.gradient.html]
[test_createPattern_broken.html]
[test_setlinedash.html]

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>Canvas test: toDataURL parameters (Bug 564388)</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<p>
The line dash setting should not be changed when bad values are passed to setLineDash().
</p>
<p> See:
<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-setlinedash">
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-setlinedash
</a>
</p>
<p>Mozilla
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1006656">Bug 1006656</a>
</p>
<canvas id="canvas"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.setLineDash([1,2,3,4,5,6,7,8,9,10]);
isDeeply(ctx.getLineDash(), [1,2,3,4,5,6,7,8,9,10], "line dash sanity");
ctx.setLineDash([1,2,3,4,5,6,7,8,9,10]);
ctx.setLineDash([Infinity]);
isDeeply(ctx.getLineDash(), [1,2,3,4,5,6,7,8,9,10], "Inf doesn't reset line dash");
ctx.setLineDash([1,2,3,4,5,6,7,8,9,10]);
ctx.setLineDash([NaN]);
isDeeply(ctx.getLineDash(), [1,2,3,4,5,6,7,8,9,10], "NaN doesn't reset line dash");
ctx.setLineDash([1,2,3,4,5,6,7,8,9,10]);
ctx.setLineDash([-1]);
isDeeply(ctx.getLineDash(), [1,2,3,4,5,6,7,8,9,10], "Negative doesn't reset line dash");
</script>
</html>