michael@0: function testInt32() { michael@0: function f(arr, i) { michael@0: arr[0] = 1; michael@0: arr[1] = arr[0] + 1; michael@0: arr[2] = arr[1] + arr[0]; michael@0: var x = arr[2]; // 3 michael@0: arr[x] = arr[x-1] + 1; michael@0: arr[x+1] = arr[x] + i; michael@0: return arr[4]; michael@0: } michael@0: var a = [1, 2, 3, 4, 5, 6, 7, 8]; michael@0: for (var i=0; i<70; i++) { michael@0: assertEq(f(a, i), i + 4); michael@0: } michael@0: } michael@0: testInt32(); michael@0: michael@0: function testDouble() { michael@0: function f(arr, d) { michael@0: arr[0] = d; michael@0: for (var i=1; i<8; i++) { michael@0: arr[i] = arr[i-1] + d; michael@0: } michael@0: return arr[7]; michael@0: } michael@0: var a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]; michael@0: for (var i=0; i<50; i++) { michael@0: assertEq(f(a, Math.PI + i)|0, ((Math.PI + i) * 8)|0); michael@0: } michael@0: } michael@0: testDouble(); michael@0: michael@0: function testOutOfBounds() { michael@0: function f(arr, i, v) { michael@0: arr[i] = v; michael@0: } michael@0: var a = [1, 2]; michael@0: for (var i=0; i<90; i++) { michael@0: f(a, 1, i); michael@0: } michael@0: assertEq(a[1], 89); michael@0: michael@0: f(a, 2, 40); michael@0: f(a, 100, 50); michael@0: f(a, -1, 3); michael@0: michael@0: assertEq(a[2], 40); michael@0: assertEq(a[100], 50); michael@0: assertEq(a[-1], 3); michael@0: } michael@0: testOutOfBounds(); michael@0: michael@0: function testClassGuard() { michael@0: function f(arr, v) { michael@0: arr[1] = v; michael@0: } michael@0: var a = [1, 2, 3, 4]; michael@0: for (var i=0; i<90; i++) { michael@0: f(a, i); michael@0: } michael@0: assertEq(a[1], 89); michael@0: michael@0: var b = {}; michael@0: f(b, 100); michael@0: assertEq(b[1], 100); michael@0: } michael@0: testClassGuard(); michael@0: michael@0: function testMultipleTypes() { michael@0: function f(arr, v) { michael@0: arr[1] = v; michael@0: } michael@0: var a = [1, 2, 3, 4]; michael@0: var b = [1.1, -233.2, 3.3]; michael@0: michael@0: for (var i=0; i<90; i++) { michael@0: f(a, i); michael@0: } michael@0: assertEq(a[1], 89); michael@0: f(b, 20); michael@0: assertEq(b[1], 20); michael@0: } michael@0: testMultipleTypes(); michael@0: michael@0: function testNull() { michael@0: function f(arr) { michael@0: arr[0] = null; michael@0: } michael@0: michael@0: var arr = [undefined]; michael@0: for (var i=0; i<100; i++) { michael@0: f(arr); michael@0: } michael@0: assertEq(arr[0], null); michael@0: } michael@0: testNull(); michael@0: michael@0: // Bug 722245. michael@0: function testConstantGcThing() { michael@0: function f(arr, x) { michael@0: arr[x] = "abc"; michael@0: } michael@0: var arr = ["", ""]; michael@0: for (var i=0; i<100; i++) { michael@0: f(arr, 1); michael@0: } michael@0: assertEq(arr[1], "abc"); michael@0: } michael@0: testConstantGcThing();