Bug 653438 - Fix number.toExponential(undefined) to behave like number.toExponential() and remove some dead code. r=till
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 05 Dec 2013 14:47:35 +0100
changeset 174600 b58f32ae7646b82a2a3d45871c712d0b68bda2a9
parent 174599 c923a7e0c5ad7ae4ee52cda6a49ae74a93ed4d93
child 174601 39a0ab97012e5ceb6cf2efb39767532c6396c981
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs653438
milestone28.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 653438 - Fix number.toExponential(undefined) to behave like number.toExponential() and remove some dead code. r=till
js/src/jit-test/tests/basic/bug653438.js
js/src/jsnum.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug653438.js
@@ -0,0 +1,2 @@
+assertEq((123456789).toExponential(), "1.23456789e+8");
+assertEq((123456789).toExponential(undefined), "1.23456789e+8");
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -934,17 +934,17 @@ num_toFixed(JSContext *cx, unsigned argc
 
 JS_ALWAYS_INLINE bool
 num_toExponential_impl(JSContext *cx, CallArgs args)
 {
     JS_ASSERT(IsNumber(args.thisv()));
 
     JSDToStrMode mode;
     int precision;
-    if (args.length() == 0) {
+    if (!args.hasDefined(0)) {
         mode = DTOSTR_STANDARD_EXPONENTIAL;
         precision = 0;
     } else {
         mode = DTOSTR_EXPONENTIAL;
         if (!ComputePrecisionInRange(cx, 0, MAX_PRECISION, args[0], &precision))
             return false;
     }
 
@@ -970,28 +970,21 @@ num_toPrecision_impl(JSContext *cx, Call
         if (!str) {
             JS_ReportOutOfMemory(cx);
             return false;
         }
         args.rval().setString(str);
         return true;
     }
 
-    JSDToStrMode mode;
     int precision;
-    if (args.length() == 0) {
-        mode = DTOSTR_STANDARD;
-        precision = 0;
-    } else {
-        mode = DTOSTR_PRECISION;
-        if (!ComputePrecisionInRange(cx, 1, MAX_PRECISION, args[0], &precision))
-            return false;
-    }
+    if (!ComputePrecisionInRange(cx, 1, MAX_PRECISION, args[0], &precision))
+        return false;
 
-    return DToStrResult(cx, d, mode, precision, args);
+    return DToStrResult(cx, d, DTOSTR_PRECISION, precision, args);
 }
 
 static bool
 num_toPrecision(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     return CallNonGenericMethod<IsNumber, num_toPrecision_impl>(cx, args);
 }