Bug 859892 - Rename JS_CANONICALIZE_NAN to JS::CanonicalizeNaN. r=Waldo
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 17 Oct 2013 10:16:17 +0200
changeset 165878 f3f9a19a57b95c54f37aa675cf571c1d838f77b0
parent 165877 8fd2088036f2f170e2a9df8e02fd1e8871b90de5
child 165879 440098bca4eb491e263f9236a131538191c720ba
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs859892
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 859892 - Rename JS_CANONICALIZE_NAN to JS::CanonicalizeNaN. r=Waldo
js/public/Value.h
js/src/jsapi.h
js/src/vm/StructuredClone.cpp
js/src/vm/TypedArrayObject.cpp
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -838,27 +838,16 @@ JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(jsval
 {
    uint64_t type = (l.asBits >> JSVAL_TAG_SHIFT) & 0xF;
    MOZ_ASSERT(type > JSVAL_TYPE_DOUBLE);
    return (JSValueType)type;
 }
 
 #endif  /* JS_BITS_PER_WORD */
 
-static inline double
-JS_CANONICALIZE_NAN(double d)
-{
-    if (MOZ_UNLIKELY(d != d)) {
-        jsval_layout l;
-        l.asBits = 0x7FF8000000000000LL;
-        return l.asDouble;
-    }
-    return d;
-}
-
 static inline jsval_layout JSVAL_TO_IMPL(JS::Value v);
 static inline JS_VALUE_CONSTEXPR JS::Value IMPL_TO_JSVAL(jsval_layout l);
 
 namespace JS {
 
 static inline JS_VALUE_CONSTEXPR JS::Value UndefinedValue();
 
 /**
@@ -868,16 +857,24 @@ static inline JS_VALUE_CONSTEXPR JS::Val
  * bit pattern restrictions.
  */
 static MOZ_ALWAYS_INLINE double
 GenericNaN()
 {
   return mozilla::SpecificNaN(0, 0x8000000000000ULL);
 }
 
+static inline double
+CanonicalizeNaN(double d)
+{
+    if (MOZ_UNLIKELY(mozilla::IsNaN(d)))
+        return GenericNaN();
+    return d;
+}
+
 /*
  * JS::Value is the interface for a single JavaScript Engine value.  A few
  * general notes on JS::Value:
  *
  * - JS::Value has setX() and isX() members for X in
  *
  *     { Int32, Double, String, Boolean, Undefined, Null, Object, Magic }
  *
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -842,17 +842,17 @@ typedef void
                               char *buf, size_t bufsize);
 
 /************************************************************************/
 
 static JS_ALWAYS_INLINE jsval
 JS_NumberValue(double d)
 {
     int32_t i;
-    d = JS_CANONICALIZE_NAN(d);
+    d = JS::CanonicalizeNaN(d);
     if (mozilla::DoubleIsInt32(d, &i))
         return INT_TO_JSVAL(i);
     return DOUBLE_TO_JSVAL(d);
 }
 
 /************************************************************************/
 
 JS_PUBLIC_API(bool)
--- a/js/src/vm/StructuredClone.cpp
+++ b/js/src/vm/StructuredClone.cpp
@@ -43,16 +43,17 @@
 #include "jscntxtinlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 
 using mozilla::IsNaN;
 using mozilla::LittleEndian;
 using mozilla::NativeEndian;
+using JS::CanonicalizeNaN;
 
 enum StructuredDataType {
     /* Structured data types provided by the engine */
     SCTAG_FLOAT_MAX = 0xFFF00000,
     SCTAG_NULL = 0xFFFF0000,
     SCTAG_UNDEFINED,
     SCTAG_BOOLEAN,
     SCTAG_INDEX,
@@ -419,36 +420,26 @@ SCInput::replace(uint64_t u)
 }
 
 bool
 SCInput::replacePair(uint32_t tag, uint32_t data)
 {
     return replace(PairToUInt64(tag, data));
 }
 
-/*
- * The purpose of this never-inlined function is to avoid a strange g++ build
- * error on OS X 10.5 (see bug 624080).  :-(
- */
-static JS_NEVER_INLINE double
-CanonicalizeNan(double d)
-{
-    return JS_CANONICALIZE_NAN(d);
-}
-
 bool
 SCInput::readDouble(double *p)
 {
     union {
         uint64_t u;
         double d;
     } pun;
     if (!read(&pun.u))
         return false;
-    *p = CanonicalizeNan(pun.d);
+    *p = CanonicalizeNaN(pun.d);
     return true;
 }
 
 template <typename T>
 static void
 copyAndSwapFromLittleEndian(T *dest, const void *src, size_t nelems)
 {
     NativeEndian::copyAndSwapFromLittleEndian(dest, src, nelems);
@@ -553,17 +544,17 @@ static inline double
 ReinterpretPairAsDouble(uint32_t tag, uint32_t data)
 {
     return ReinterpretUInt64AsDouble(PairToUInt64(tag, data));
 }
 
 bool
 SCOutput::writeDouble(double d)
 {
-    return write(ReinterpretDoubleAsUInt64(CanonicalizeNan(d)));
+    return write(ReinterpretDoubleAsUInt64(CanonicalizeNaN(d)));
 }
 
 template <typename T>
 static void
 copyAndSwapToLittleEndian(void *dest, const T *src, size_t nelems)
 {
     NativeEndian::copyAndSwapToLittleEndian(dest, src, nelems);
 }
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -48,16 +48,17 @@
 #endif
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
 using mozilla::IsNaN;
 using mozilla::PodCopy;
+using JS::CanonicalizeNaN;
 using JS::GenericNaN;
 
 /*
  * Allocate array buffers with the maximum number of fixed slots marked as
  * reserved, so that the fixed slots may be used for the buffer's contents.
  * The last fixed slot is kept for the object's private data.
  */
 static const uint8_t ARRAYBUFFER_RESERVED_SLOTS = JSObject::MAX_FIXED_SLOTS - 1;
@@ -1258,17 +1259,17 @@ js::ToDoubleForTypedArray(JSContext *cx,
         *d = GenericNaN();
     }
 
 #ifdef JS_MORE_DETERMINISTIC
     // It's possible to have a NaN value with the sign bit set. The spec allows
     // this but it can confuse differential testing when this value is stored
     // to a float array and then read back as integer. To work around this, we
     // always canonicalize NaN values in more-deterministic builds.
-    *d = JS_CANONICALIZE_NAN(*d);
+    *d = CanonicalizeNaN(*d);
 #endif
 
     return true;
 }
 
 /*
  * This method is used to trace TypedArrayObjects and DataViewObjects. We need
  * a custom tracer because some of an ArrayBufferViewObject's reserved slots
@@ -2628,34 +2629,34 @@ TypedArrayObjectTemplate<float>::copyInd
      * could allow user code to break the engine-wide invariant that only
      * canonical nans are stored into jsvals, which means user code could
      * confuse the engine into interpreting a double-typed jsval as an
      * object-typed jsval.
      *
      * This could be removed for platforms/compilers known to convert a 32-bit
      * non-canonical nan to a 64-bit canonical nan.
      */
-    vp.setDouble(JS_CANONICALIZE_NAN(dval));
+    vp.setDouble(CanonicalizeNaN(dval));
 }
 
 template<>
 void
 TypedArrayObjectTemplate<double>::copyIndexToValue(JSObject *tarray, uint32_t index,
                                                    MutableHandleValue vp)
 {
     double val = getIndex(tarray, index);
 
     /*
      * Doubles in typed arrays could be typed-punned arrays of integers. This
      * could allow user code to break the engine-wide invariant that only
      * canonical nans are stored into jsvals, which means user code could
      * confuse the engine into interpreting a double-typed jsval as an
      * object-typed jsval.
      */
-    vp.setDouble(JS_CANONICALIZE_NAN(val));
+    vp.setDouble(CanonicalizeNaN(val));
 }
 
 } /* anonymous namespace */
 
 static NewObjectKind
 DataViewNewObjectKind(JSContext *cx, uint32_t byteLength, JSObject *proto)
 {
     if (!proto && byteLength >= TypedArrayObject::SINGLETON_TYPE_BYTE_LENGTH)
@@ -3106,17 +3107,17 @@ DataViewObject::getFloat32Impl(JSContext
     JS_ASSERT(is(args.thisv()));
 
     Rooted<DataViewObject*> thisView(cx, &args.thisv().toObject().as<DataViewObject>());
 
     float val;
     if (!read(cx, thisView, args, &val, "getFloat32"))
         return false;
 
-    args.rval().setDouble(JS_CANONICALIZE_NAN(val));
+    args.rval().setDouble(CanonicalizeNaN(val));
     return true;
 }
 
 bool
 DataViewObject::fun_getFloat32(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<is, getFloat32Impl>(cx, args);
@@ -3128,17 +3129,17 @@ DataViewObject::getFloat64Impl(JSContext
     JS_ASSERT(is(args.thisv()));
 
     Rooted<DataViewObject*> thisView(cx, &args.thisv().toObject().as<DataViewObject>());
 
     double val;
     if (!read(cx, thisView, args, &val, "getFloat64"))
         return false;
 
-    args.rval().setDouble(JS_CANONICALIZE_NAN(val));
+    args.rval().setDouble(CanonicalizeNaN(val));
     return true;
 }
 
 bool
 DataViewObject::fun_getFloat64(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<is, getFloat64Impl>(cx, args);