Bug 1167423 - patch 4 - Handle return values of FallibleTArray functions in CanvasRenderingContext2D, r=smaug

This commit is contained in:
Andrea Marchesini 2015-05-25 12:50:15 +01:00
parent 4cb28b400a
commit c89a834b25
3 changed files with 24 additions and 10 deletions

View File

@ -2642,7 +2642,8 @@ CanvasRenderingContext2D::Stroke(const CanvasPath& path)
Redraw(); Redraw();
} }
void CanvasRenderingContext2D::DrawFocusIfNeeded(mozilla::dom::Element& aElement) void CanvasRenderingContext2D::DrawFocusIfNeeded(mozilla::dom::Element& aElement,
ErrorResult& aRv)
{ {
EnsureUserSpacePath(); EnsureUserSpacePath();
@ -2674,8 +2675,12 @@ void CanvasRenderingContext2D::DrawFocusIfNeeded(mozilla::dom::Element& aElement
// set dashing for foreground // set dashing for foreground
FallibleTArray<mozilla::gfx::Float>& dash = CurrentState().dash; FallibleTArray<mozilla::gfx::Float>& dash = CurrentState().dash;
dash.AppendElement(1); for (uint32_t i = 0; i < 2; ++i) {
dash.AppendElement(1); if (!dash.AppendElement(1)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
}
// set the foreground focus color // set the foreground focus color
CurrentState().SetColorStyle(Style::STROKE, NS_RGBA(0,0,0, 255)); CurrentState().SetColorStyle(Style::STROKE, NS_RGBA(0,0,0, 255));
@ -3947,7 +3952,8 @@ CanvasRenderingContext2D::SetMozDashOffset(double mozDashOffset)
} }
void void
CanvasRenderingContext2D::SetLineDash(const Sequence<double>& aSegments) CanvasRenderingContext2D::SetLineDash(const Sequence<double>& aSegments,
ErrorResult& aRv)
{ {
FallibleTArray<mozilla::gfx::Float> dash; FallibleTArray<mozilla::gfx::Float> dash;
@ -3957,11 +3963,18 @@ CanvasRenderingContext2D::SetLineDash(const Sequence<double>& aSegments)
// taken care of by WebIDL // taken care of by WebIDL
return; return;
} }
dash.AppendElement(aSegments[x]);
if (!dash.AppendElement(aSegments[x])) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
} }
if (aSegments.Length() % 2) { // If the number of elements is odd, concatenate again if (aSegments.Length() % 2) { // If the number of elements is odd, concatenate again
for (uint32_t x = 0; x < aSegments.Length(); x++) { for (uint32_t x = 0; x < aSegments.Length(); x++) {
dash.AppendElement(aSegments[x]); if (!dash.AppendElement(aSegments[x])) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
} }
} }

View File

@ -187,7 +187,7 @@ public:
void Fill(const CanvasPath& path, const CanvasWindingRule& winding); void Fill(const CanvasPath& path, const CanvasWindingRule& winding);
void Stroke(); void Stroke();
void Stroke(const CanvasPath& path); void Stroke(const CanvasPath& path);
void DrawFocusIfNeeded(mozilla::dom::Element& element); void DrawFocusIfNeeded(mozilla::dom::Element& element, ErrorResult& aRv);
bool DrawCustomFocusRing(mozilla::dom::Element& element); bool DrawCustomFocusRing(mozilla::dom::Element& element);
void Clip(const CanvasWindingRule& winding); void Clip(const CanvasWindingRule& winding);
void Clip(const CanvasPath& path, const CanvasWindingRule& winding); void Clip(const CanvasPath& path, const CanvasWindingRule& winding);
@ -363,7 +363,8 @@ public:
void SetMozDash(JSContext* cx, const JS::Value& mozDash, void SetMozDash(JSContext* cx, const JS::Value& mozDash,
mozilla::ErrorResult& error); mozilla::ErrorResult& error);
void SetLineDash(const Sequence<double>& mSegments); void SetLineDash(const Sequence<double>& mSegments,
mozilla::ErrorResult& aRv);
void GetLineDash(nsTArray<double>& mSegments) const; void GetLineDash(nsTArray<double>& mSegments) const;
void SetLineDashOffset(double mOffset); void SetLineDashOffset(double mOffset);

View File

@ -92,7 +92,7 @@ interface CanvasRenderingContext2D {
void fill(Path2D path, optional CanvasWindingRule winding = "nonzero"); void fill(Path2D path, optional CanvasWindingRule winding = "nonzero");
void stroke(); void stroke();
void stroke(Path2D path); void stroke(Path2D path);
[Pref="canvas.focusring.enabled"] void drawFocusIfNeeded(Element element); [Pref="canvas.focusring.enabled", Throws] void drawFocusIfNeeded(Element element);
// NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element); // NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element);
[Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element); [Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element);
// NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element); // NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element);
@ -246,7 +246,7 @@ interface CanvasDrawingStyles {
attribute double miterLimit; // (default 10) attribute double miterLimit; // (default 10)
// dashed lines // dashed lines
[LenientFloat] void setLineDash(sequence<double> segments); // default empty [LenientFloat, Throws] void setLineDash(sequence<double> segments); // default empty
sequence<double> getLineDash(); sequence<double> getLineDash();
[LenientFloat] attribute double lineDashOffset; [LenientFloat] attribute double lineDashOffset;