Bug 788359 - Remove unused argumentFormatMap and associated API; r=dmandelin

This removes some fiddly code sitting around completely unused and untested.

--HG--
rename : layout/base/tests/chrome/blue-32x32.png => layout/reftests/backgrounds/blue-32x32.png
rename : mobile/android/config/mozconfigs/android-noion/nightly => mobile/android/config/mozconfigs/android/nightly
extra : rebase_source : 68192aba59396a37242ee2aa266621dbea513171
This commit is contained in:
Terrence Cole 2012-09-04 17:17:21 -07:00
parent bd416a20af
commit ebe3bd6fcf
7 changed files with 2 additions and 287 deletions

View File

@ -224,23 +224,6 @@ JS_GetEmptyString(JSRuntime *rt)
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)
{
@ -389,65 +372,14 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for
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)
{

View File

@ -1944,14 +1944,6 @@ 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);
@ -2606,56 +2598,6 @@ 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);

View File

@ -1207,7 +1207,6 @@ JSContext::JSContext(JSRuntime *rt)
stack(thisDuringConstruction()),
parseMapPool_(NULL),
cycleDetectorSet(thisDuringConstruction()),
argumentFormatMap(NULL),
lastMessage(NULL),
errorReporter(NULL),
operationCallback(NULL),
@ -1250,14 +1249,6 @@ JSContext::~JSContext()
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);
}

View File

@ -1075,20 +1075,6 @@ struct JSRuntime : js::RuntimeFriendFields
#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;
@ -1318,9 +1304,6 @@ struct JSContext : js::ContextFriendFields
/* 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;

View File

@ -47,7 +47,6 @@ 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;

View File

@ -2130,129 +2130,6 @@ DumpObject(JSContext *cx, unsigned argc, jsval *vp)
#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)
{
@ -3707,12 +3584,6 @@ static JSFunctionSpecWithHelp shell_functions[] = {
" 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()",

View File

@ -47,9 +47,6 @@ XPCContext::~XPCContext()
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