diff --git a/CHANGELOG.md b/CHANGELOG.md index 29a7d2136..6558bf06f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/). * Changed `DOMPoint()` constructor to check for parameter nullability. * Changed `DOMMatrix.js` to use string literals for non-special cases. * Remove semicolons from Dommatrix.js. +* Clean up inf/nan macros and slightly speed up argument checking. ### Added * Added `deregisterAllFonts` method to free up memory and reduce font conflicts. ### Fixed diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 0bb867c73..f3415a7ed 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -21,17 +21,6 @@ using namespace v8; -// Windows doesn't support the C99 names for these -#ifdef _MSC_VER -#define isnan(x) _isnan(x) -#define isinf(x) (!_finite(x)) -#endif - -#ifndef isnan -#define isnan(x) std::isnan(x) -#define isinf(x) std::isinf(x) -#endif - Nan::Persistent Context2d::constructor; /* @@ -77,9 +66,7 @@ inline static bool checkArgs(const Nan::FunctionCallbackInfo &info, doubl double val = Nan::To(info[i]).FromMaybe(0); if (areArgsValid) { - if (val != val || - val == std::numeric_limits::infinity() || - val == -std::numeric_limits::infinity()) { + if (!std::isfinite(val)) { // We should continue the loop instead of returning immediately // See https://html.spec.whatwg.org/multipage/canvas.html @@ -2787,7 +2774,7 @@ NAN_METHOD(Context2d::SetLineDash) { if (!d->IsNumber()) return; a[i] = Nan::To(d).FromMaybe(0); if (a[i] == 0) zero_dashes++; - if (a[i] < 0 || isnan(a[i]) || isinf(a[i])) return; + if (a[i] < 0 || !std::isfinite(a[i])) return; } Context2d *context = Nan::ObjectWrap::Unwrap(info.This()); @@ -2827,7 +2814,7 @@ NAN_METHOD(Context2d::GetLineDash) { */ NAN_SETTER(Context2d::SetLineDashOffset) { double offset = Nan::To(value).FromMaybe(0); - if (isnan(offset) || isinf(offset)) return; + if (!std::isfinite(offset)) return; Context2d *context = Nan::ObjectWrap::Unwrap(info.This()); cairo_t *ctx = context->context();