michael@0: // IM has the following fastpaths: michael@0: // - constant index (constant) michael@0: // - need negative int check (neg) michael@0: // - needs hole check (hole) michael@0: // So to test everything we have to do: michael@0: // constant | neg | hole michael@0: // test 1: 0 0 0 michael@0: // test 2: 1 0 0 michael@0: // test 3: 0 1 0 michael@0: // test 4: 1 1 0 michael@0: // test 5: 0 0 1 michael@0: // test 6: 1 0 1 michael@0: // test 7: 0 1 1 michael@0: // test 8: 1 1 1 michael@0: michael@0: function test1(index, a) { michael@0: if (index < 0) michael@0: index = -index michael@0: return index in a; michael@0: } michael@0: assertEq(test1(1, [1,2]), true); michael@0: michael@0: function test2(a) { michael@0: return 0 in a; michael@0: } michael@0: assertEq(test2([1,2]), true); michael@0: michael@0: function test3(index, a) { michael@0: return index in a; michael@0: } michael@0: michael@0: var arr3 = []; michael@0: arr3["-1073741828"] = 17; michael@0: assertEq(test3(-1073741828, arr3), true); michael@0: michael@0: function test4(a) { michael@0: return -1073741828 in a; michael@0: } michael@0: assertEq(test4(arr3), true); michael@0: michael@0: michael@0: function test5(index, a) { michael@0: if (index < 0) michael@0: index = -index michael@0: return index in a; michael@0: } michael@0: var arr5 = []; michael@0: arr5[0] = 1 michael@0: arr5[1] = 1 michael@0: arr5[2] = 1 michael@0: arr5[4] = 1 michael@0: assertEq(test5(1, arr5), true); michael@0: assertEq(test5(3, arr5), false); michael@0: michael@0: function test7a(a) { michael@0: return 3 in a; michael@0: } michael@0: function test7b(a) { michael@0: return 4 in a; michael@0: } michael@0: assertEq(test7a(arr5), false); michael@0: assertEq(test7b(arr5), true); michael@0: michael@0: function test8(index, a) { michael@0: return index in a; michael@0: } michael@0: arr5["-1073741828"] = 17; michael@0: assertEq(test8(-1073741828, arr5), true); michael@0: assertEq(test8(3, arr5), false); michael@0: assertEq(test8(0, arr5), true); michael@0: michael@0: function test9a(a) { michael@0: return 0 in a; michael@0: } michael@0: function test9b(a) { michael@0: return 3 in a; michael@0: } michael@0: function test9c(a) { michael@0: return -1073741828 in a; michael@0: } michael@0: assertEq(test9a(arr5), true); michael@0: assertEq(test9b(arr5), false); michael@0: assertEq(test9c(arr5), true);