Bug 1297720 - Streamline ToNumberSlow's code so it matches ToStringSlow. r=till
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 01 Nov 2016 10:23:35 -0700
changeset 347581 382e04e39c82ef5a38f11f713deedd933c526ca1
parent 347580 d3041026a9219ae3fdf6b6e081a2a0e679b23af7
child 347582 3219bfc7b776e975cb92f8849cba4c43b40c1b2a
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1297720
milestone52.0a1
Bug 1297720 - Streamline ToNumberSlow's code so it matches ToStringSlow. r=till
js/src/jsnum.cpp
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -1573,57 +1573,48 @@ js::StringToNumber(ExclusiveContext* cx,
            : CharsToNumber(cx, linearStr->twoByteChars(nogc), str->length(), result);
 }
 
 bool
 js::ToNumberSlow(ExclusiveContext* cx, HandleValue v_, double* out)
 {
     RootedValue v(cx, v_);
     MOZ_ASSERT(!v.isNumber());
-    goto skip_int_double;
-    for (;;) {
-        if (v.isNumber()) {
-            *out = v.toNumber();
-            return true;
-        }
 
-      skip_int_double:
-        if (!v.isObject()) {
-            if (v.isString())
-                return StringToNumber(cx, v.toString(), out);
-            if (v.isBoolean()) {
-                *out = v.toBoolean() ? 1.0 : 0.0;
-                return true;
-            }
-            if (v.isNull()) {
-                *out = 0.0;
-                return true;
-            }
-            if (v.isSymbol()) {
-                if (cx->isJSContext()) {
-                    JS_ReportErrorNumberASCII(cx->asJSContext(), GetErrorMessage, nullptr,
-                                              JSMSG_SYMBOL_TO_NUMBER);
-                }
-                return false;
-            }
-
-            MOZ_ASSERT(v.isUndefined());
-            *out = GenericNaN();
-            return true;
-        }
-
+    if (!v.isPrimitive()) {
         if (!cx->isJSContext())
             return false;
 
         if (!ToPrimitive(cx->asJSContext(), JSTYPE_NUMBER, &v))
             return false;
-        if (v.isObject())
-            break;
+
+        if (v.isNumber()) {
+            *out = v.toNumber();
+            return true;
+        }
+    }
+    if (v.isString())
+        return StringToNumber(cx, v.toString(), out);
+    if (v.isBoolean()) {
+        *out = v.toBoolean() ? 1.0 : 0.0;
+        return true;
+    }
+    if (v.isNull()) {
+        *out = 0.0;
+        return true;
+    }
+    if (v.isSymbol()) {
+        if (cx->isJSContext()) {
+            JS_ReportErrorNumberASCII(cx->asJSContext(), GetErrorMessage, nullptr,
+                                      JSMSG_SYMBOL_TO_NUMBER);
+        }
+        return false;
     }
 
+    MOZ_ASSERT(v.isUndefined());
     *out = GenericNaN();
     return true;
 }
 
 JS_PUBLIC_API(bool)
 js::ToNumberSlow(JSContext* cx, HandleValue v, double* out)
 {
     return ToNumberSlow(static_cast<ExclusiveContext*>(cx), v, out);