michael@0: function test1() { michael@0: // splice GetElement calls are observable and should be executed even if michael@0: // the return value of splice is unused. michael@0: Object.defineProperty(Object.prototype, "0", {get: function() { michael@0: c++; michael@0: }, set: function() {}}); michael@0: var arr = [,,,]; michael@0: var c = 0; michael@0: for (var i=0; i<100; i++) { michael@0: arr.splice(0, 1); michael@0: arr.length = 1; michael@0: } michael@0: michael@0: assertEq(c, 100); michael@0: } michael@0: test1(); michael@0: michael@0: function test2() { michael@0: var arr = []; michael@0: for (var i=0; i<100; i++) michael@0: arr.push(i); michael@0: for (var i=0; i<40; i++) michael@0: arr.splice(0, 2); michael@0: assertEq(arr.length, 20); michael@0: assertEq(arr[0], 80); michael@0: } michael@0: test2(); michael@0: michael@0: function testNonArray() { michael@0: for (var i=0; i<10; i++) { michael@0: var o = {splice:[].splice, 0:"a", 1:"b", 2:"c", length:3}; michael@0: o.splice(0, 2); michael@0: assertEq(o.length, 1); michael@0: assertEq(o[0], "c"); michael@0: } michael@0: } michael@0: testNonArray();