Bug 884410 - Remove JS_ValueToNumber. r=terrence
authorTom Schuster <evilpies@gmail.com>
Sat, 19 Oct 2013 18:39:52 +0200
changeset 151772 313eee20c52fab692f64c88be95de5b9c094332f
parent 151771 cc9ce7c8ab997aedfca52933f7637aa63c356de8
child 151773 5373095214d9b1d0fa695388717161fc28e1a1c8
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersterrence
bugs884410
milestone27.0a1
Bug 884410 - Remove JS_ValueToNumber. r=terrence
dom/base/nsDOMClassInfo.cpp
dom/bindings/DOMJSProxyHandler.cpp
dom/workers/WorkerPrivate.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/shell/js.cpp
js/xpconnect/src/dictionary_helper_gen.py
js/xpconnect/src/qsgen.py
toolkit/components/places/History.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1414,20 +1414,20 @@ nsDOMClassInfo::GetArrayIndexFromId(JSCo
   if (aIsNumber) {
     *aIsNumber = false;
   }
 
   int i;
   if (JSID_IS_INT(id)) {
       i = JSID_TO_INT(id);
   } else {
-      jsval idval;
+      JS::RootedValue idval(cx);
       double array_index;
-      if (!::JS_IdToValue(cx, id, &idval) ||
-          !::JS_ValueToNumber(cx, idval, &array_index) ||
+      if (!::JS_IdToValue(cx, id, idval.address()) ||
+          !JS::ToNumber(cx, idval, &array_index) ||
           !::JS_DoubleIsInt32(array_index, &i)) {
         return -1;
       }
   }
 
   if (aIsNumber) {
     *aIsNumber = true;
   }
--- a/dom/bindings/DOMJSProxyHandler.cpp
+++ b/dom/bindings/DOMJSProxyHandler.cpp
@@ -262,21 +262,21 @@ DOMProxyHandler::has(JSContext* cx, JS::
     *bp = protoHasProp;
   }
   return ok;
 }
 
 int32_t
 IdToInt32(JSContext* cx, JS::Handle<jsid> id)
 {
-  JS::Value idval;
+  JS::RootedValue idval(cx);
   double array_index;
   int32_t i;
-  if (!::JS_IdToValue(cx, id, &idval) ||
-      !::JS_ValueToNumber(cx, idval, &array_index) ||
+  if (!::JS_IdToValue(cx, id, idval.address()) ||
+      !JS::ToNumber(cx, idval, &array_index) ||
       !::JS_DoubleIsInt32(array_index, &i)) {
     return -1;
   }
 
   return i;
 }
 
 } // namespace dom
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -4641,17 +4641,18 @@ WorkerPrivate::SetTimeout(JSContext* aCx
     JS_ReportError(aCx, "Useless %s call (missing quotes around argument?)",
                    aIsInterval ? "setInterval" : "setTimeout");
     return false;
   }
 
   // See if any of the optional arguments were passed.
   if (aArgc > 1) {
     double intervalMS = 0;
-    if (!JS_ValueToNumber(aCx, argv[1], &intervalMS)) {
+    JS::RootedValue interval(aCx, argv[1]);
+    if (!JS::ToNumber(aCx, interval, &intervalMS)) {
       return false;
     }
     newInfo->mInterval = TimeDuration::FromMilliseconds(intervalMS);
 
     if (aArgc > 2 && newInfo->mTimeoutVal.isObject()) {
       nsTArray<JS::Heap<JS::Value> > extraArgVals(aArgc - 2);
       for (unsigned index = 2; index < aArgc; index++) {
         extraArgVals.AppendElement(argv[index]);
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -256,21 +256,21 @@ JS_ConvertArgumentsVA(JSContext *cx, uns
             if (!JS_ValueToECMAUint32(cx, *sp, va_arg(ap, uint32_t *)))
                 return false;
             break;
           case 'j':
             if (!JS_ValueToInt32(cx, *sp, va_arg(ap, int32_t *)))
                 return false;
             break;
           case 'd':
-            if (!JS_ValueToNumber(cx, *sp, va_arg(ap, double *)))
+            if (!ToNumber(cx, arg, va_arg(ap, double *)))
                 return false;
             break;
           case 'I':
-            if (!JS_ValueToNumber(cx, *sp, &d))
+            if (!ToNumber(cx, arg, &d))
                 return false;
             *va_arg(ap, double *) = ToInteger(d);
             break;
           case 'S':
           case 'W':
             val = *sp;
             str = ToString<CanGC>(cx, val);
             if (!str)
@@ -351,17 +351,17 @@ JS_ConvertValue(JSContext *cx, HandleVal
         break;
       case JSTYPE_STRING:
         str = ToString<CanGC>(cx, value);
         ok = (str != nullptr);
         if (ok)
             vp.setString(str);
         break;
       case JSTYPE_NUMBER:
-        ok = JS_ValueToNumber(cx, value, &d);
+        ok = ToNumber(cx, value, &d);
         if (ok)
             vp.setDouble(d);
         break;
       case JSTYPE_BOOLEAN:
         vp.setBoolean(ToBoolean(value));
         return true;
       default: {
         char numBuf[12];
@@ -425,23 +425,16 @@ JS_ValueToSource(JSContext *cx, jsval va
     RootedValue value(cx, valueArg);
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, value);
     return ValueToSource(cx, value);
 }
 
 JS_PUBLIC_API(bool)
-JS_ValueToNumber(JSContext *cx, jsval valueArg, double *dp)
-{
-    RootedValue value(cx, valueArg);
-    return JS::ToNumber(cx, value, dp);
-}
-
-JS_PUBLIC_API(bool)
 JS_DoubleIsInt32(double d, int32_t *ip)
 {
     return mozilla::DoubleIsInt32(d, ip);
 }
 
 JS_PUBLIC_API(int32_t)
 JS_DoubleToInt32(double d)
 {
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1036,19 +1036,16 @@ extern JS_PUBLIC_API(JSFunction *)
 JS_ValueToConstructor(JSContext *cx, JS::HandleValue v);
 
 extern JS_PUBLIC_API(JSString *)
 JS_ValueToString(JSContext *cx, jsval v);
 
 extern JS_PUBLIC_API(JSString *)
 JS_ValueToSource(JSContext *cx, jsval v);
 
-extern JS_PUBLIC_API(bool)
-JS_ValueToNumber(JSContext *cx, jsval v, double *dp);
-
 namespace js {
 /*
  * DO NOT CALL THIS.  Use JS::ToNumber
  */
 extern JS_PUBLIC_API(bool)
 ToNumberSlow(JSContext *cx, JS::Value v, double *dp);
 
 /*
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2829,26 +2829,27 @@ Resolver(JSContext *cx, unsigned argc, j
  */
 static bool
 IsBefore(int64_t t1, int64_t t2)
 {
     return int32_t(t1 - t2) < 0;
 }
 
 static bool
-Sleep_fn(JSContext *cx, unsigned argc, jsval *vp)
+Sleep_fn(JSContext *cx, unsigned argc, Value *vp)
 {
+    CallArgs args = CallArgsFromVp(argc, vp);
     int64_t t_ticks;
 
-    if (argc == 0) {
+    if (args.length() == 0) {
         t_ticks = 0;
     } else {
         double t_secs;
 
-        if (!JS_ValueToNumber(cx, argc == 0 ? UndefinedValue() : vp[2], &t_secs))
+        if (!ToNumber(cx, args[0], &t_secs))
             return false;
 
         /* NB: The next condition also filter out NaNs. */
         if (!(t_secs <= MAX_TIMEOUT_INTERVAL)) {
             JS_ReportError(cx, "Excessive sleep interval");
             return false;
         }
         t_ticks = (t_secs <= 0.0)
@@ -3087,42 +3088,44 @@ SetTimeoutValue(JSContext *cx, double t)
     if (!ScheduleWatchdog(cx->runtime(), t)) {
         JS_ReportError(cx, "Failed to create the watchdog");
         return false;
     }
     return true;
 }
 
 static bool
-Timeout(JSContext *cx, unsigned argc, jsval *vp)
+Timeout(JSContext *cx, unsigned argc, Value *vp)
 {
-    if (argc == 0) {
-        JS_SET_RVAL(cx, vp, JS_NumberValue(gTimeoutInterval));
+    CallArgs args = CallArgsFromVp(argc, vp);
+
+    if (args.length() == 0) {
+        args.rval().setNumber(gTimeoutInterval);
         return true;
     }
 
-    if (argc > 2) {
+    if (args.length() > 2) {
         JS_ReportError(cx, "Wrong number of arguments");
         return false;
     }
 
     double t;
-    if (!JS_ValueToNumber(cx, JS_ARGV(cx, vp)[0], &t))
-        return false;
-
-    if (argc > 1) {
-        RootedValue value(cx, JS_ARGV(cx, vp)[1]);
+    if (!ToNumber(cx, args[0], &t))
+        return false;
+
+    if (args.length() > 1) {
+        RootedValue value(cx, args[1]);
         if (!value.isObject() || !value.toObject().is<JSFunction>()) {
             JS_ReportError(cx, "Second argument must be a timeout function");
             return false;
         }
         gTimeoutFunc = value;
     }
 
-    JS_SET_RVAL(cx, vp, UndefinedValue());
+    args.rval().setUndefined();
     return SetTimeoutValue(cx, t);
 }
 
 static bool
 Elapsed(JSContext *cx, unsigned argc, jsval *vp)
 {
     if (argc == 0) {
         double d = 0.0;
--- a/js/xpconnect/src/dictionary_helper_gen.py
+++ b/js/xpconnect/src/dictionary_helper_gen.py
@@ -297,20 +297,20 @@ def write_getter(a, iface, fd):
         fd.write("    NS_ENSURE_STATE(JS_ValueToECMAUint32(aCx, v, &aDict.%s));\n" % a.name)
     elif realtype.count("int32_t"):
         fd.write("    NS_ENSURE_STATE(JS::ToInt32(aCx, v, &aDict.%s));\n" % a.name)
     elif realtype.count("uint64_t"):
         fd.write("    NS_ENSURE_STATE(JS::ToUint64(aCx, v, &aDict.%s));\n" % a.name)
     elif realtype.count("int64_t"):
         fd.write("    NS_ENSURE_STATE(JS::ToInt64(aCx, v, &aDict.%s));\n" % a.name)
     elif realtype.count("double"):
-        fd.write("    NS_ENSURE_STATE(JS_ValueToNumber(aCx, v, &aDict.%s));\n" % a.name)
+        fd.write("    NS_ENSURE_STATE(JS::ToNumber(aCx, v, &aDict.%s));\n" % a.name)
     elif realtype.count("float"):
         fd.write("    double d;\n")
-        fd.write("    NS_ENSURE_STATE(JS_ValueToNumber(aCx, v, &d));")
+        fd.write("    NS_ENSURE_STATE(JS::ToNumber(aCx, v, &d));")
         fd.write("    aDict.%s = (float) d;\n" % a.name)
     elif realtype.count("nsAString"):
         if a.nullable:
             fd.write("    xpc_qsDOMString d(aCx, v, &v, false, xpc_qsDOMString::eNull, xpc_qsDOMString::eNull);\n")
         else:
             fd.write("    xpc_qsDOMString d(aCx, v, &v, false, xpc_qsDOMString::eStringify, xpc_qsDOMString::eStringify);\n")
         fd.write("    NS_ENSURE_STATE(d.IsValid());\n")
         fd.write("    aDict.%s = d;\n" % a.name)
--- a/js/xpconnect/src/qsgen.py
+++ b/js/xpconnect/src/qsgen.py
@@ -418,23 +418,23 @@ argumentUnboxingTemplates = {
 
     'unsigned long long':
         "    uint64_t ${name};\n"
         "    if (!JS::ToUint64(cx, ${argVal}, &${name}))\n"
         "        return false;\n",
 
     'float':
         "    double ${name}_dbl;\n"
-        "    if (!JS_ValueToNumber(cx, ${argVal}, &${name}_dbl))\n"
+        "    if (!JS::ToNumber(cx, ${argVal}, &${name}_dbl))\n"
         "        return false;\n"
         "    float ${name} = (float) ${name}_dbl;\n",
 
     'double':
         "    double ${name};\n"
-        "    if (!JS_ValueToNumber(cx, ${argVal}, &${name}))\n"
+        "    if (!JS::ToNumber(cx, ${argVal}, &${name}))\n"
         "        return false;\n",
 
     'boolean':
         "    bool ${name};\n"
         "    JS_ValueToBoolean(cx, ${argVal}, &${name});\n",
 
     '[astring]':
         "    xpc_qsAString ${name}(cx, ${argVal}, ${argPtr}, ${notPassed});\n"
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -390,17 +390,17 @@ GetIntFromJSObject(JSContext* aCtx,
   NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
   if (JSVAL_IS_VOID(value)) {
     return NS_ERROR_INVALID_ARG;
   }
   NS_ENSURE_ARG(JSVAL_IS_PRIMITIVE(value));
   NS_ENSURE_ARG(JSVAL_IS_NUMBER(value));
 
   double num;
-  rc = JS_ValueToNumber(aCtx, value, &num);
+  rc = JS::ToNumber(aCtx, value, &num);
   NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
   NS_ENSURE_ARG(IntType(num) == num);
 
   *_int = IntType(num);
   return NS_OK;
 }
 
 /**