Bug 788359 - Remove unused argumentFormatMap and associated API; r=dmandelin
authorTerrence Cole <terrence@mozilla.com>
Tue, 04 Sep 2012 17:17:21 -0700
changeset 106995 46ac1ff1dca260f7a7c4a92c652090b8ef581a94
parent 106994 81bcdc9521510f23a0b5a3d6ffb898cda592b4c4
child 106996 d96c4d2a28be3ca1ba8234af3b9a4434c0f86d5f
push id14808
push usertcole@mozilla.com
push dateThu, 13 Sep 2012 19:04:32 +0000
treeherdermozilla-inbound@46ac1ff1dca2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmandelin
bugs788359
milestone18.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 788359 - Remove unused argumentFormatMap and associated API; r=dmandelin This removes some fiddly code sitting around completely unused and untested.
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jsprvtd.h
js/src/shell/js.cpp
js/xpconnect/src/XPCContext.cpp
layout/reftests/backgrounds/blue-32x32.png
mobile/android/config/mozconfigs/android/nightly
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -219,33 +219,16 @@ JS_GetEmptyStringValue(JSContext *cx)
 
 JS_PUBLIC_API(JSString *)
 JS_GetEmptyString(JSRuntime *rt)
 {
     JS_ASSERT(rt->hasContexts());
     return rt->emptyString;
 }
 
-static JSBool
-TryArgumentFormatter(JSContext *cx, const char **formatp, JSBool fromJS, jsval **vpp, va_list *app)
-{
-    const char *format;
-    JSArgumentFormatMap *map;
-
-    format = *formatp;
-    for (map = cx->argumentFormatMap; map; map = map->next) {
-        if (!strncmp(format, map->format, map->length)) {
-            *formatp = format + map->length;
-            return map->formatter(cx, format, fromJS, vpp, app);
-        }
-    }
-    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_CHAR, format);
-    return JS_FALSE;
-}
-
 static void
 AssertHeapIsIdle(JSRuntime *rt)
 {
     JS_ASSERT(rt->heapState == JSRuntime::Idle);
 }
 
 static void
 AssertHeapIsIdle(JSContext *cx)
@@ -384,76 +367,25 @@ JS_ConvertArgumentsVA(JSContext *cx, uns
             *va_arg(ap, JSFunction **) = obj->toFunction();
             break;
           case 'v':
             *va_arg(ap, jsval *) = *sp;
             break;
           case '*':
             break;
           default:
-            format--;
-            if (!TryArgumentFormatter(cx, &format, JS_TRUE, &sp,
-                                      JS_ADDRESSOF_VA_LIST(ap))) {
-                return JS_FALSE;
-            }
-            /* NB: the formatter already updated sp, so we continue here. */
-            continue;
+            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_CHAR, format);
+            return JS_FALSE;
         }
         sp++;
     }
     return JS_TRUE;
 }
 
 JS_PUBLIC_API(JSBool)
-JS_AddArgumentFormatter(JSContext *cx, const char *format, JSArgumentFormatter formatter)
-{
-    size_t length;
-    JSArgumentFormatMap **mpp, *map;
-
-    length = strlen(format);
-    mpp = &cx->argumentFormatMap;
-    while ((map = *mpp) != NULL) {
-        /* Insert before any shorter string to match before prefixes. */
-        if (map->length < length)
-            break;
-        if (map->length == length && !strcmp(map->format, format))
-            goto out;
-        mpp = &map->next;
-    }
-    map = cx->pod_malloc<JSArgumentFormatMap>();
-    if (!map)
-        return JS_FALSE;
-    map->format = format;
-    map->length = length;
-    map->next = *mpp;
-    *mpp = map;
-out:
-    map->formatter = formatter;
-    return JS_TRUE;
-}
-
-JS_PUBLIC_API(void)
-JS_RemoveArgumentFormatter(JSContext *cx, const char *format)
-{
-    size_t length;
-    JSArgumentFormatMap **mpp, *map;
-
-    length = strlen(format);
-    mpp = &cx->argumentFormatMap;
-    while ((map = *mpp) != NULL) {
-        if (map->length == length && !strcmp(map->format, format)) {
-            *mpp = map->next;
-            js_free(map);
-            return;
-        }
-        mpp = &map->next;
-    }
-}
-
-JS_PUBLIC_API(JSBool)
 JS_ConvertValue(JSContext *cx, jsval valueArg, JSType type, jsval *vp)
 {
     RootedValue value(cx, valueArg);
     JSBool ok;
     RootedObject obj(cx);
     JSString *str;
     double d;
 
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1939,24 +1939,16 @@ typedef struct JSErrorFormatString {
     /* One of the JSExnType constants above. */
     int16_t exnType;
 } JSErrorFormatString;
 
 typedef const JSErrorFormatString *
 (* JSErrorCallback)(void *userRef, const char *locale,
                     const unsigned errorNumber);
 
-#ifdef va_start
-#define JS_ARGUMENT_FORMATTER_DEFINED 1
-
-typedef JSBool
-(* JSArgumentFormatter)(JSContext *cx, const char *format, JSBool fromJS,
-                        jsval **vpp, va_list *app);
-#endif
-
 typedef JSBool
 (* JSLocaleToUpperCase)(JSContext *cx, JSString *src, jsval *rval);
 
 typedef JSBool
 (* JSLocaleToLowerCase)(JSContext *cx, JSString *src, jsval *rval);
 
 typedef JSBool
 (* JSLocaleCompare)(JSContext *cx, JSString *src1, JSString *src2,
@@ -2601,66 +2593,16 @@ JS_ConvertArguments(JSContext *cx, unsig
                     ...);
 
 #ifdef va_start
 extern JS_PUBLIC_API(JSBool)
 JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv,
                       const char *format, va_list ap);
 #endif
 
-#ifdef JS_ARGUMENT_FORMATTER_DEFINED
-
-/*
- * Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
- * The handler function has this signature:
- *
- *   JSBool MyArgumentFormatter(JSContext *cx, const char *format,
- *                              JSBool fromJS, jsval **vpp, va_list *app);
- *
- * It should return true on success, and return false after reporting an error
- * or detecting an already-reported error.
- *
- * For a given format string, for example "AA", the formatter is called from
- * JS_ConvertArgumentsVA like so:
- *
- *   formatter(cx, "AA...", JS_TRUE, &sp, &ap);
- *
- * sp points into the arguments array on the JS stack, while ap points into
- * the stdarg.h va_list on the C stack.  The JS_TRUE passed for fromJS tells
- * the formatter to convert zero or more jsvals at sp to zero or more C values
- * accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
- * (via *app) to point past the converted arguments and their result pointers
- * on the C stack.
- *
- * When called from JS_PushArgumentsVA, the formatter is invoked thus:
- *
- *   formatter(cx, "AA...", JS_FALSE, &sp, &ap);
- *
- * where JS_FALSE for fromJS means to wrap the C values at ap according to the
- * format specifier and store them at sp, updating ap and sp appropriately.
- *
- * The "..." after "AA" is the rest of the format string that was passed into
- * JS_{Convert,Push}Arguments{,VA}.  The actual format trailing substring used
- * in each Convert or PushArguments call is passed to the formatter, so that
- * one such function may implement several formats, in order to share code.
- *
- * Remove just forgets about any handler associated with format.  Add does not
- * copy format, it points at the string storage allocated by the caller, which
- * is typically a string constant.  If format is in dynamic storage, it is up
- * to the caller to keep the string alive until Remove is called.
- */
-extern JS_PUBLIC_API(JSBool)
-JS_AddArgumentFormatter(JSContext *cx, const char *format,
-                        JSArgumentFormatter formatter);
-
-extern JS_PUBLIC_API(void)
-JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
-
-#endif /* JS_ARGUMENT_FORMATTER_DEFINED */
-
 extern JS_PUBLIC_API(JSBool)
 JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
 
 extern JS_PUBLIC_API(JSFunction *)
 JS_ValueToFunction(JSContext *cx, jsval v);
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1202,17 +1202,16 @@ JSContext::JSContext(JSRuntime *rt)
     generatingError(false),
     compartment(NULL),
     enterCompartmentDepth_(0),
     savedFrameChains_(),
     defaultCompartmentObject_(NULL),
     stack(thisDuringConstruction()),
     parseMapPool_(NULL),
     cycleDetectorSet(thisDuringConstruction()),
-    argumentFormatMap(NULL),
     lastMessage(NULL),
     errorReporter(NULL),
     operationCallback(NULL),
     data(NULL),
     data2(NULL),
 #ifdef JS_THREADSAFE
     outstandingRequests(0),
 #endif
@@ -1245,24 +1244,16 @@ JSContext::~JSContext()
 {
     /* Free the stuff hanging off of cx. */
     if (parseMapPool_)
         js_delete(parseMapPool_);
 
     if (lastMessage)
         js_free(lastMessage);
 
-    /* Remove any argument formatters. */
-    JSArgumentFormatMap *map = argumentFormatMap;
-    while (map) {
-        JSArgumentFormatMap *temp = map;
-        map = map->next;
-        js_free(temp);
-    }
-
     JS_ASSERT(!resolvingList);
 }
 
 /*
  * Since this function is only called in the context of a pending exception,
  * the caller must subsequently take an error path. If wrapping fails, it will
  * set a new (uncatchable) exception to be used in place of the original.
  */
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1070,30 +1070,16 @@ struct JSRuntime : js::RuntimeFriendFiel
     void sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf, JS::RuntimeSizes *runtime);
     size_t sizeOfExplicitNonHeap();
 };
 
 /* Common macros to access thread-local caches in JSRuntime. */
 #define JS_KEEP_ATOMS(rt)   (rt)->gcKeepAtoms++;
 #define JS_UNKEEP_ATOMS(rt) (rt)->gcKeepAtoms--;
 
-#ifdef JS_ARGUMENT_FORMATTER_DEFINED
-/*
- * Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
- * formatter functions.  Elements are sorted in non-increasing format string
- * length order.
- */
-struct JSArgumentFormatMap {
-    const char          *format;
-    size_t              length;
-    JSArgumentFormatter formatter;
-    JSArgumentFormatMap *next;
-};
-#endif
-
 namespace js {
 
 struct AutoResolving;
 
 static inline bool
 OptionsHasAllowXML(uint32_t options)
 {
     return !!(options & JSOPTION_ALLOW_XML);
@@ -1313,19 +1299,16 @@ struct JSContext : js::ContextFriendFiel
   private:
     /* Lazily initialized pool of maps used during parse/emit. */
     js::frontend::ParseMapPool *parseMapPool_;
 
   public:
     /* State for object and array toSource conversion. */
     js::ObjectSet       cycleDetectorSet;
 
-    /* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
-    JSArgumentFormatMap *argumentFormatMap;
-
     /* Last message string and log file for debugging. */
     char                *lastMessage;
 
     /* Per-context optional error reporter. */
     JSErrorReporter     errorReporter;
 
     /* Branch callback. */
     JSOperationCallback operationCallback;
--- a/js/src/jsprvtd.h
+++ b/js/src/jsprvtd.h
@@ -42,17 +42,16 @@ static const unsigned JS_GCTHING_ALIGN =
 static const unsigned JS_GCTHING_ZEROBITS = 3;
 
 /* Scalar typedefs. */
 typedef uint8_t     jsbytecode;
 typedef uint8_t     jssrcnote;
 typedef uintptr_t   jsatomid;
 
 /* Struct typedefs. */
-typedef struct JSArgumentFormatMap  JSArgumentFormatMap;
 typedef struct JSGCThing            JSGCThing;
 typedef struct JSGenerator          JSGenerator;
 typedef struct JSNativeEnumerator   JSNativeEnumerator;
 typedef struct JSTryNote            JSTryNote;
 
 /* Friend "Advanced API" typedefs. */
 typedef struct JSAtomState          JSAtomState;
 typedef struct JSCodeSpec           JSCodeSpec;
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2125,139 +2125,16 @@ DumpObject(JSContext *cx, unsigned argc,
     js_DumpObject(arg0);
 
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
     return true;
 }
 
 #endif /* DEBUG */
 
-#ifdef TEST_CVTARGS
-#include <ctype.h>
-
-static const char *
-EscapeWideString(jschar *w)
-{
-    static char enuf[80];
-    static char hex[] = "0123456789abcdef";
-    jschar u;
-    unsigned char b, c;
-    int i, j;
-
-    if (!w)
-        return "";
-    for (i = j = 0; i < sizeof enuf - 1; i++, j++) {
-        u = w[j];
-        if (u == 0)
-            break;
-        b = (unsigned char)(u >> 8);
-        c = (unsigned char)(u);
-        if (b) {
-            if (i >= sizeof enuf - 6)
-                break;
-            enuf[i++] = '\\';
-            enuf[i++] = 'u';
-            enuf[i++] = hex[b >> 4];
-            enuf[i++] = hex[b & 15];
-            enuf[i++] = hex[c >> 4];
-            enuf[i] = hex[c & 15];
-        } else if (!isprint(c)) {
-            if (i >= sizeof enuf - 4)
-                break;
-            enuf[i++] = '\\';
-            enuf[i++] = 'x';
-            enuf[i++] = hex[c >> 4];
-            enuf[i] = hex[c & 15];
-        } else {
-            enuf[i] = (char)c;
-        }
-    }
-    enuf[i] = 0;
-    return enuf;
-}
-
-#include <stdarg.h>
-
-static JSBool
-ZZ_formatter(JSContext *cx, const char *format, bool fromJS, jsval **vpp,
-             va_list *app)
-{
-    jsval *vp;
-    va_list ap;
-    double re, im;
-
-    printf("entering ZZ_formatter");
-    vp = *vpp;
-    ap = *app;
-    if (fromJS) {
-        if (!JS_ValueToNumber(cx, vp[0], &re))
-            return false;
-        if (!JS_ValueToNumber(cx, vp[1], &im))
-            return false;
-        *va_arg(ap, double *) = re;
-        *va_arg(ap, double *) = im;
-    } else {
-        re = va_arg(ap, double);
-        im = va_arg(ap, double);
-        vp[0] = JS_NumberValue(re);
-        vp[1] = JS_NumberValue(im);
-    }
-    *vpp = vp + 2;
-    *app = ap;
-    printf("leaving ZZ_formatter");
-    return true;
-}
-
-static JSBool
-ConvertArgs(JSContext *cx, unsigned argc, jsval *vp)
-{
-    bool b = false;
-    jschar c = 0;
-    int32_t i = 0, j = 0;
-    uint32_t u = 0;
-    double d = 0, I = 0, re = 0, im = 0;
-    JSString *str = NULL;
-    jschar *w = NULL;
-    JSObject *obj2 = NULL;
-    JSFunction *fun = NULL;
-    jsval v = JSVAL_VOID;
-    bool ok;
-
-    if (!JS_AddArgumentFormatter(cx, "ZZ", ZZ_formatter))
-        return false;
-    ok = JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "b/ciujdISWofvZZ*",
-                             &b, &c, &i, &u, &j, &d, &I, &str, &w, &obj2,
-                             &fun, &v, &re, &im);
-    JS_RemoveArgumentFormatter(cx, "ZZ");
-    if (!ok)
-        return false;
-    fprintf(gOutFile,
-            "b %u, c %x (%c), i %ld, u %lu, j %ld\n",
-            b, c, (char)c, i, u, j);
-    ToStringHelper obj2string(cx, obj2);
-    ToStringHelper valueString(cx, v);
-    JSAutoByteString strBytes;
-    if (str)
-        strBytes.encode(cx, str);
-    JSString *tmpstr = JS_DecompileFunction(cx, fun, 4);
-    JSAutoByteString func;
-    if (!tmpstr || !func.encode(cx, tmpstr))
-        ReportException(cx);
-    fprintf(gOutFile,
-            "d %g, I %g, S %s, W %s, obj %s, fun %s\n"
-            "v %s, re %g, im %g\n",
-            d, I, !!strBytes ? strBytes.ptr() : "", EscapeWideString(w),
-            obj2string.getBytes(),
-            fun ? (!!func ? func.ptr() : "error decompiling fun") : "",
-            valueString.getBytes(), re, im);
-    JS_SET_RVAL(cx, vp, JSVAL_VOID);
-    return true;
-}
-#endif
-
 static JSBool
 BuildDate(JSContext *cx, unsigned argc, jsval *vp)
 {
     char version[20] = "\n";
 #if JS_VERSION < 150
     sprintf(version, " for version %d\n", JS_VERSION);
 #endif
     fprintf(gOutFile, "built on %s at %s%s", __DATE__, __TIME__, version);
@@ -3703,22 +3580,16 @@ static JSFunctionSpecWithHelp shell_func
 "  themselves from roots that keep |thing| from being collected. (We could make\n"
 "  this distinction if it is useful.)\n"
 "\n"
 "  If any references are found by the conservative scanner, the references\n"
 "  object will have a property named \"edge: machine stack\"; the referrers will\n"
 "  be 'null', because they are roots."),
 
 #endif
-#ifdef TEST_CVTARGS
-    JS_FN_HELP("cvtargs", ConvertArgs, 0, 0,
-"cvtargs(arg1..., arg12)",
-"  Test argument formatter."),
-
-#endif
     JS_FN_HELP("build", BuildDate, 0, 0,
 "build()",
 "  Show build date and time."),
 
     JS_FN_HELP("intern", Intern, 1, 0,
 "intern(str)",
 "  Internalize str in the atom table."),
 
--- a/js/xpconnect/src/XPCContext.cpp
+++ b/js/xpconnect/src/XPCContext.cpp
@@ -42,19 +42,16 @@ XPCContext::~XPCContext()
     // Iterate over our scopes and tell them that we have been destroyed
     for (PRCList *scopeptr = PR_NEXT_LINK(&mScopes);
          scopeptr != &mScopes;
          scopeptr = PR_NEXT_LINK(scopeptr)) {
         XPCWrappedNativeScope *scope =
             static_cast<XPCWrappedNativeScope*>(scopeptr);
         scope->ClearContext();
     }
-
-    // we do not call JS_RemoveArgumentFormatter because we now only
-    // delete XPCContext *after* the underlying JSContext is dead
 }
 
 void
 XPCContext::DebugDump(int16_t depth)
 {
 #ifdef DEBUG
     depth--;
     XPC_LOG_ALWAYS(("XPCContext @ %x", this));