Bug 580051 - Catch ints-as-doubles in JSOP_TABLESWITCH (r=jorendorff)

This commit is contained in:
Luke Wagner 2010-07-20 19:32:11 -07:00
parent 890c4cda11
commit 0fd878fe59
3 changed files with 20 additions and 4 deletions

View File

@ -4961,11 +4961,11 @@ BEGIN_CASE(JSOP_TABLESWITCH)
int32_t i;
if (rref.isInt32()) {
i = rref.toInt32();
} else if (rref.isDouble() && rref.toDouble() == 0) {
/* Treat -0 (double) as 0. */
i = 0;
} else {
DO_NEXT_OP(len);
double d;
/* Don't use JSDOUBLE_IS_INT32; treat -0 (double) as 0. */
if (!rref.isDouble() || (d = rref.toDouble()) != (i = int32_t(rref.toDouble())))
DO_NEXT_OP(len);
}
pc2 += JUMP_OFFSET_LEN;

View File

@ -0,0 +1,7 @@
var a = Math.sin(Math.PI/2); // spec does not specify precise answer here...
if (a === 1) { // ...but if a === 1 here...
switch (a) {
case 1: break; // ...then it must also match here
default: throw "FAIL";
}
}

View File

@ -0,0 +1,9 @@
var arr = Float32Array(1);
arr[0] = 15;
var a = arr[0];
assertEq(a, 15);
switch (a) {
case 15: break;
default: throw "FAIL";
}