Bug 1024860 - getTotalLength on an empty path should not throw but return 0 instead. r=jwatt,bzbarsky

This commit is contained in:
Robert Longson 2014-07-03 19:50:42 +01:00
parent e3eefacbb9
commit f8dd9d1270
4 changed files with 15 additions and 15 deletions

View File

@ -68,16 +68,10 @@ SVGPathElement::PathLength()
}
float
SVGPathElement::GetTotalLength(ErrorResult& rv)
SVGPathElement::GetTotalLength()
{
RefPtr<Path> flat = GetPathForLengthOrPositionMeasuring();
if (!flat) {
rv.Throw(NS_ERROR_FAILURE);
return 0.f;
}
return flat->ComputeLength();
return flat ? flat->ComputeLength() : 0.f;
}
already_AddRefed<nsISVGPoint>
@ -353,7 +347,11 @@ SVGPathElement::GetPathLengthScale(PathLengthScaleForType aFor)
float authorsPathLengthEstimate = mPathLength.GetAnimValue();
if (authorsPathLengthEstimate > 0) {
RefPtr<Path> path = GetPathForLengthOrPositionMeasuring();
if (!path) {
// The path is empty or invalid so its length must be zero and
// we know that 0 / authorsPathLengthEstimate = 0.
return 0.0;
}
if (aFor == eForTextPath) {
// For textPath, a transform on the referenced path affects the
// textPath layout, so when calculating the actual path length
@ -365,10 +363,7 @@ SVGPathElement::GetPathLengthScale(PathLengthScaleForType aFor)
path = builder->Finish();
}
}
if (path) {
return path->ComputeLength() / authorsPathLengthEstimate;
}
return path->ComputeLength() / authorsPathLengthEstimate;
}
}
return 1.0;

View File

@ -88,7 +88,7 @@ public:
// WebIDL
already_AddRefed<SVGAnimatedNumber> PathLength();
float GetTotalLength(ErrorResult& rv);
float GetTotalLength();
already_AddRefed<nsISVGPoint> GetPointAtLength(float distance, ErrorResult& rv);
uint32_t GetPathSegAtLength(float distance);
already_AddRefed<DOMSVGPathSegClosePath> CreateSVGPathSegClosePath();

View File

@ -32,6 +32,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1024926
is(path.getTotalLength(), 150, "Unexpected path length");
while (path.pathSegList.numberOfItems > 0) {
path.pathSegList.removeItem(0);
}
is(path.getTotalLength(), 0, "Unexpected path length");
SimpleTest.finish();
</script>

View File

@ -13,7 +13,6 @@ interface SVGPathElement : SVGGraphicsElement {
readonly attribute SVGAnimatedNumber pathLength;
[Throws]
float getTotalLength();
[NewObject, Throws]
SVGPoint getPointAtLength(float distance);