Skip to content

Commit

Permalink
Bug 1660405 - Move away from mozilla::IsFinite in favor of std::isfin…
Browse files Browse the repository at this point in the history
…ite. r=sergesanspaille

Differential Revision: https://phabricator.services.mozilla.com/D173036
  • Loading branch information
abpostelnicu committed Mar 22, 2023
1 parent cc4638d commit 426691b
Show file tree
Hide file tree
Showing 56 changed files with 138 additions and 143 deletions.
6 changes: 3 additions & 3 deletions dom/animation/AnimationEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ ComputedTiming AnimationEffect::GetComputedTimingAt(
}

// Factor in iteration start offset.
if (IsFinite(overallProgress)) {
if (std::isfinite(overallProgress)) {
overallProgress += result.mIterationStart;
}

Expand All @@ -200,7 +200,7 @@ ComputedTiming AnimationEffect::GetComputedTimingAt(
// Convert the overall progress to a fraction of a single iteration--the
// simply iteration progress.
// https://drafts.csswg.org/web-animations/#simple-iteration-progress
double progress = IsFinite(overallProgress)
double progress = std::isfinite(overallProgress)
? fmod(overallProgress, 1.0)
: fmod(result.mIterationStart, 1.0);

Expand Down Expand Up @@ -260,7 +260,7 @@ ComputedTiming AnimationEffect::GetComputedTimingAt(
progress = fn->At(progress, result.mBeforeFlag);
}

MOZ_ASSERT(IsFinite(progress), "Progress value should be finite");
MOZ_ASSERT(std::isfinite(progress), "Progress value should be finite");
result.mProgress.SetValue(progress);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/DOMMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void DOMMatrixReadOnly::Stringify(nsAString& aResult, ErrorResult& aRv) {
nsAutoString matrixStr;
auto AppendDouble = [&aRv, &cbuf, &matrixStr](double d,
bool isLastItem = false) {
if (!mozilla::IsFinite(d)) {
if (!std::isfinite(d)) {
aRv.ThrowInvalidStateError(
"Matrix with a non-finite element cannot be stringified.");
return false;
Expand Down
26 changes: 13 additions & 13 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3608,28 +3608,28 @@ class TreeOrderComparator {
* series is not finite.
*/
#define NS_ENSURE_FINITE(f, rv) \
if (!mozilla::IsFinite(f)) { \
if (!std::isfinite(f)) { \
return (rv); \
}

#define NS_ENSURE_FINITE2(f1, f2, rv) \
if (!mozilla::IsFinite((f1) + (f2))) { \
return (rv); \
#define NS_ENSURE_FINITE2(f1, f2, rv) \
if (!std::isfinite((f1) + (f2))) { \
return (rv); \
}

#define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4))) { \
return (rv); \
#define NS_ENSURE_FINITE4(f1, f2, f3, f4, rv) \
if (!std::isfinite((f1) + (f2) + (f3) + (f4))) { \
return (rv); \
}

#define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4) + (f5))) { \
return (rv); \
#define NS_ENSURE_FINITE5(f1, f2, f3, f4, f5, rv) \
if (!std::isfinite((f1) + (f2) + (f3) + (f4) + (f5))) { \
return (rv); \
}

#define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \
if (!mozilla::IsFinite((f1) + (f2) + (f3) + (f4) + (f5) + (f6))) { \
return (rv); \
#define NS_ENSURE_FINITE6(f1, f2, f3, f4, f5, f6, rv) \
if (!std::isfinite((f1) + (f2) + (f3) + (f4) + (f5) + (f6))) { \
return (rv); \
}

// Deletes a linked list iteratively to avoid blowing up the stack (bug 460444).
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/Codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7354,7 +7354,7 @@ def getConversionCode(varName):
template = template.rstrip()
template += fill(
"""
else if (!mozilla::IsFinite(${readLoc})) {
else if (!std::isfinite(${readLoc})) {
$*{nonFiniteCode}
}
""",
Expand Down
4 changes: 2 additions & 2 deletions dom/bindings/PrimitiveConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ inline bool PrimitiveConversionTraits_EnforceRange(
static_assert(std::numeric_limits<T>::is_integer,
"This can only be applied to integers!");

if (!mozilla::IsFinite(d)) {
if (!std::isfinite(d)) {
return cx.ThrowErrorMessage<MSG_ENFORCE_RANGE_NON_FINITE>(
sourceDescription, TypeName<T>::value());
}
Expand Down Expand Up @@ -242,7 +242,7 @@ inline bool PrimitiveConversionTraits_Clamp(JSContext* cx,
return true;
}

MOZ_ASSERT(mozilla::IsFinite(d));
MOZ_ASSERT(std::isfinite(d));

// Banker's rounding (round ties towards even).
// We move away from 0 by 0.5f and then truncate. That gets us the right
Expand Down
9 changes: 5 additions & 4 deletions dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3208,7 +3208,8 @@ static void RoundRectImpl(
aRadii,
ErrorResult& aError) {
// Step 1. If any of x, y, w, or h are infinite or NaN, then return.
if (!IsFinite(aX) || !IsFinite(aY) || !IsFinite(aW) || !IsFinite(aH)) {
if (!std::isfinite(aX) || !std::isfinite(aY) || !std::isfinite(aW) ||
!std::isfinite(aH)) {
return;
}

Expand Down Expand Up @@ -3240,7 +3241,7 @@ static void RoundRectImpl(
const DOMPointInit& point = radius.GetAsDOMPointInit();
// Step 5.1.1. If radius["x"] or radius["y"] is infinite or NaN, then
// return.
if (!IsFinite(point.mX) || !IsFinite(point.mY)) {
if (!std::isfinite(point.mX) || !std::isfinite(point.mY)) {
return;
}

Expand All @@ -3261,7 +3262,7 @@ static void RoundRectImpl(
// Step 5.2. If radius is a unrestricted double:
double r = radius.GetAsUnrestrictedDouble();
// Step 5.2.1. If radius is infinite or NaN, then return.
if (!IsFinite(r)) {
if (!std::isfinite(r)) {
return;
}

Expand Down Expand Up @@ -4257,7 +4258,7 @@ TextMetrics* CanvasRenderingContext2D::DrawOrMeasureText(
return nullptr;
}

if (!IsFinite(aX) || !IsFinite(aY)) {
if (!std::isfinite(aX) || !std::isfinite(aY)) {
aError = NS_OK;
// This may not be correct - what should TextMetrics contain in the case of
// infinite width or height?
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/CanvasUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool CoerceDouble(const JS::Value& v, double* d);

/* Float validation stuff */
#define VALIDATE(_f) \
if (!IsFinite(_f)) return false
if (!std::isfinite(_f)) return false

inline bool FloatValidate(double f1) {
VALIDATE(f1);
Expand Down
4 changes: 2 additions & 2 deletions dom/canvas/DrawTargetWebgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2709,8 +2709,8 @@ static Maybe<AAStroke::VertexBuffer> GenerateStrokeVertexBuffer(
ToAAStrokeLineCap(aStrokeOptions->mLineCap),
ToAAStrokeLineJoin(aStrokeOptions->mLineJoin),
aStrokeOptions->mMiterLimit};
if (style.width <= 0.0f || !IsFinite(style.width) ||
style.miter_limit <= 0.0f || !IsFinite(style.miter_limit)) {
if (style.width <= 0.0f || !std::isfinite(style.width) ||
style.miter_limit <= 0.0f || !std::isfinite(style.miter_limit)) {
return Nothing();
}
AAStroke::Stroker* s = AAStroke::aa_stroke_new(
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ void HTMLInputElement::SetValueAsNumber(double aValueAsNumber,
ErrorResult& aRv) {
// TODO: return TypeError when HTMLInputElement is converted to WebIDL, see
// bug 825197.
if (IsInfinite(aValueAsNumber)) {
if (std::isinf(aValueAsNumber)) {
aRv.Throw(NS_ERROR_INVALID_ARG);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ChannelMediaDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ ChannelMediaDecoder::ComputePlaybackRate(const MediaChannelStatistics& aStats,
MOZ_ASSERT(!NS_IsMainThread());

int64_t length = aResource->GetLength();
if (mozilla::IsFinite<double>(aDuration) && aDuration > 0 && length >= 0 &&
if (std::isfinite(aDuration) && aDuration > 0 && length >= 0 &&
length / aDuration < UINT32_MAX) {
return {uint32_t(length / aDuration), true};
}
Expand Down
3 changes: 2 additions & 1 deletion dom/media/MediaDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "nsTArray.h"
#include "WindowRenderer.h"
#include <algorithm>
#include <cmath>
#include <limits>

using namespace mozilla::dom;
Expand Down Expand Up @@ -246,7 +247,7 @@ double MediaDecoder::GetDuration() {

bool MediaDecoder::IsInfinite() const {
MOZ_ASSERT(NS_IsMainThread());
return mozilla::IsInfinite<double>(mDuration);
return std::isinf(mDuration);
}

#define INIT_MIRROR(name, val) \
Expand Down
2 changes: 1 addition & 1 deletion dom/media/MediaMIMETypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(
rv = parser.GetParameter("codecs", codecs);
bool haveCodecs = NS_SUCCEEDED(rv);

if (!IsFinite(aConfig.mFramerate) || aConfig.mFramerate <= 0.0) {
if (!std::isfinite(aConfig.mFramerate) || aConfig.mFramerate <= 0.0) {
return Nothing();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/media/webaudio/AudioEventTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class AudioEventTimeline {

const AudioTimelineEvent* GetPreviousEvent(double aTime) const;

static bool IsValid(double value) { return mozilla::IsFinite(value); }
static bool IsValid(double value) { return std::isfinite(value); }

// This is a sorted array of the events in the timeline. Queries of this
// data structure should probably be more frequent than modifications to it,
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webaudio/PannerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void PannerNode::SetPanningModel(PanningModelType aPanningModel) {
static bool SetParamFromDouble(AudioParam* aParam, double aValue,
const char (&aParamName)[2], ErrorResult& aRv) {
float value = static_cast<float>(aValue);
if (!mozilla::IsFinite(value)) {
if (!std::isfinite(value)) {
aRv.ThrowTypeError<MSG_NOT_FINITE>(aParamName);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webaudio/blink/Reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static float calculateNormalizationScale(const nsTArray<const float*>& response,
power = sqrt(power / (numberOfChannels * aLength));

// Protect against accidental overload
if (!IsFinite(power) || std::isnan(power) || power < MinPower)
if (!std::isfinite(power) || std::isnan(power) || power < MinPower)
power = MinPower;

float scale = 1 / power;
Expand Down
6 changes: 3 additions & 3 deletions dom/svg/DOMSVGLength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ float DOMSVGLength::GetValue(ErrorResult& aRv) {
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
float value = InternalItem().GetValueInUserUnits(lengthList->Element(),
lengthList->Axis());
if (!IsFinite(value)) {
if (!std::isfinite(value)) {
aRv.Throw(NS_ERROR_FAILURE);
}
return value;
Expand Down Expand Up @@ -196,7 +196,7 @@ void DOMSVGLength::SetValue(float aUserUnitValue, ErrorResult& aRv) {
lengthList->Axis());
if (uuPerUnit > 0) {
float newValue = aUserUnitValue / uuPerUnit;
if (IsFinite(newValue)) {
if (std::isfinite(newValue)) {
AutoChangeLengthListNotifier notifier(this);
internalItem.SetValueAndUnit(newValue, internalItem.GetUnit());
return;
Expand Down Expand Up @@ -357,7 +357,7 @@ void DOMSVGLength::ConvertToSpecifiedUnits(uint16_t aUnit, ErrorResult& aRv) {
} else {
val = SVGLength(mValue, mUnit).GetValueInSpecifiedUnit(aUnit, nullptr, 0);
}
if (IsFinite(val)) {
if (std::isfinite(val)) {
if (HasOwner()) {
AutoChangeLengthListNotifier notifier(this);
InternalItem().SetValueAndUnit(val, aUnit);
Expand Down
4 changes: 2 additions & 2 deletions dom/svg/DOMSVGTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void DOMSVGTransform::SetSkewX(float angle, ErrorResult& rv) {
return;
}

if (!IsFinite(tan(angle * kRadPerDegree))) {
if (!std::isfinite(tan(angle * kRadPerDegree))) {
rv.ThrowRangeError<MSG_INVALID_TRANSFORM_ANGLE_ERROR>();
return;
}
Expand All @@ -235,7 +235,7 @@ void DOMSVGTransform::SetSkewY(float angle, ErrorResult& rv) {
return;
}

if (!IsFinite(tan(angle * kRadPerDegree))) {
if (!std::isfinite(tan(angle * kRadPerDegree))) {
rv.ThrowRangeError<MSG_INVALID_TRANSFORM_ANGLE_ERROR>();
return;
}
Expand Down
6 changes: 3 additions & 3 deletions dom/svg/SVGAnimatedLength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ nsresult SVGAnimatedLength::ConvertToSpecifiedUnits(uint16_t unitType,
mBaseVal * GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);
float valueInSpecifiedUnits = valueInUserUnits / pixelsPerUnit;

if (!IsFinite(valueInSpecifiedUnits)) {
if (!std::isfinite(valueInSpecifiedUnits)) {
return NS_ERROR_ILLEGAL_VALUE;
}

Expand Down Expand Up @@ -416,7 +416,7 @@ nsresult SVGAnimatedLength::SetBaseValue(float aValue, SVGElement* aSVGElement,
}

float valueInSpecifiedUnits = aValue / pixelsPerUnit;
if (!IsFinite(valueInSpecifiedUnits)) {
if (!std::isfinite(valueInSpecifiedUnits)) {
return NS_ERROR_ILLEGAL_VALUE;
}

Expand All @@ -439,7 +439,7 @@ nsresult SVGAnimatedLength::SetAnimValue(float aValue,
float valueInSpecifiedUnits =
aValue / GetPixelsPerUnit(aSVGElement, mSpecifiedUnitType);

if (IsFinite(valueInSpecifiedUnits)) {
if (std::isfinite(valueInSpecifiedUnits)) {
SetAnimValueInSpecifiedUnits(valueInSpecifiedUnits, aSVGElement);
return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGAnimatedNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SVGAnimatedNumber {

float BaseVal() override { return mVal->GetBaseValue(); }
void SetBaseVal(float aValue) override {
MOZ_ASSERT(IsFinite(aValue));
MOZ_ASSERT(std::isfinite(aValue));
mVal->SetBaseValue(aValue, mSVGElement);
}

Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGAnimatedNumberPair.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SVGAnimatedNumberPair {

float BaseVal() override { return mVal->GetBaseValue(mIndex); }
void SetBaseVal(float aValue) override {
MOZ_ASSERT(IsFinite(aValue));
MOZ_ASSERT(std::isfinite(aValue));
mVal->SetBaseValue(aValue, mIndex, mSVGElement);
}

Expand Down
4 changes: 2 additions & 2 deletions dom/svg/SVGContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static DashState GetStrokeDashData(
if (auto* shapeElement = SVGGeometryElement::FromNode(aElement)) {
pathScale =
shapeElement->GetPathLengthScale(SVGGeometryElement::eForStroking);
if (pathScale <= 0 || !IsFinite(pathScale)) {
if (pathScale <= 0 || !std::isfinite(pathScale)) {
return eContinuousStroke;
}
}
Expand Down Expand Up @@ -720,7 +720,7 @@ bool SVGContentUtils::ParseNumber(RangedPtr<const char16_t>& aIter,
return false;
}
floatType floatValue = floatType(value);
if (!IsFinite(floatValue)) {
if (!std::isfinite(floatValue)) {
return false;
}
aValue = floatValue;
Expand Down
6 changes: 3 additions & 3 deletions dom/svg/SVGLength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ float SVGLength::GetValueInSpecifiedUnit(uint8_t aUnit,
SVGLength(0.0f, aUnit).GetUserUnitsPerUnit(aElement, aAxis);

NS_ASSERTION(
userUnitsPerCurrentUnit >= 0 || !IsFinite(userUnitsPerCurrentUnit),
userUnitsPerCurrentUnit >= 0 || !std::isfinite(userUnitsPerCurrentUnit),
"bad userUnitsPerCurrentUnit");
NS_ASSERTION(userUnitsPerNewUnit >= 0 || !IsFinite(userUnitsPerNewUnit),
NS_ASSERTION(userUnitsPerNewUnit >= 0 || !std::isfinite(userUnitsPerNewUnit),
"bad userUnitsPerNewUnit");

float value = mValue * userUnitsPerCurrentUnit / userUnitsPerNewUnit;

// userUnitsPerCurrentUnit could be infinity, or userUnitsPerNewUnit could
// be zero.
if (IsFinite(value)) {
if (std::isfinite(value)) {
return value;
}
return std::numeric_limits<float>::quiet_NaN();
Expand Down
4 changes: 3 additions & 1 deletion dom/svg/SVGLength.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class SVGLength {

private:
#ifdef DEBUG
bool IsValid() const { return IsFinite(mValue) && IsValidUnitType(mUnit); }
bool IsValid() const {
return std::isfinite(mValue) && IsValidUnitType(mUnit);
}
#endif

/**
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGLengthListSMILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ nsresult SVGLengthListSMILType::ComputeDistance(const SMILValue& aFrom,
}

float distance = sqrt(total);
if (!IsFinite(distance)) {
if (!std::isfinite(distance)) {
return NS_ERROR_FAILURE;
}
aDistance = distance;
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGMarkerElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void SVGMarkerElement::SetOrientToAuto() {

void SVGMarkerElement::SetOrientToAngle(DOMSVGAngle& angle, ErrorResult& rv) {
float f = angle.Value();
if (!IsFinite(f)) {
if (!std::isfinite(f)) {
rv.ThrowTypeError("Unknown or invalid type");
return;
}
Expand Down
Loading

0 comments on commit 426691b

Please sign in to comment.