js/src/tests/ecma_5/Array/pop-nonarray-higher-elements.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/licenses/publicdomain/
michael@0 4 */
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 var BUGNUMBER = 909602;
michael@0 8 var summary =
michael@0 9 "Array.prototype.pop shouldn't touch elements greater than length on " +
michael@0 10 "non-arrays";
michael@0 11
michael@0 12 print(BUGNUMBER + ": " + summary);
michael@0 13
michael@0 14 /**************
michael@0 15 * BEGIN TEST *
michael@0 16 **************/
michael@0 17
michael@0 18 function doTest(obj, index)
michael@0 19 {
michael@0 20 // print("testing " + JSON.stringify(obj) + " with index " + index);
michael@0 21 assertEq(Array.prototype.pop.call(obj), undefined);
michael@0 22 assertEq(index in obj, true);
michael@0 23 assertEq(obj[index], 42);
michael@0 24 }
michael@0 25
michael@0 26 // not-super-much-later element
michael@0 27
michael@0 28 // non-zero length
michael@0 29 function testPop1()
michael@0 30 {
michael@0 31 var obj = { length: 2, 3: 42 };
michael@0 32 doTest(obj, 3);
michael@0 33 }
michael@0 34 for (var i = 0; i < 50; i++)
michael@0 35 testPop1();
michael@0 36
michael@0 37 // zero length
michael@0 38 function testPop2()
michael@0 39 {
michael@0 40 var obj = { length: 0, 3: 42 };
michael@0 41 doTest(obj, 3);
michael@0 42 }
michael@0 43 for (var i = 0; i < 50; i++)
michael@0 44 testPop2();
michael@0 45
michael@0 46 // much-later (but dense) element
michael@0 47
michael@0 48 // non-zero length
michael@0 49 function testPop3()
michael@0 50 {
michael@0 51 var obj = { length: 2, 55: 42 };
michael@0 52 doTest(obj, 55);
michael@0 53 }
michael@0 54 for (var i = 0; i < 50; i++)
michael@0 55 testPop3();
michael@0 56
michael@0 57 // zero length
michael@0 58 function testPop4()
michael@0 59 {
michael@0 60 var obj = { length: 0, 55: 42 };
michael@0 61 doTest(obj, 55);
michael@0 62 }
michael@0 63 for (var i = 0; i < 50; i++)
michael@0 64 testPop4();
michael@0 65
michael@0 66 // much much much later (sparse) element
michael@0 67
michael@0 68 // non-zero length
michael@0 69 function testPop5()
michael@0 70 {
michael@0 71 var obj = { length: 2, 65530: 42 };
michael@0 72 doTest(obj, 65530);
michael@0 73 }
michael@0 74 for (var i = 0; i < 50; i++)
michael@0 75 testPop5();
michael@0 76
michael@0 77 // zero length
michael@0 78 function testPop6()
michael@0 79 {
michael@0 80 var obj = { length: 0, 65530: 42 };
michael@0 81 doTest(obj, 65530);
michael@0 82 }
michael@0 83 for (var i = 0; i < 50; i++)
michael@0 84 testPop6();
michael@0 85
michael@0 86 /******************************************************************************/
michael@0 87
michael@0 88 if (typeof reportCompare === "function")
michael@0 89 reportCompare(true, true);
michael@0 90
michael@0 91 print("Tests complete");

mercurial