diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/Array/regress-465980-02.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Array/regress-465980-02.js')
-rw-r--r-- | js/src/tests/non262/Array/regress-465980-02.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/js/src/tests/non262/Array/regress-465980-02.js b/js/src/tests/non262/Array/regress-465980-02.js new file mode 100644 index 0000000000..da86a5fe54 --- /dev/null +++ b/js/src/tests/non262/Array/regress-465980-02.js @@ -0,0 +1,107 @@ +// |reftest| slow +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 465980; +var summary = 'Do not crash @ InitArrayElements'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + printBugNumber(BUGNUMBER); + printStatus (summary); + + function describe(name, startLength, pushArgs, expectThrow, expectLength) + { + return name + "(" + startLength + ", " + + "[" + pushArgs.join(", ") + "], " + + expectThrow + ", " + + expectLength + ")"; + } + + var push = Array.prototype.push; + var unshift = Array.prototype.unshift; + + function testArrayPush(startLength, pushArgs, expectThrow, expectLength) + { + print("running testArrayPush(" + + startLength + ", " + + "[" + pushArgs.join(", ") + "], " + + expectThrow + ", " + + expectLength + ")..."); + var a = new Array(startLength); + try + { + push.apply(a, pushArgs); + if (expectThrow) + { + throw "expected to throw for " + + describe("testArrayPush", startLength, pushArgs, expectThrow, + expectLength); + } + } + catch (e) + { + if (!(e instanceof RangeError)) + { + throw "unexpected exception type thrown: " + e + " for " + + describe("testArrayPush", startLength, pushArgs, expectThrow, + expectLength); + } + if (!expectThrow) + { + throw "unexpected exception " + e + " for " + + describe("testArrayPush", startLength, pushArgs, expectThrow, + expectLength); + } + } + + if (a.length !== expectLength) + { + throw "unexpected modified-array length for " + + describe("testArrayPush", startLength, pushArgs, expectThrow, + expectLength); + } + + for (var i = 0, sz = pushArgs.length; i < sz; i++) + { + var index = i + startLength; + if (a[index] !== pushArgs[i]) + { + throw "unexpected value " + a[index] + + " at index " + index + " (" + i + ") during " + + describe("testArrayPush", startLength, pushArgs, expectThrow, + expectLength) + ", expected " + pushArgs[i]; + } + } + } + + var failed = true; + + try + { + var foo = "foo", bar = "bar", baz = "baz"; + + testArrayPush(4294967294, [foo], false, 4294967295); + testArrayPush(4294967294, [foo, bar], true, 4294967295); + testArrayPush(4294967294, [foo, bar, baz], true, 4294967295); + testArrayPush(4294967295, [foo], true, 4294967295); + testArrayPush(4294967295, [foo, bar], true, 4294967295); + testArrayPush(4294967295, [foo, bar, baz], true, 4294967295); + } + catch (e) + { + actual = e + ''; + } + + reportCompare(expect, actual, summary); +} |