1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/Array/pop-nonarray-higher-elements.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 909602; 1.11 +var summary = 1.12 + "Array.prototype.pop shouldn't touch elements greater than length on " + 1.13 + "non-arrays"; 1.14 + 1.15 +print(BUGNUMBER + ": " + summary); 1.16 + 1.17 +/************** 1.18 + * BEGIN TEST * 1.19 + **************/ 1.20 + 1.21 +function doTest(obj, index) 1.22 +{ 1.23 + // print("testing " + JSON.stringify(obj) + " with index " + index); 1.24 + assertEq(Array.prototype.pop.call(obj), undefined); 1.25 + assertEq(index in obj, true); 1.26 + assertEq(obj[index], 42); 1.27 +} 1.28 + 1.29 +// not-super-much-later element 1.30 + 1.31 +// non-zero length 1.32 +function testPop1() 1.33 +{ 1.34 + var obj = { length: 2, 3: 42 }; 1.35 + doTest(obj, 3); 1.36 +} 1.37 +for (var i = 0; i < 50; i++) 1.38 + testPop1(); 1.39 + 1.40 +// zero length 1.41 +function testPop2() 1.42 +{ 1.43 + var obj = { length: 0, 3: 42 }; 1.44 + doTest(obj, 3); 1.45 +} 1.46 +for (var i = 0; i < 50; i++) 1.47 + testPop2(); 1.48 + 1.49 +// much-later (but dense) element 1.50 + 1.51 +// non-zero length 1.52 +function testPop3() 1.53 +{ 1.54 + var obj = { length: 2, 55: 42 }; 1.55 + doTest(obj, 55); 1.56 +} 1.57 +for (var i = 0; i < 50; i++) 1.58 + testPop3(); 1.59 + 1.60 +// zero length 1.61 +function testPop4() 1.62 +{ 1.63 + var obj = { length: 0, 55: 42 }; 1.64 + doTest(obj, 55); 1.65 +} 1.66 +for (var i = 0; i < 50; i++) 1.67 + testPop4(); 1.68 + 1.69 +// much much much later (sparse) element 1.70 + 1.71 +// non-zero length 1.72 +function testPop5() 1.73 +{ 1.74 + var obj = { length: 2, 65530: 42 }; 1.75 + doTest(obj, 65530); 1.76 +} 1.77 +for (var i = 0; i < 50; i++) 1.78 + testPop5(); 1.79 + 1.80 +// zero length 1.81 +function testPop6() 1.82 +{ 1.83 + var obj = { length: 0, 65530: 42 }; 1.84 + doTest(obj, 65530); 1.85 +} 1.86 +for (var i = 0; i < 50; i++) 1.87 + testPop6(); 1.88 + 1.89 +/******************************************************************************/ 1.90 + 1.91 +if (typeof reportCompare === "function") 1.92 + reportCompare(true, true); 1.93 + 1.94 +print("Tests complete");