valueToInt32.js (754B)
1 // vim: set ts=8 sts=4 et sw=4 tw=99: 2 3 function f(x, y) { 4 // Confuse the type analysis to not know the type of x. 5 var u; 6 var a = x + u; 7 var b = x + 3; 8 return x + y; 9 } 10 11 function g_bool(x, y) { 12 var t; 13 if (x + 0) 14 t = true; 15 else 16 t = false; 17 return t + y; 18 19 } 20 function g_null(x) { 21 return null + x; 22 } 23 24 assertEq(g_bool(1, 2), 3); 25 assertEq(g_bool(0, 2), 2); 26 assertEq(g_null(2), 2); 27 28 // These will not bailout. 29 assertEq(f(Math.cos(Math.PI), 2), 1); 30 assertEq(f(null, 2), 2); 31 assertEq(f(false, 2), 2); 32 assertEq(f(true, 2), 3); 33 assertEq(f(17, 2), 19); 34 35 // These will bailout. 36 assertEq(f(undefined, 2), Number.NaN); 37 assertEq(f("20", 2), "202"); 38 assertEq(f(16.3, 2), 18.3); 39 assertEq((1 / f(-0, -0)), -Infinity);