Bug 933946 - Remove the rest of the old number conversion functions from SpiderMonkey. r=terrence

This commit is contained in:
Tom Schuster 2013-11-02 13:48:09 +01:00
Родитель 9d34d8815f
Коммит 822b70dad6
6 изменённых файлов: 20 добавлений и 119 удалений

Просмотреть файл

@ -228,17 +228,18 @@ DumpXPC(JSContext *cx,
unsigned argc,
JS::Value *vp)
{
int32_t depth = 2;
JS::CallArgs args = CallArgsFromVp(argc, vp);
if (argc > 0) {
if (!JS_ValueToInt32(cx, JS_ARGV(cx, vp)[0], &depth))
uint16_t depth = 2;
if (args.length() > 0) {
if (!JS::ToUint16(cx, args[0], &depth))
return false;
}
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
if(xpc)
if (xpc)
xpc->DebugDump(int16_t(depth));
JS_SET_RVAL(cx, vp, JSVAL_VOID);
args.rval().setUndefined();
return true;
}

Просмотреть файл

@ -773,13 +773,9 @@ OOMAfterAllocations(JSContext *cx, unsigned argc, jsval *vp)
return false;
}
int32_t count;
if (!JS_ValueToInt32(cx, args[0], &count))
uint32_t count;
if (!JS::ToUint32(cx, args[0], &count))
return false;
if (count <= 0) {
JS_ReportError(cx, "count argument must be positive");
return false;
}
OOM_maxAllocations = OOM_counter + count;
return true;

Просмотреть файл

@ -245,10 +245,11 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for
*va_arg(ap, bool *) = ToBoolean(*sp);
break;
case 'c':
if (!JS_ValueToUint16(cx, *sp, va_arg(ap, uint16_t *)))
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;
@ -256,10 +257,6 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for
if (!ToUint32(cx, arg, 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 (!ToNumber(cx, arg, va_arg(ap, double *)))
return false;
@ -447,58 +444,6 @@ JS_DoubleToUint32(double d)
return ToUint32(d);
}
JS_PUBLIC_API(bool)
JS_ValueToInt64(JSContext *cx, jsval valueArg, int64_t *ip)
{
RootedValue value(cx, valueArg);
return JS::ToInt64(cx, value, ip);
}
JS_PUBLIC_API(bool)
JS_ValueToUint64(JSContext *cx, jsval valueArg, uint64_t *ip)
{
RootedValue value(cx, valueArg);
return JS::ToUint64(cx, value, ip);
}
JS_PUBLIC_API(bool)
JS_ValueToInt32(JSContext *cx, jsval vArg, int32_t *ip)
{
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
RootedValue v(cx, vArg);
assertSameCompartment(cx, v);
if (v.isInt32()) {
*ip = v.toInt32();
return true;
}
double d;
if (v.isDouble()) {
d = v.toDouble();
} else if (!ToNumberSlow(cx, v, &d)) {
return false;
}
if (mozilla::IsNaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
js_ReportValueError(cx, JSMSG_CANT_CONVERT,
JSDVG_SEARCH_STACK, v, NullPtr());
return false;
}
*ip = (int32_t) floor(d + 0.5); /* Round to nearest */
return true;
}
JS_PUBLIC_API(bool)
JS_ValueToUint16(JSContext *cx, jsval valueArg, uint16_t *ip)
{
RootedValue value(cx, valueArg);
return ToUint16(cx, value, ip);
}
JS_PUBLIC_API(bool)
JS_ValueToBoolean(JSContext *cx, jsval value, bool *bp)
{

Просмотреть файл

@ -992,8 +992,8 @@ JS_GetEmptyString(JSRuntime *rt);
* b bool Boolean
* c uint16_t/jschar ECMA uint16_t, Unicode char
* i int32_t ECMA int32_t
* j int32_t ECMA int32_t (used to be different)
* u uint32_t ECMA uint32_t
* j int32_t Rounded int32_t (coordinate)
* d double IEEE double
* I double Integral IEEE double
* S JSString * Unicode string, accessed by a JSString pointer
@ -1107,30 +1107,17 @@ JS_DoubleToInt32(double d);
extern JS_PUBLIC_API(uint32_t)
JS_DoubleToUint32(double d);
/*
* Convert a value to a number, then to an int64_t, according to the WebIDL
* rules for ToInt64: http://dev.w3.org/2006/webapi/WebIDL/#es-long-long
*/
extern JS_PUBLIC_API(bool)
JS_ValueToInt64(JSContext *cx, jsval v, int64_t *ip);
/*
* Convert a value to a number, then to an uint64_t, according to the WebIDL
* rules for ToUint64: http://dev.w3.org/2006/webapi/WebIDL/#es-unsigned-long-long
*/
extern JS_PUBLIC_API(bool)
JS_ValueToUint64(JSContext *cx, jsval v, uint64_t *ip);
namespace js {
/* DO NOT CALL THIS. Use JS::ToInt16. */
/* DO NOT CALL THIS. Use JS::ToUint16. */
extern JS_PUBLIC_API(bool)
ToUint16Slow(JSContext *cx, JS::Handle<JS::Value> v, uint16_t *out);
/* DO NOT CALL THIS. Use JS::ToInt32. */
/* DO NOT CALL THIS. Use JS::ToInt32. */
extern JS_PUBLIC_API(bool)
ToInt32Slow(JSContext *cx, JS::Handle<JS::Value> v, int32_t *out);
/* DO NOT CALL THIS. Use JS::ToUint32. */
/* DO NOT CALL THIS. Use JS::ToUint32. */
extern JS_PUBLIC_API(bool)
ToUint32Slow(JSContext *cx, JS::Handle<JS::Value> v, uint32_t *out);
@ -1216,20 +1203,6 @@ ToUint64(JSContext *cx, JS::Handle<JS::Value> v, uint64_t *out)
} /* namespace JS */
/*
* Convert a value to a number, then to an int32_t if it fits by rounding to
* nearest; but failing with an error report if the double is out of range
* or unordered.
*/
extern JS_PUBLIC_API(bool)
JS_ValueToInt32(JSContext *cx, jsval v, int32_t *ip);
/*
* ECMA ToUint16, for mapping a jsval to a Unicode point.
*/
extern JS_PUBLIC_API(bool)
JS_ValueToUint16(JSContext *cx, jsval v, uint16_t *ip);
extern JS_PUBLIC_API(bool)
JS_ValueToBoolean(JSContext *cx, jsval v, bool *bp);

Просмотреть файл

@ -1526,7 +1526,7 @@ GetScriptAndPCArgs(JSContext *cx, unsigned argc, jsval *argv, MutableHandleScrip
intarg++;
}
if (argc > intarg) {
if (!JS_ValueToInt32(cx, argv[intarg], ip))
if (!JS::ToInt32(cx, HandleValue::fromMarkedLocation(&argv[intarg]), ip))
return false;
if ((uint32_t)*ip >= script->length) {
JS_ReportError(cx, "Invalid PC");
@ -2431,17 +2431,6 @@ GetSLX(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
static bool
ToInt32(JSContext *cx, unsigned argc, jsval *vp)
{
int32_t i;
if (!JS_ValueToInt32(cx, argc == 0 ? UndefinedValue() : vp[2], &i))
return false;
JS_SET_RVAL(cx, vp, JS_NumberValue(i));
return true;
}
static bool
ThrowError(JSContext *cx, unsigned argc, jsval *vp)
{
@ -4172,10 +4161,6 @@ static const JSFunctionSpecWithHelp shell_functions[] = {
"getslx(obj)",
" Get script line extent."),
JS_FN_HELP("toint32", ToInt32, 1, 0,
"toint32(n)",
" Testing hook for JS_ValueToInt32."),
JS_FN_HELP("evalcx", EvalInContext, 1, 0,
"evalcx(s[, o])",
" Evaluate s in optional sandbox object o.\n"

Просмотреть файл

@ -387,17 +387,18 @@ IgnoreReportedErrors(JSContext *cx, unsigned argc, jsval *vp)
static bool
DumpXPC(JSContext *cx, unsigned argc, jsval *vp)
{
int32_t depth = 2;
JS::CallArgs args = CallArgsFromVp(argc, vp);
if (argc > 0) {
if (!JS_ValueToInt32(cx, JS_ARGV(cx, vp)[0], &depth))
uint16_t depth = 2;
if (args.length() > 0) {
if (!JS::ToUint16(cx, args[0], &depth))
return false;
}
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID());
if (xpc)
xpc->DebugDump(int16_t(depth));
JS_SET_RVAL(cx, vp, JSVAL_VOID);
args.rval().setUndefined();
return true;
}