Bug 1453809: Call ToUint16 in ToUint16Slow. r=Waldo
authorAndré Bargull <andre.bargull@gmail.com>
Thu, 12 Apr 2018 14:56:03 -0700
changeset 467813 06911984ea8738053b829ee2f396a598999159d5
parent 467812 fd2a5219b1033d6d233629c04502f9488808819a
child 467814 6480454995dae4a44c86887f4ae01dc998edb36f
child 467865 9c39f5ae7a07bb1a3c20d1fde49db39f8552da01
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1453809
milestone61.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 1453809: Call ToUint16 in ToUint16Slow. r=Waldo
js/src/jsnum.cpp
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -51,16 +51,18 @@ using mozilla::PositiveInfinity;
 using mozilla::RangedPtr;
 
 using JS::AutoCheckCannotGC;
 using JS::GenericNaN;
 using JS::ToInt8;
 using JS::ToInt16;
 using JS::ToInt32;
 using JS::ToInt64;
+using JS::ToUint8;
+using JS::ToUint16;
 using JS::ToUint32;
 using JS::ToUint64;
 
 static bool
 EnsureDtoaState(JSContext* cx)
 {
     if (!cx->dtoaState) {
         cx->dtoaState = NewDtoaState();
@@ -1629,17 +1631,17 @@ js::ToUint8Slow(JSContext *cx, const Han
     MOZ_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else {
         if (!ToNumberSlow(cx, v, &d))
             return false;
     }
-    *out = ToInt8(d);
+    *out = ToUint8(d);
     return true;
 }
 
 /*
  * Convert a value to an int16_t, according to the WebIDL rules for short
  * conversion. Return converted value in *out on success, false on failure.
  */
 JS_PUBLIC_API(bool)
@@ -1730,36 +1732,17 @@ js::ToUint16Slow(JSContext* cx, const Ha
 {
     MOZ_ASSERT(!v.isInt32());
     double d;
     if (v.isDouble()) {
         d = v.toDouble();
     } else if (!ToNumberSlow(cx, v, &d)) {
         return false;
     }
-
-    if (d == 0 || !mozilla::IsFinite(d)) {
-        *out = 0;
-        return true;
-    }
-
-    uint16_t u = (uint16_t) d;
-    if ((double)u == d) {
-        *out = u;
-        return true;
-    }
-
-    bool neg = (d < 0);
-    d = floor(neg ? -d : d);
-    d = neg ? -d : d;
-    unsigned m = JS_BIT(16);
-    d = fmod(d, (double) m);
-    if (d < 0)
-        d += m;
-    *out = (uint16_t) d;
+    *out = ToUint16(d);
     return true;
 }
 
 // ES2017 draft 7.1.17 ToIndex
 bool
 js::ToIndex(JSContext* cx, JS::HandleValue v, const unsigned errorNumber, uint64_t* index)
 {
     // Step 1.