regress-465980-02.js (3164B)
1 // |reftest| slow 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 //----------------------------------------------------------------------------- 8 var BUGNUMBER = 465980; 9 var summary = 'Do not crash @ InitArrayElements'; 10 var actual = ''; 11 var expect = ''; 12 13 14 //----------------------------------------------------------------------------- 15 test(); 16 //----------------------------------------------------------------------------- 17 18 function test() 19 { 20 printBugNumber(BUGNUMBER); 21 printStatus (summary); 22 23 function describe(name, startLength, pushArgs, expectThrow, expectLength) 24 { 25 return name + "(" + startLength + ", " + 26 "[" + pushArgs.join(", ") + "], " + 27 expectThrow + ", " + 28 expectLength + ")"; 29 } 30 31 var push = Array.prototype.push; 32 var unshift = Array.prototype.unshift; 33 34 function testArrayPush(startLength, pushArgs, expectThrow, expectLength) 35 { 36 print("running testArrayPush(" + 37 startLength + ", " + 38 "[" + pushArgs.join(", ") + "], " + 39 expectThrow + ", " + 40 expectLength + ")..."); 41 var a = new Array(startLength); 42 try 43 { 44 push.apply(a, pushArgs); 45 if (expectThrow) 46 { 47 throw "expected to throw for " + 48 describe("testArrayPush", startLength, pushArgs, expectThrow, 49 expectLength); 50 } 51 } 52 catch (e) 53 { 54 if (!(e instanceof RangeError)) 55 { 56 throw "unexpected exception type thrown: " + e + " for " + 57 describe("testArrayPush", startLength, pushArgs, expectThrow, 58 expectLength); 59 } 60 if (!expectThrow) 61 { 62 throw "unexpected exception " + e + " for " + 63 describe("testArrayPush", startLength, pushArgs, expectThrow, 64 expectLength); 65 } 66 } 67 68 if (a.length !== expectLength) 69 { 70 throw "unexpected modified-array length for " + 71 describe("testArrayPush", startLength, pushArgs, expectThrow, 72 expectLength); 73 } 74 75 for (var i = 0, sz = pushArgs.length; i < sz; i++) 76 { 77 var index = i + startLength; 78 if (a[index] !== pushArgs[i]) 79 { 80 throw "unexpected value " + a[index] + 81 " at index " + index + " (" + i + ") during " + 82 describe("testArrayPush", startLength, pushArgs, expectThrow, 83 expectLength) + ", expected " + pushArgs[i]; 84 } 85 } 86 } 87 88 var failed = true; 89 90 try 91 { 92 var foo = "foo", bar = "bar", baz = "baz"; 93 94 testArrayPush(4294967294, [foo], false, 4294967295); 95 testArrayPush(4294967294, [foo, bar], true, 4294967295); 96 testArrayPush(4294967294, [foo, bar, baz], true, 4294967295); 97 testArrayPush(4294967295, [foo], true, 4294967295); 98 testArrayPush(4294967295, [foo, bar], true, 4294967295); 99 testArrayPush(4294967295, [foo, bar, baz], true, 4294967295); 100 } 101 catch (e) 102 { 103 actual = e + ''; 104 } 105 106 reportCompare(expect, actual, summary); 107 }