Skip to content

Commit 072f98c

Browse files
committed
Merge remote-tracking branch 'origin/tracking' into custom
2 parents e2f0795 + f1c456c commit 072f98c

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

dom/base/DOMQuad.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "mozilla/dom/DOMQuadBinding.h"
99
#include "mozilla/dom/DOMPoint.h"
1010
#include "mozilla/dom/DOMRect.h"
11-
#include <algorithm>
11+
#include "mozilla/FloatingPoint.h"
1212

1313
using namespace mozilla;
1414
using namespace mozilla::dom;
@@ -106,8 +106,8 @@ DOMQuad::GetHorizontalMinMax(double* aX1, double* aX2) const
106106
x1 = x2 = Point(0)->X();
107107
for (uint32_t i = 1; i < 4; ++i) {
108108
double x = Point(i)->X();
109-
x1 = std::min(x1, x);
110-
x2 = std::max(x2, x);
109+
x1 = NaNSafeMin(x1, x);
110+
x2 = NaNSafeMax(x2, x);
111111
}
112112
*aX1 = x1;
113113
*aX2 = x2;
@@ -120,8 +120,8 @@ DOMQuad::GetVerticalMinMax(double* aY1, double* aY2) const
120120
y1 = y2 = Point(0)->Y();
121121
for (uint32_t i = 1; i < 4; ++i) {
122122
double y = Point(i)->Y();
123-
y1 = std::min(y1, y);
124-
y2 = std::max(y2, y);
123+
y1 = NaNSafeMin(y1, y);
124+
y2 = NaNSafeMax(y2, y);
125125
}
126126
*aY1 = y1;
127127
*aY2 = y2;

dom/base/DOMRect.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "mozilla/Attributes.h"
1717
#include "mozilla/dom/BindingDeclarations.h"
1818
#include "mozilla/ErrorResult.h"
19-
#include <algorithm>
19+
#include "mozilla/FloatingPoint.h"
2020

2121
struct nsRect;
2222

@@ -79,22 +79,22 @@ class DOMRectReadOnly : public nsISupports
7979
double Left() const
8080
{
8181
double x = X(), w = Width();
82-
return std::min(x, x + w);
82+
return NaNSafeMin(x, x + w);
8383
}
8484
double Top() const
8585
{
8686
double y = Y(), h = Height();
87-
return std::min(y, y + h);
87+
return NaNSafeMin(y, y + h);
8888
}
8989
double Right() const
9090
{
9191
double x = X(), w = Width();
92-
return std::max(x, x + w);
92+
return NaNSafeMax(x, x + w);
9393
}
9494
double Bottom() const
9595
{
9696
double y = Y(), h = Height();
97-
return std::max(y, y + h);
97+
return NaNSafeMax(y, y + h);
9898
}
9999

100100
bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;

mfbt/FloatingPoint.h

+25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mozilla/MathAlgorithms.h"
1515
#include "mozilla/Types.h"
1616

17+
#include <algorithm>
1718
#include <stdint.h>
1819

1920
namespace mozilla {
@@ -450,6 +451,30 @@ EqualOrBothNaN(T aValue1, T aValue2)
450451
return aValue1 == aValue2;
451452
}
452453

454+
/**
455+
* Return NaN if either |aValue1| or |aValue2| is NaN, or the minimum of
456+
* |aValue1| and |aValue2| otherwise.
457+
*/
458+
template <typename T>
459+
static inline T NaNSafeMin(T aValue1, T aValue2) {
460+
if (IsNaN(aValue1) || IsNaN(aValue2)) {
461+
return UnspecifiedNaN<T>();
462+
}
463+
return std::min(aValue1, aValue2);
464+
}
465+
466+
/**
467+
* Return NaN if either |aValue1| or |aValue2| is NaN, or the maximum of
468+
* |aValue1| and |aValue2| otherwise.
469+
*/
470+
template <typename T>
471+
static inline T NaNSafeMax(T aValue1, T aValue2) {
472+
if (IsNaN(aValue1) || IsNaN(aValue2)) {
473+
return UnspecifiedNaN<T>();
474+
}
475+
return std::max(aValue1, aValue2);
476+
}
477+
453478
namespace detail {
454479

455480
template<typename T>

0 commit comments

Comments
 (0)