michael@0: // |reftest| skip -- slow michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 465980; michael@0: var summary = 'Do not crash @ InitArrayElements'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: function describe(name, startLength, pushArgs, expectThrow, expectLength) michael@0: { michael@0: return name + "(" + startLength + ", " + michael@0: "[" + pushArgs.join(", ") + "], " + michael@0: expectThrow + ", " + michael@0: expectLength + ")"; michael@0: } michael@0: michael@0: var push = Array.prototype.push; michael@0: var unshift = Array.prototype.unshift; michael@0: michael@0: function testArrayPush(startLength, pushArgs, expectThrow, expectLength) michael@0: { michael@0: print("running testArrayPush(" + michael@0: startLength + ", " + michael@0: "[" + pushArgs.join(", ") + "], " + michael@0: expectThrow + ", " + michael@0: expectLength + ")..."); michael@0: var a = new Array(startLength); michael@0: try michael@0: { michael@0: push.apply(a, pushArgs); michael@0: if (expectThrow) michael@0: { michael@0: throw "expected to throw for " + michael@0: describe("testArrayPush", startLength, pushArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: } michael@0: catch (e) michael@0: { michael@0: if (!(e instanceof RangeError)) michael@0: { michael@0: throw "unexpected exception type thrown: " + e + " for " + michael@0: describe("testArrayPush", startLength, pushArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: if (!expectThrow) michael@0: { michael@0: throw "unexpected exception " + e + " for " + michael@0: describe("testArrayPush", startLength, pushArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: } michael@0: michael@0: if (a.length !== expectLength) michael@0: { michael@0: throw "unexpected modified-array length for " + michael@0: describe("testArrayPush", startLength, pushArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: michael@0: for (var i = 0, sz = pushArgs.length; i < sz; i++) michael@0: { michael@0: var index = i + startLength; michael@0: if (a[index] !== pushArgs[i]) michael@0: { michael@0: throw "unexpected value " + a[index] + michael@0: " at index " + index + " (" + i + ") during " + michael@0: describe("testArrayPush", startLength, pushArgs, expectThrow, michael@0: expectLength) + ", expected " + pushArgs[i]; michael@0: } michael@0: } michael@0: } michael@0: michael@0: function testArrayUnshift(startLength, unshiftArgs, expectThrow, expectLength) michael@0: { michael@0: print("running testArrayUnshift(" + michael@0: startLength + ", " + michael@0: "[" + unshiftArgs.join(", ") + "], " + michael@0: expectThrow + ", " + michael@0: expectLength + ")..."); michael@0: var a = new Array(startLength); michael@0: try michael@0: { michael@0: unshift.apply(a, unshiftArgs); michael@0: if (expectThrow) michael@0: { michael@0: throw "expected to throw for " + michael@0: describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: } michael@0: catch (e) michael@0: { michael@0: if (!(e instanceof RangeError)) michael@0: { michael@0: throw "unexpected exception type thrown: " + e + " for " + michael@0: describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: if (!expectThrow) michael@0: { michael@0: throw "unexpected exception " + e + " for " + michael@0: describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: } michael@0: michael@0: if (a.length !== expectLength) michael@0: { michael@0: throw "unexpected modified-array length for " + michael@0: describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: michael@0: for (var i = 0, sz = unshiftArgs.length; i < sz; i++) michael@0: { michael@0: if (a[i] !== unshiftArgs[i]) michael@0: { michael@0: throw "unexpected value at index " + i + " during " + michael@0: describe("testArrayUnshift", startLength, unshiftArgs, expectThrow, michael@0: expectLength); michael@0: } michael@0: } michael@0: } michael@0: michael@0: var failed = true; michael@0: michael@0: try michael@0: { michael@0: var foo = "foo", bar = "bar", baz = "baz"; michael@0: michael@0: testArrayPush(4294967294, [foo], false, 4294967295); michael@0: testArrayPush(4294967294, [foo, bar], true, 4294967295); michael@0: testArrayPush(4294967294, [foo, bar, baz], true, 4294967295); michael@0: testArrayPush(4294967295, [foo], true, 4294967295); michael@0: testArrayPush(4294967295, [foo, bar], true, 4294967295); michael@0: testArrayPush(4294967295, [foo, bar, baz], true, 4294967295); michael@0: michael@0: testArrayUnshift(4294967294, [foo], false, 4294967295); michael@0: testArrayUnshift(4294967294, [foo, bar], true, 4294967294); michael@0: testArrayUnshift(4294967294, [foo, bar, baz], true, 4294967294); michael@0: testArrayUnshift(4294967295, [foo], true, 4294967295); michael@0: testArrayUnshift(4294967295, [foo, bar], true, 4294967295); michael@0: testArrayUnshift(4294967295, [foo, bar, baz], true, 4294967295); michael@0: michael@0: } michael@0: catch (e) michael@0: { michael@0: actual = e + ''; michael@0: } michael@0: michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: exitFunc ('test'); michael@0: }