| Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
|
| diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
|
| index d3fb0e25fd12d224c0cfb32603fb0776ed59ae46..f569c0bcaf098cb69a9e7fb125ef4afffdaae5af 100644
|
| --- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
|
| +++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
|
| @@ -31,6 +31,23 @@
|
|
|
| namespace blink {
|
|
|
| +namespace {
|
| +
|
| +bool IsFiniteFloat(float x) {
|
| + return std::isfinite(x);
|
| +}
|
| +
|
| +bool IsFiniteFloat(double x) {
|
| + if (!std::isfinite(x))
|
| + return false;
|
| + constexpr double max_float_as_double =
|
| + static_cast<double>(std::numeric_limits<float>::max());
|
| + if (x > max_float_as_double)
|
| + return false;
|
| + return true;
|
| +}
|
| +}
|
| +
|
| BaseRenderingContext2D::BaseRenderingContext2D()
|
| : m_clipAntialiasing(NotAntiAliased) {
|
| m_stateStack.append(CanvasRenderingContext2DState::create());
|
| @@ -240,7 +257,7 @@ double BaseRenderingContext2D::lineWidth() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setLineWidth(double width) {
|
| - if (!std::isfinite(width) || width <= 0)
|
| + if (!IsFiniteFloat(width) || width <= 0)
|
| return;
|
| if (state().lineWidth() == width)
|
| return;
|
| @@ -278,7 +295,7 @@ double BaseRenderingContext2D::miterLimit() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setMiterLimit(double limit) {
|
| - if (!std::isfinite(limit) || limit <= 0)
|
| + if (!IsFiniteFloat(limit) || limit <= 0)
|
| return;
|
| if (state().miterLimit() == limit)
|
| return;
|
| @@ -290,7 +307,7 @@ double BaseRenderingContext2D::shadowOffsetX() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setShadowOffsetX(double x) {
|
| - if (!std::isfinite(x))
|
| + if (!IsFiniteFloat(x))
|
| return;
|
| if (state().shadowOffset().width() == x)
|
| return;
|
| @@ -302,7 +319,7 @@ double BaseRenderingContext2D::shadowOffsetY() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setShadowOffsetY(double y) {
|
| - if (!std::isfinite(y))
|
| + if (!IsFiniteFloat(y))
|
| return;
|
| if (state().shadowOffset().height() == y)
|
| return;
|
| @@ -314,7 +331,7 @@ double BaseRenderingContext2D::shadowBlur() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setShadowBlur(double blur) {
|
| - if (!std::isfinite(blur) || blur < 0)
|
| + if (!IsFiniteFloat(blur) || blur < 0)
|
| return;
|
| if (state().shadowBlur() == blur)
|
| return;
|
| @@ -340,7 +357,7 @@ const Vector<double>& BaseRenderingContext2D::getLineDash() const {
|
|
|
| static bool lineDashSequenceIsValid(const Vector<double>& dash) {
|
| for (size_t i = 0; i < dash.size(); i++) {
|
| - if (!std::isfinite(dash[i]) || dash[i] < 0)
|
| + if (!IsFiniteFloat(dash[i]) || dash[i] < 0)
|
| return false;
|
| }
|
| return true;
|
| @@ -357,7 +374,7 @@ double BaseRenderingContext2D::lineDashOffset() const {
|
| }
|
|
|
| void BaseRenderingContext2D::setLineDashOffset(double offset) {
|
| - if (!std::isfinite(offset) || state().lineDashOffset() == offset)
|
| + if (!IsFiniteFloat(offset) || state().lineDashOffset() == offset)
|
| return;
|
| modifiableState().setLineDashOffset(offset);
|
| }
|
| @@ -429,7 +446,7 @@ void BaseRenderingContext2D::scale(double sx, double sy) {
|
| if (!c)
|
| return;
|
|
|
| - if (!std::isfinite(sx) || !std::isfinite(sy))
|
| + if (!IsFiniteFloat(sx) || !IsFiniteFloat(sy))
|
| return;
|
|
|
| AffineTransform newTransform = state().transform();
|
| @@ -450,7 +467,7 @@ void BaseRenderingContext2D::rotate(double angleInRadians) {
|
| if (!c)
|
| return;
|
|
|
| - if (!std::isfinite(angleInRadians))
|
| + if (!IsFiniteFloat(angleInRadians))
|
| return;
|
|
|
| AffineTransform newTransform = state().transform();
|
| @@ -472,7 +489,7 @@ void BaseRenderingContext2D::translate(double tx, double ty) {
|
| if (!state().isTransformInvertible())
|
| return;
|
|
|
| - if (!std::isfinite(tx) || !std::isfinite(ty))
|
| + if (!IsFiniteFloat(tx) || !IsFiniteFloat(ty))
|
| return;
|
|
|
| AffineTransform newTransform = state().transform();
|
| @@ -497,8 +514,8 @@ void BaseRenderingContext2D::transform(double m11,
|
| if (!c)
|
| return;
|
|
|
| - if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) ||
|
| - !std::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy))
|
| + if (!IsFiniteFloat(m11) || !IsFiniteFloat(m21) || !IsFiniteFloat(dx) ||
|
| + !IsFiniteFloat(m12) || !IsFiniteFloat(m22) || !IsFiniteFloat(dy))
|
| return;
|
|
|
| AffineTransform transform(m11, m12, m21, m22, dx, dy);
|
| @@ -548,8 +565,8 @@ void BaseRenderingContext2D::setTransform(double m11,
|
| if (!c)
|
| return;
|
|
|
| - if (!std::isfinite(m11) || !std::isfinite(m21) || !std::isfinite(dx) ||
|
| - !std::isfinite(m12) || !std::isfinite(m22) || !std::isfinite(dy))
|
| + if (!IsFiniteFloat(m11) || !IsFiniteFloat(m21) || !IsFiniteFloat(dx) ||
|
| + !IsFiniteFloat(m12) || !IsFiniteFloat(m22) || !IsFiniteFloat(dy))
|
| return;
|
|
|
| resetTransform();
|
| @@ -564,8 +581,8 @@ static bool validateRectForCanvas(double& x,
|
| double& y,
|
| double& width,
|
| double& height) {
|
| - if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) ||
|
| - !std::isfinite(height))
|
| + if (!IsFiniteFloat(x) || !IsFiniteFloat(y) || !IsFiniteFloat(width) ||
|
| + !IsFiniteFloat(height))
|
| return false;
|
|
|
| if (!width && !height)
|
| @@ -780,7 +797,7 @@ bool BaseRenderingContext2D::isPointInPathInternal(
|
| return false;
|
|
|
| FloatPoint point(x, y);
|
| - if (!std::isfinite(point.x()) || !std::isfinite(point.y()))
|
| + if (!IsFiniteFloat(point.x()) || !IsFiniteFloat(point.y()))
|
| return false;
|
| AffineTransform ctm = state().transform();
|
| FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
|
| @@ -809,7 +826,7 @@ bool BaseRenderingContext2D::isPointInStrokeInternal(const Path& path,
|
| return false;
|
|
|
| FloatPoint point(x, y);
|
| - if (!std::isfinite(point.x()) || !std::isfinite(point.y()))
|
| + if (!IsFiniteFloat(point.x()) || !IsFiniteFloat(point.y()))
|
| return false;
|
| AffineTransform ctm = state().transform();
|
| FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
|
| @@ -1150,9 +1167,9 @@ void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext,
|
| return;
|
| }
|
|
|
| - if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) ||
|
| - !std::isfinite(dh) || !std::isfinite(sx) || !std::isfinite(sy) ||
|
| - !std::isfinite(sw) || !std::isfinite(sh) || !dw || !dh || !sw || !sh)
|
| + if (!IsFiniteFloat(dx) || !IsFiniteFloat(dy) || !IsFiniteFloat(dw) ||
|
| + !IsFiniteFloat(dh) || !IsFiniteFloat(sx) || !IsFiniteFloat(sy) ||
|
| + !IsFiniteFloat(sw) || !IsFiniteFloat(sh) || !dw || !dh || !sw || !sh)
|
| return;
|
|
|
| FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh));
|
|
|