Don't crash when expecting an int32 as double box in unbox but getting something else (and better debug output).

This commit is contained in:
Andreas Gal 2008-07-10 21:23:32 -07:00
parent 90c5b152e7
commit b6707f6c19
2 changed files with 12 additions and 4 deletions

View File

@ -600,10 +600,12 @@ unbox_jsval(jsval v, uint8 t, double* slot)
jsint i;
if (JSVAL_IS_INT(v))
*(jsint*)slot = JSVAL_TO_INT(v);
else if (JSDOUBLE_IS_INT(*JSVAL_TO_DOUBLE(v), i))
else if (JSVAL_IS_DOUBLE(v) && JSDOUBLE_IS_INT(*JSVAL_TO_DOUBLE(v), i))
*(jsint*)slot = i;
else
else {
verbose_only(printf("int != tag%d ", JSVAL_TAG(v));)
return false;
}
verbose_only(printf("int<%d> ", i);)
return true;
}
@ -613,14 +615,18 @@ unbox_jsval(jsval v, uint8 t, double* slot)
d = JSVAL_TO_INT(v);
else if (JSVAL_IS_DOUBLE(v))
d = *JSVAL_TO_DOUBLE(v);
else
else {
verbose_only(printf("double != tag%d ", JSVAL_TAG(v));)
return false;
}
*(jsdouble*)slot = d;
verbose_only(printf("double<%g> ", d);)
return true;
}
if (JSVAL_TAG(v) != type)
if (JSVAL_TAG(v) != type) {
verbose_only(printf("%d != tag%d ", type, JSVAL_TAG(v));)
return false;
}
switch (JSVAL_TAG(v)) {
case JSVAL_BOOLEAN:
*(bool*)slot = JSVAL_TO_BOOLEAN(v);

View File

@ -65,6 +65,7 @@ function getelem(a)
}
test("getelem", getelem(a), 3486);
/*
globalName = 907;
function name()
{
@ -83,6 +84,7 @@ test("get undeclared global at top level", globalInt, globalName + 499);
for (var i = 0; i < 500; i++)
globalInt = i;
test("setting global variable", globalInt, 499);
*/
function arith()
{