Bug 707383 - Rename ValueTo{ECMA,}{Ui,I}nt32 so that To{Ui,I}nt32 is the ECMA spec method and NonstandardTo{Ui,I}nt32 is the non-standard JSAPI method functionality. r=luke

This commit is contained in:
Jeff Walden 2011-12-05 17:10:02 -05:00
parent f757943ac9
commit adf79ecc9c
14 changed files with 54 additions and 57 deletions

View File

@ -532,7 +532,7 @@ JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip)
assertSameCompartment(cx, v);
AutoValueRooter tvr(cx, v);
return ValueToECMAInt32(cx, tvr.value(), (int32_t *)ip);
return ToInt32(cx, tvr.value(), (int32_t *)ip);
}
JS_PUBLIC_API(JSBool)
@ -542,7 +542,7 @@ JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip)
assertSameCompartment(cx, v);
AutoValueRooter tvr(cx, v);
return ValueToECMAUint32(cx, tvr.value(), (uint32_t *)ip);
return ToUint32(cx, tvr.value(), (uint32_t *)ip);
}
JS_PUBLIC_API(JSBool)
@ -552,7 +552,7 @@ JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip)
assertSameCompartment(cx, v);
AutoValueRooter tvr(cx, v);
return ValueToInt32(cx, tvr.value(), (int32_t *)ip);
return NonstandardToInt32(cx, tvr.value(), (int32_t *)ip);
}
JS_PUBLIC_API(JSBool)

View File

@ -173,7 +173,7 @@ js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp)
}
JS_STATIC_ASSERT(sizeof(jsuint) == sizeof(uint32_t));
return ValueToECMAUint32(cx, tvr.value(), (uint32_t *)lengthp);
return ToUint32(cx, tvr.value(), (uint32_t *)lengthp);
}
namespace js {
@ -600,7 +600,7 @@ array_length_setter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value
}
uint32 newlen;
if (!ValueToECMAUint32(cx, *vp, &newlen))
if (!ToUint32(cx, *vp, &newlen))
return false;
jsdouble d;

View File

@ -762,7 +762,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
/* Set the 'lineNumber' property. */
uint32_t lineno;
if (args.length() > 2) {
if (!ValueToECMAUint32(cx, args[2], &lineno))
if (!ToUint32(cx, args[2], &lineno))
return false;
} else {
lineno = iter.done() ? 0 : js_FramePCToLineNumber(cx, iter.fp(), iter.pc());
@ -891,7 +891,7 @@ exn_toSource(JSContext *cx, uintN argc, Value *vp)
Value linenoVal;
uint32_t lineno;
if (!obj->getProperty(cx, cx->runtime->atomState.lineNumberAtom, &linenoVal) ||
!ValueToECMAUint32(cx, linenoVal, &lineno))
!ToUint32(cx, linenoVal, &lineno))
{
return false;
}
@ -1226,7 +1226,7 @@ js_ReportUncaughtException(JSContext *cx)
if (!JS_GetProperty(cx, exnObject, js_lineNumber_str, &roots[4]))
return false;
uint32_t lineno;
if (!ValueToECMAUint32(cx, roots[4], &lineno))
if (!ToUint32(cx, roots[4], &lineno))
return false;
reportp = &report;

View File

@ -1581,7 +1581,7 @@ fun_toString(JSContext *cx, uintN argc, Value *vp)
JS_ASSERT(IsFunctionObject(vp[0]));
uint32_t indent = 0;
if (argc != 0 && !ValueToECMAUint32(cx, vp[2], &indent))
if (argc != 0 && !ToUint32(cx, vp[2], &indent))
return false;
JSObject *obj = ToObject(cx, &vp[1]);

View File

@ -2456,9 +2456,9 @@ END_CASE(JSOP_BINDNAME)
#define BITWISE_OP(OP) \
JS_BEGIN_MACRO \
int32_t i, j; \
if (!ValueToECMAInt32(cx, regs.sp[-2], &i)) \
if (!ToInt32(cx, regs.sp[-2], &i)) \
goto error; \
if (!ValueToECMAInt32(cx, regs.sp[-1], &j)) \
if (!ToInt32(cx, regs.sp[-1], &j)) \
goto error; \
i = i OP j; \
regs.sp--; \
@ -2607,9 +2607,9 @@ END_CASE(JSOP_GE)
#define SIGNED_SHIFT_OP(OP) \
JS_BEGIN_MACRO \
int32_t i, j; \
if (!ValueToECMAInt32(cx, regs.sp[-2], &i)) \
if (!ToInt32(cx, regs.sp[-2], &i)) \
goto error; \
if (!ValueToECMAInt32(cx, regs.sp[-1], &j)) \
if (!ToInt32(cx, regs.sp[-1], &j)) \
goto error; \
i = i OP (j & 31); \
regs.sp--; \
@ -2629,10 +2629,10 @@ END_CASE(JSOP_RSH)
BEGIN_CASE(JSOP_URSH)
{
uint32_t u;
if (!ValueToECMAUint32(cx, regs.sp[-2], &u))
if (!ToUint32(cx, regs.sp[-2], &u))
goto error;
int32_t j;
if (!ValueToECMAInt32(cx, regs.sp[-1], &j))
if (!ToInt32(cx, regs.sp[-1], &j))
goto error;
u >>= (j & 31);
@ -2799,7 +2799,7 @@ END_CASE(JSOP_NOT)
BEGIN_CASE(JSOP_BITNOT)
{
int32_t i;
if (!ValueToECMAInt32(cx, regs.sp[-1], &i))
if (!ToInt32(cx, regs.sp[-1], &i))
goto error;
i = ~i;
regs.sp[-1].setInt32(i);

View File

@ -447,7 +447,7 @@ num_parseInt(JSContext *cx, uintN argc, Value *vp)
bool stripPrefix = true;
int32 radix = 0;
if (args.length() > 1) {
if (!ValueToECMAInt32(cx, args[1], &radix))
if (!ToInt32(cx, args[1], &radix))
return false;
if (radix != 0) {
if (radix < 2 || radix > 36) {
@ -1294,7 +1294,7 @@ ToNumberSlow(JSContext *cx, Value v, double *out)
}
bool
ValueToECMAInt32Slow(JSContext *cx, const Value &v, int32_t *out)
ToInt32Slow(JSContext *cx, const Value &v, int32_t *out)
{
JS_ASSERT(!v.isInt32());
jsdouble d;
@ -1309,7 +1309,7 @@ ValueToECMAInt32Slow(JSContext *cx, const Value &v, int32_t *out)
}
bool
ValueToECMAUint32Slow(JSContext *cx, const Value &v, uint32_t *out)
ToUint32Slow(JSContext *cx, const Value &v, uint32_t *out)
{
JS_ASSERT(!v.isInt32());
jsdouble d;
@ -1357,7 +1357,7 @@ js_DoubleToECMAUint32(jsdouble d)
namespace js {
bool
ValueToInt32Slow(JSContext *cx, const Value &v, int32_t *out)
NonstandardToInt32Slow(JSContext *cx, const Value &v, int32_t *out)
{
JS_ASSERT(!v.isInt32());
jsdouble d;

View File

@ -275,25 +275,25 @@ ToNumber(JSContext *cx, Value *vp)
* failure.
*/
JS_ALWAYS_INLINE bool
ValueToECMAInt32(JSContext *cx, const js::Value &v, int32_t *out)
ToInt32(JSContext *cx, const js::Value &v, int32_t *out)
{
if (v.isInt32()) {
*out = v.toInt32();
return true;
}
extern bool ValueToECMAInt32Slow(JSContext *, const js::Value &, int32_t *);
return ValueToECMAInt32Slow(cx, v, out);
extern bool ToInt32Slow(JSContext *cx, const js::Value &v, int32_t *ip);
return ToInt32Slow(cx, v, out);
}
JS_ALWAYS_INLINE bool
ValueToECMAUint32(JSContext *cx, const js::Value &v, uint32_t *out)
ToUint32(JSContext *cx, const js::Value &v, uint32_t *out)
{
if (v.isInt32()) {
*out = (uint32_t)v.toInt32();
return true;
}
extern bool ValueToECMAUint32Slow(JSContext *, const js::Value &, uint32_t *);
return ValueToECMAUint32Slow(cx, v, out);
extern bool ToUint32Slow(JSContext *cx, const js::Value &v, uint32_t *ip);
return ToUint32Slow(cx, v, out);
}
/*
@ -302,14 +302,14 @@ ValueToECMAUint32(JSContext *cx, const js::Value &v, uint32_t *out)
* side effect, *vp will be mutated to match *out.
*/
JS_ALWAYS_INLINE bool
ValueToInt32(JSContext *cx, const js::Value &v, int32_t *out)
NonstandardToInt32(JSContext *cx, const js::Value &v, int32_t *out)
{
if (v.isInt32()) {
*out = v.toInt32();
return true;
}
extern bool ValueToInt32Slow(JSContext *, const js::Value &, int32_t *);
return ValueToInt32Slow(cx, v, out);
extern bool NonstandardToInt32Slow(JSContext *cx, const js::Value &v, int32_t *ip);
return NonstandardToInt32Slow(cx, v, out);
}
/*

View File

@ -3201,7 +3201,7 @@ reflect_parse(JSContext *cx, uint32 argc, jsval *vp)
/* config.line */
if (!GetPropertyDefault(cx, config, ATOM_TO_JSID(cx->runtime->atomState.lineAtom),
Int32Value(1), &prop) ||
!ValueToECMAUint32(cx, prop, &lineno)) {
!ToUint32(cx, prop, &lineno)) {
return JS_FALSE;
}
}

View File

@ -147,7 +147,7 @@ JSBool
ArrayBuffer::class_constructor(JSContext *cx, uintN argc, Value *vp)
{
int32 nbytes = 0;
if (argc > 0 && !ValueToECMAInt32(cx, vp[2], &nbytes))
if (argc > 0 && !ToInt32(cx, vp[2], &nbytes))
return false;
JSObject *bufobj = create(cx, nbytes);
@ -1454,7 +1454,7 @@ class TypedArrayTemplate
int32_t length = -1;
if (argc > 1) {
if (!ValueToInt32(cx, argv[1], &byteOffset))
if (!NonstandardToInt32(cx, argv[1], &byteOffset))
return NULL;
if (byteOffset < 0) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
@ -1463,7 +1463,7 @@ class TypedArrayTemplate
}
if (argc > 2) {
if (!ValueToInt32(cx, argv[2], &length))
if (!NonstandardToInt32(cx, argv[2], &length))
return NULL;
if (length < 0) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
@ -1497,7 +1497,7 @@ class TypedArrayTemplate
int32_t length = int32(getLength(tarray));
if (args.length() > 0) {
if (!ValueToInt32(cx, args[0], &begin))
if (!NonstandardToInt32(cx, args[0], &begin))
return false;
if (begin < 0) {
begin += length;
@ -1508,7 +1508,7 @@ class TypedArrayTemplate
}
if (args.length() > 1) {
if (!ValueToInt32(cx, args[1], &end))
if (!NonstandardToInt32(cx, args[1], &end))
return false;
if (end < 0) {
end += length;
@ -1549,7 +1549,7 @@ class TypedArrayTemplate
int32_t off = 0;
if (args.length() > 1) {
if (!ValueToInt32(cx, args[1], &off))
if (!NonstandardToInt32(cx, args[1], &off))
return false;
if (off < 0 || uint32_t(off) > getLength(tarray)) {

View File

@ -2000,7 +2000,7 @@ mjit::Compiler::generateMethod()
FrameEntry *top = frame.peek(-1);
if (top->isConstant() && top->getValue().isPrimitive()) {
int32_t i;
JS_ALWAYS_TRUE(ValueToECMAInt32(cx, top->getValue(), &i));
JS_ALWAYS_TRUE(ToInt32(cx, top->getValue(), &i));
i = ~i;
frame.pop();
frame.push(Int32Value(i));

View File

@ -95,8 +95,8 @@ mjit::Compiler::tryBinaryConstantFold(JSContext *cx, FrameState &frame, JSOp op,
* is infallible.
*/
if (needInt) {
JS_ALWAYS_TRUE(ValueToECMAInt32(cx, L, &nL));
JS_ALWAYS_TRUE(ValueToECMAInt32(cx, R, &nR));
JS_ALWAYS_TRUE(ToInt32(cx, L, &nL));
JS_ALWAYS_TRUE(ToInt32(cx, R, &nR));
} else {
JS_ALWAYS_TRUE(ToNumber(cx, L, &dL));
JS_ALWAYS_TRUE(ToNumber(cx, R, &dR));

View File

@ -229,7 +229,7 @@ mjit::Compiler::jsop_bitop(JSOp op)
case JSOP_URSH:
{
uint32 unsignedL;
ValueToECMAUint32(cx, Int32Value(L), (uint32_t*)&unsignedL); /* Can't fail. */
ToUint32(cx, Int32Value(L), (uint32_t*)&unsignedL); /* Can't fail. */
Value v = NumberValue(uint32(unsignedL >> (R & 31)));
JS_ASSERT(v.isInt32());
frame.push(v);

View File

@ -91,7 +91,7 @@ class FrameEntry
void convertConstantDoubleToInt32(JSContext *cx) {
JS_ASSERT(isType(JSVAL_TYPE_DOUBLE) && isConstant());
int32 value;
ValueToECMAInt32(cx, getValue(), &value);
ToInt32(cx, getValue(), &value);
Value newValue = Int32Value(value);
setConstant(newValue);

View File

@ -565,10 +565,9 @@ stubs::BitOr(VMFrame &f)
{
int32_t i, j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-2], &i) ||
!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j)) {
if (!ToInt32(f.cx, f.regs.sp[-2], &i) || !ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
}
i = i | j;
f.regs.sp[-2].setInt32(i);
}
@ -578,10 +577,9 @@ stubs::BitXor(VMFrame &f)
{
int32_t i, j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-2], &i) ||
!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j)) {
if (!ToInt32(f.cx, f.regs.sp[-2], &i) || !ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
}
i = i ^ j;
f.regs.sp[-2].setInt32(i);
}
@ -591,10 +589,9 @@ stubs::BitAnd(VMFrame &f)
{
int32_t i, j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-2], &i) ||
!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j)) {
if (!ToInt32(f.cx, f.regs.sp[-2], &i) || !ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
}
i = i & j;
f.regs.sp[-2].setInt32(i);
}
@ -604,7 +601,7 @@ stubs::BitNot(VMFrame &f)
{
int32_t i;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-1], &i))
if (!ToInt32(f.cx, f.regs.sp[-1], &i))
THROW();
i = ~i;
f.regs.sp[-1].setInt32(i);
@ -614,9 +611,9 @@ void JS_FASTCALL
stubs::Lsh(VMFrame &f)
{
int32_t i, j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-2], &i))
if (!ToInt32(f.cx, f.regs.sp[-2], &i))
THROW();
if (!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j))
if (!ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
i = i << (j & 31);
f.regs.sp[-2].setInt32(i);
@ -626,9 +623,9 @@ void JS_FASTCALL
stubs::Rsh(VMFrame &f)
{
int32_t i, j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-2], &i))
if (!ToInt32(f.cx, f.regs.sp[-2], &i))
THROW();
if (!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j))
if (!ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
i = i >> (j & 31);
f.regs.sp[-2].setInt32(i);
@ -638,10 +635,10 @@ void JS_FASTCALL
stubs::Ursh(VMFrame &f)
{
uint32_t u;
if (!ValueToECMAUint32(f.cx, f.regs.sp[-2], &u))
if (!ToUint32(f.cx, f.regs.sp[-2], &u))
THROW();
int32_t j;
if (!ValueToECMAInt32(f.cx, f.regs.sp[-1], &j))
if (!ToInt32(f.cx, f.regs.sp[-1], &j))
THROW();
u >>= (j & 31);