Bug 1125784 - Remove JS_ConvertArguments and JS_ConvertValue. r=jorendorff
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 05 Feb 2015 12:01:11 +0100
changeset 256480 0ae3113e0583c699f1babe41eb1c9cdc85f0c988
parent 256479 b2e330b524b9a9c98a670adc7e001640fd4f6e4c
child 256481 2edd2f2ff1d94609c5c107632b337fc79f61c821
push id721
push userjlund@mozilla.com
push dateTue, 21 Apr 2015 23:03:33 +0000
treeherdermozilla-release@d27c9211ebb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1125784
milestone38.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 1125784 - Remove JS_ConvertArguments and JS_ConvertValue. r=jorendorff
js/src/builtin/TestingFunctions.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/shell/js.cpp
js/xpconnect/src/XPCShellImpl.cpp
netwerk/base/ProxyAutoConfig.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -1837,18 +1837,18 @@ DisableTraceLogger(JSContext *cx, unsign
     return true;
 }
 
 #ifdef DEBUG
 static bool
 DumpObject(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-    RootedObject obj(cx);
-    if (!JS_ConvertArguments(cx, args, "o", obj.address()))
+    RootedObject obj(cx, ToObject(cx, args.get(0)));
+    if (!obj)
         return false;
 
     js_DumpObject(obj);
 
     args.rval().setUndefined();
     return true;
 }
 #endif
@@ -2172,21 +2172,29 @@ FindPath(JSContext *cx, unsigned argc, j
     args.rval().setObject(*result);
     return true;
 }
 
 static bool
 EvalReturningScope(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-
-    RootedString str(cx);
+    if (!args.requireAtLeast(cx, "evalReturningScope", 1))
+        return false;
+
+    RootedString str(cx, ToString(cx, args[0]));
+    if (!str)
+        return false;
+
     RootedObject global(cx);
-    if (!JS_ConvertArguments(cx, args, "S/o", str.address(), global.address()))
-        return false;
+    if (args.hasDefined(1)) {
+        global = ToObject(cx, args[1]);
+        if (!global)
+            return false;
+    }
 
     AutoStableStringChars strChars(cx);
     if (!strChars.initTwoByte(cx, str))
         return false;
 
     mozilla::Range<const char16_t> chars = strChars.twoByteRange();
     size_t srclen = chars.length();
     const char16_t *src = chars.start().get();
@@ -2238,20 +2246,25 @@ EvalReturningScope(JSContext *cx, unsign
     args.rval().setObject(*scope);
     return true;
 }
 
 static bool
 ShellCloneAndExecuteScript(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-
-    RootedString str(cx);
-    RootedObject global(cx);
-    if (!JS_ConvertArguments(cx, args, "So", str.address(), global.address()))
+    if (!args.requireAtLeast(cx, "cloneAndExecuteScript", 2))
+        return false;
+
+    RootedString str(cx, ToString(cx, args[0]));
+    if (!str)
+        return false;
+
+    RootedObject global(cx, ToObject(cx, args[1]));
+    if (!global)
         return false;
 
     AutoStableStringChars strChars(cx);
     if (!strChars.initTwoByte(cx, str))
         return false;
 
     mozilla::Range<const char16_t> chars = strChars.twoByteRange();
     size_t srclen = chars.length();
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -225,189 +225,16 @@ AssertHeapIsIdleOrStringIsFlat(JSContext
     /*
      * We allow some functions to be called during a GC as long as the argument
      * is a flat string, since that will not cause allocation.
      */
     MOZ_ASSERT_IF(cx->runtime()->isHeapBusy(), str->isFlat());
 }
 
 JS_PUBLIC_API(bool)
-JS_ConvertArguments(JSContext *cx, const CallArgs &args, const char *format, ...)
-{
-    va_list ap;
-    bool ok;
-
-    AssertHeapIsIdle(cx);
-
-    va_start(ap, format);
-    ok = JS_ConvertArgumentsVA(cx, args, format, ap);
-    va_end(ap);
-    return ok;
-}
-
-JS_PUBLIC_API(bool)
-JS_ConvertArgumentsVA(JSContext *cx, const CallArgs &args, const char *format, va_list ap)
-{
-    unsigned index = 0;
-    bool required;
-    char c;
-    double d;
-    JSString *str;
-    RootedObject obj(cx);
-    RootedValue val(cx);
-
-    AssertHeapIsIdle(cx);
-    CHECK_REQUEST(cx);
-    assertSameCompartment(cx, args);
-    required = true;
-    while ((c = *format++) != '\0') {
-        if (isspace(c))
-            continue;
-        if (c == '/') {
-            required = false;
-            continue;
-        }
-        if (index == args.length()) {
-            if (required) {
-                if (JSFunction *fun = ReportIfNotFunction(cx, args.calleev())) {
-                    char numBuf[12];
-                    JS_snprintf(numBuf, sizeof numBuf, "%u", args.length());
-                    JSAutoByteString funNameBytes;
-                    if (const char *name = GetFunctionNameBytes(cx, fun, &funNameBytes)) {
-                        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr,
-                                             JSMSG_MORE_ARGS_NEEDED,
-                                             name, numBuf, (args.length() == 1) ? "" : "s");
-                    }
-                }
-                return false;
-            }
-            break;
-        }
-        MutableHandleValue arg = args[index++];
-        switch (c) {
-          case 'b':
-            *va_arg(ap, bool *) = ToBoolean(arg);
-            break;
-          case 'c':
-            if (!ToUint16(cx, arg, va_arg(ap, uint16_t *)))
-                return false;
-            break;
-          case 'i':
-          case 'j': // "j" was broken, you should not use it.
-            if (!ToInt32(cx, arg, va_arg(ap, int32_t *)))
-                return false;
-            break;
-          case 'u':
-            if (!ToUint32(cx, arg, va_arg(ap, uint32_t *)))
-                return false;
-            break;
-          case 'd':
-            if (!ToNumber(cx, arg, va_arg(ap, double *)))
-                return false;
-            break;
-          case 'I':
-            if (!ToNumber(cx, arg, &d))
-                return false;
-            *va_arg(ap, double *) = ToInteger(d);
-            break;
-          case 'S':
-            str = ToString<CanGC>(cx, arg);
-            if (!str)
-                return false;
-            arg.setString(str);
-            *va_arg(ap, JSString **) = str;
-            break;
-          case 'o':
-            if (arg.isNullOrUndefined()) {
-                obj = nullptr;
-            } else {
-                obj = ToObject(cx, arg);
-                if (!obj)
-                    return false;
-            }
-            arg.setObjectOrNull(obj);
-            *va_arg(ap, JSObject **) = obj;
-            break;
-          case 'f':
-            obj = ReportIfNotFunction(cx, arg);
-            if (!obj)
-                return false;
-            arg.setObject(*obj);
-            *va_arg(ap, JSFunction **) = &obj->as<JSFunction>();
-            break;
-          case 'v':
-            *va_arg(ap, jsval *) = arg;
-            break;
-          case '*':
-            break;
-          default:
-            JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_BAD_CHAR, format);
-            return false;
-        }
-    }
-    return true;
-}
-
-JS_PUBLIC_API(bool)
-JS_ConvertValue(JSContext *cx, HandleValue value, JSType type, MutableHandleValue vp)
-{
-    bool ok;
-    RootedObject obj(cx);
-    JSString *str;
-    double d;
-
-    AssertHeapIsIdle(cx);
-    CHECK_REQUEST(cx);
-    assertSameCompartment(cx, value);
-    switch (type) {
-      case JSTYPE_VOID:
-        vp.setUndefined();
-        ok = true;
-        break;
-      case JSTYPE_OBJECT:
-        if (value.isNullOrUndefined()) {
-            obj.set(nullptr);
-        } else {
-            obj = ToObject(cx, value);
-            if (!obj)
-                return false;
-        }
-        ok = true;
-        break;
-      case JSTYPE_FUNCTION:
-        vp.set(value);
-        obj = ReportIfNotFunction(cx, vp);
-        ok = (obj != nullptr);
-        break;
-      case JSTYPE_STRING:
-        str = ToString<CanGC>(cx, value);
-        ok = (str != nullptr);
-        if (ok)
-            vp.setString(str);
-        break;
-      case JSTYPE_NUMBER:
-        ok = ToNumber(cx, value, &d);
-        if (ok)
-            vp.setDouble(d);
-        break;
-      case JSTYPE_BOOLEAN:
-        vp.setBoolean(ToBoolean(value));
-        return true;
-      default: {
-        char numBuf[12];
-        JS_snprintf(numBuf, sizeof numBuf, "%d", (int)type);
-        JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_BAD_TYPE, numBuf);
-        ok = false;
-        break;
-      }
-    }
-    return ok;
-}
-
-JS_PUBLIC_API(bool)
 JS_ValueToObject(JSContext *cx, HandleValue value, MutableHandleObject objp)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, value);
     if (value.isNullOrUndefined()) {
         objp.set(nullptr);
         return true;
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1033,60 +1033,16 @@ struct CompartmentTimeStats {
     uint64_t cpowTime; // microseconds
 };
 
 typedef js::Vector<CompartmentTimeStats, 0, js::SystemAllocPolicy> CompartmentStatsVector;
 
 extern JS_PUBLIC_API(bool)
 JS_GetCompartmentStats(JSRuntime *rt, CompartmentStatsVector &stats);
 
-/*
- * Format is a string of the following characters (spaces are insignificant),
- * specifying the tabulated type conversions:
- *
- *   b      bool            Boolean
- *   c      char16_t        ECMA uint16_t, Unicode character
- *   i      int32_t         ECMA int32_t
- *   j      int32_t         ECMA int32_t (used to be different)
- *   u      uint32_t        ECMA uint32_t
- *   d      double          IEEE double
- *   I      double          Integral IEEE double
- *   S      JSString *      Unicode string, accessed by a JSString pointer
- *   W      char16_t *      Unicode character vector, 0-terminated (W for wide)
- *   o      JSObject *      Object reference
- *   f      JSFunction *    Function private
- *   v      jsval           Argument value (no conversion)
- *   *      N/A             Skip this argument (no vararg)
- *   /      N/A             End of required arguments
- *
- * The variable argument list after format must consist of &b, &c, &s, e.g.,
- * where those variables have the types given above.  For the pointer types
- * char *, JSString *, and JSObject *, the pointed-at memory returned belongs
- * to the JS runtime, not to the calling native code.  The runtime promises
- * to keep this memory valid so long as argv refers to allocated stack space
- * (so long as the native function is active).
- *
- * Fewer arguments than format specifies may be passed only if there is a /
- * in format after the last required argument specifier and argc is at least
- * the number of required arguments.  More arguments than format specifies
- * may be passed without error; it is up to the caller to deal with trailing
- * unconverted arguments.
- */
-extern JS_PUBLIC_API(bool)
-JS_ConvertArguments(JSContext *cx, const JS::CallArgs &args, const char *format, ...);
-
-#ifdef va_start
-extern JS_PUBLIC_API(bool)
-JS_ConvertArgumentsVA(JSContext *cx, const JS::CallArgs &args, const char *format,
-                      va_list ap);
-#endif
-
-extern JS_PUBLIC_API(bool)
-JS_ConvertValue(JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp);
-
 extern JS_PUBLIC_API(bool)
 JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
 
 extern JS_PUBLIC_API(JSFunction *)
 JS_ValueToFunction(JSContext *cx, JS::HandleValue v);
 
 extern JS_PUBLIC_API(JSFunction *)
 JS_ValueToConstructor(JSContext *cx, JS::HandleValue v);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2675,21 +2675,29 @@ NewSandbox(JSContext *cx, bool lazy)
         return nullptr;
     return obj;
 }
 
 static bool
 EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-
-    RootedString str(cx);
+    if (!args.requireAtLeast(cx, "evalcx", 1))
+        return false;
+
+    RootedString str(cx, ToString(cx, args[0]));
+    if (!str)
+        return false;
+
     RootedObject sobj(cx);
-    if (!JS_ConvertArguments(cx, args, "S / o", str.address(), sobj.address()))
-        return false;
+    if (args.hasDefined(1)) {
+        sobj = ToObject(cx, args[1]);
+        if (!sobj)
+            return false;
+    }
 
     AutoStableStringChars strChars(cx);
     if (!strChars.initTwoByte(cx, str))
         return false;
 
     mozilla::Range<const char16_t> chars = strChars.twoByteRange();
     size_t srclen = chars.length();
     const char16_t *src = chars.start().get();
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -367,18 +367,21 @@ BuildDate(JSContext *cx, unsigned argc, 
     fprintf(gOutFile, "built on %s at %s\n", __DATE__, __TIME__);
     args.rval().setUndefined();
     return true;
 }
 
 static bool
 Quit(JSContext *cx, unsigned argc, jsval *vp)
 {
+    CallArgs args = CallArgsFromVp(argc, vp);
+
     gExitCode = 0;
-    JS_ConvertArguments(cx, JS::CallArgsFromVp(argc, vp),"/ i", &gExitCode);
+    if (!ToInt32(cx, args.get(0), &gExitCode))
+        return false;
 
     gQuitting = true;
 //    exit(0);
     return false;
 }
 
 // Provide script a way to disable the xpcshell error reporter, preventing
 // reported errors from being logged to the console and also from affecting the
--- a/netwerk/base/ProxyAutoConfig.cpp
+++ b/netwerk/base/ProxyAutoConfig.cpp
@@ -411,18 +411,21 @@ bool PACDnsResolve(JSContext *cx, unsign
 {
   JS::CallArgs args = CallArgsFromVp(argc, vp);
 
   if (NS_IsMainThread()) {
     NS_WARNING("DNS Resolution From PAC on Main Thread. How did that happen?");
     return false;
   }
 
-  JS::Rooted<JSString*> arg1(cx);
-  if (!JS_ConvertArguments(cx, args, "S", arg1.address()))
+  if (!args.requireAtLeast(cx, "dnsResolve", 1))
+    return false;
+
+  JS::Rooted<JSString*> arg1(cx, JS::ToString(cx, args[0]));
+  if (!arg1)
     return false;
 
   nsAutoJSString hostName;
   nsAutoCString dottedDecimal;
 
   if (!hostName.init(cx, arg1))
     return false;
   if (PACResolveToString(NS_ConvertUTF16toUTF8(hostName), dottedDecimal, 0)) {
@@ -460,18 +463,21 @@ bool PACMyIpAddress(JSContext *cx, unsig
 }
 
 // proxyAlert(msg) javascript implementation
 static
 bool PACProxyAlert(JSContext *cx, unsigned int argc, JS::Value *vp)
 {
   JS::CallArgs args = CallArgsFromVp(argc, vp);
 
-  JS::Rooted<JSString*> arg1(cx);
-  if (!JS_ConvertArguments(cx, args, "S", arg1.address()))
+  if (!args.requireAtLeast(cx, "alert", 1))
+    return false;
+
+  JS::Rooted<JSString*> arg1(cx, JS::ToString(cx, args[0]));
+  if (!arg1)
     return false;
 
   nsAutoJSString message;
   if (!message.init(cx, arg1))
     return false;
 
   nsAutoString alertMessage;
   alertMessage.SetCapacity(32 + message.Length());