michael@0: function f(arr) michael@0: { michael@0: assertEq(arr.shift(), 0); michael@0: } michael@0: michael@0: function test(out) michael@0: { michael@0: // Create an array of arrays, to be iterated over for [].shift-calling. We michael@0: // can't just loop on shift on a single array with non-writable length because michael@0: // shift throws when called on an array with non-writable length. michael@0: var arrs = out.arrs = []; michael@0: for (var i = 0; i < 100; i++) michael@0: arrs.push([0, 1, 2, 3]); michael@0: michael@0: // Use a much-greater capacity than the eventual non-writable length. michael@0: var a = [0, 1, 2, 3, 4, 5, 6, 7]; michael@0: Object.defineProperty(a, "length", { writable: false, value: 4 }); michael@0: michael@0: arrs.push(a); michael@0: michael@0: for (var i = 0, sz = arrs.length; i < sz; i++) michael@0: { michael@0: var arr = arrs[i]; michael@0: f(arr); michael@0: } michael@0: } michael@0: michael@0: var obj = {}; michael@0: var a, arrs; michael@0: michael@0: try michael@0: { michael@0: test(obj); michael@0: throw new Error("didn't throw!"); michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); michael@0: michael@0: arrs = obj.arrs; michael@0: assertEq(arrs.length, 101); michael@0: for (var i = 0; i < 100; i++) michael@0: { michael@0: assertEq(arrs[i].length, 3, "unexpected length for arrs[" + i + "]"); michael@0: assertEq(arrs[i][0], 1, "bad element for arrs[" + i + "][0]"); michael@0: assertEq(arrs[i][1], 2, "bad element for arrs[" + i + "][1]"); michael@0: assertEq(arrs[i][2], 3, "bad element for arrs[" + i + "][2]"); michael@0: assertEq(3 in arrs[i], false, "shouldn't be a third element"); michael@0: assertEq(arrs[i][3], undefined); michael@0: } michael@0: michael@0: a = arrs[100]; michael@0: assertEq(a[0], 1, "bad element for a[" + i + "]"); michael@0: assertEq(a[1], 2, "bad element for a[" + i + "]"); michael@0: assertEq(a[2], 3, "bad element for a[" + i + "]"); michael@0: assertEq(a.hasOwnProperty(3), false, "should have been deleted before throw"); michael@0: assertEq(a[3], undefined); michael@0: assertEq(a.length, 4, "length shouldn't have been changed"); michael@0: }