summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_5/Array
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/js1_5/Array
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/js1_5/Array')
-rw-r--r--js/src/tests/js1_5/Array/11.1.4.js68
-rw-r--r--js/src/tests/js1_5/Array/array-001.js88
-rw-r--r--js/src/tests/js1_5/Array/browser.js0
-rw-r--r--js/src/tests/js1_5/Array/regress-101964.js86
-rw-r--r--js/src/tests/js1_5/Array/regress-107138.js177
-rw-r--r--js/src/tests/js1_5/Array/regress-108440.js77
-rw-r--r--js/src/tests/js1_5/Array/regress-154338.js90
-rw-r--r--js/src/tests/js1_5/Array/regress-157652.js122
-rw-r--r--js/src/tests/js1_5/Array/regress-178722.js130
-rw-r--r--js/src/tests/js1_5/Array/regress-255555.js32
-rw-r--r--js/src/tests/js1_5/Array/regress-299644.js27
-rw-r--r--js/src/tests/js1_5/Array/regress-300858.js21
-rw-r--r--js/src/tests/js1_5/Array/regress-310351.js54
-rw-r--r--js/src/tests/js1_5/Array/regress-311515.js20
-rw-r--r--js/src/tests/js1_5/Array/regress-313153.js18
-rw-r--r--js/src/tests/js1_5/Array/regress-315509-01.js28
-rw-r--r--js/src/tests/js1_5/Array/regress-330812.js33
-rw-r--r--js/src/tests/js1_5/Array/regress-345961.js36
-rw-r--r--js/src/tests/js1_5/Array/regress-348810.js28
-rw-r--r--js/src/tests/js1_5/Array/regress-350256-01.js45
-rw-r--r--js/src/tests/js1_5/Array/regress-350256-02.js47
-rw-r--r--js/src/tests/js1_5/Array/regress-360681-01.js33
-rw-r--r--js/src/tests/js1_5/Array/regress-360681-02.js58
-rw-r--r--js/src/tests/js1_5/Array/regress-364104.js74
-rw-r--r--js/src/tests/js1_5/Array/regress-422286.js34
-rw-r--r--js/src/tests/js1_5/Array/regress-424954.js30
-rw-r--r--js/src/tests/js1_5/Array/regress-451483.js31
-rw-r--r--js/src/tests/js1_5/Array/regress-451906.js30
-rw-r--r--js/src/tests/js1_5/Array/regress-456845.js51
-rw-r--r--js/src/tests/js1_5/Array/regress-465980-01.js35
-rwxr-xr-xjs/src/tests/js1_5/Array/regress-465980-02.js170
-rw-r--r--js/src/tests/js1_5/Array/regress-474529.js55
-rw-r--r--js/src/tests/js1_5/Array/regress-94257.js86
-rw-r--r--js/src/tests/js1_5/Array/shell.js0
34 files changed, 1914 insertions, 0 deletions
diff --git a/js/src/tests/js1_5/Array/11.1.4.js b/js/src/tests/js1_5/Array/11.1.4.js
new file mode 100644
index 000000000..7f39c9305
--- /dev/null
+++ b/js/src/tests/js1_5/Array/11.1.4.js
@@ -0,0 +1,68 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 260106;
+var summary = 'Elisons in Array literals should not be enumed';
+var actual = '';
+var expect = '';
+var status;
+var prop;
+var array;
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+status = summary + ' ' + inSection(1) + ' [,1] ';
+array = [,1];
+actual = '';
+expect = '1';
+for (prop in array)
+{
+ if (prop != 'length')
+ {
+ actual += prop;
+ }
+}
+reportCompare(expect, actual, status);
+
+status = summary + ' ' + inSection(2) + ' [,,1] ';
+array = [,,1];
+actual = '';
+expect = '2';
+for (prop in array)
+{
+ if (prop != 'length')
+ {
+ actual += prop;
+ }
+}
+reportCompare(expect, actual, status);
+
+status = summary + ' ' + inSection(3) + ' [1,] ';
+array = [1,];
+actual = '';
+expect = '0';
+for (prop in array)
+{
+ if (prop != 'length')
+ {
+ actual += prop;
+ }
+}
+reportCompare(expect, actual, status);
+
+status = summary + ' ' + inSection(4) + ' [1,,] ';
+array = [1,,];
+actual = '';
+expect = '0';
+for (prop in array)
+{
+ if (prop != 'length')
+ {
+ actual += prop;
+ }
+}
+reportCompare(expect, actual, status);
diff --git a/js/src/tests/js1_5/Array/array-001.js b/js/src/tests/js1_5/Array/array-001.js
new file mode 100644
index 000000000..26e1ae256
--- /dev/null
+++ b/js/src/tests/js1_5/Array/array-001.js
@@ -0,0 +1,88 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+/*
+ * Date: 24 September 2001
+ *
+ * SUMMARY: Truncating arrays that have decimal property names.
+ * From correspondence with Igor Bukanov <igor@icesoft.no>:
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var BUGNUMBER = '(none)';
+var summary = 'Truncating arrays that have decimal property names';
+var BIG_INDEX = 4294967290;
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+
+
+var arr = Array(BIG_INDEX);
+arr[BIG_INDEX - 1] = 'a';
+arr[BIG_INDEX - 10000] = 'b';
+arr[BIG_INDEX - 0.5] = 'c'; // not an array index - but a valid property name
+// Truncate the array -
+arr.length = BIG_INDEX - 5000;
+
+
+// Enumerate its properties with for..in
+var s = '';
+for (var i in arr)
+{
+ s += arr[i];
+}
+
+
+/*
+ * We expect s == 'cb' or 'bc' (EcmaScript does not fix the order).
+ * Note 'c' is included: for..in includes ALL enumerable properties,
+ * not just array-index properties. The bug was: Rhino gave s == ''.
+ */
+status = inSection(1);
+actual = sortThis(s);
+expect = 'bc';
+addThis();
+
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function sortThis(str)
+{
+ var chars = str.split('');
+ chars = chars.sort();
+ return chars.join('');
+}
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = actual;
+ expectedvalues[UBound] = expect;
+ UBound++;
+}
+
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/browser.js b/js/src/tests/js1_5/Array/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_5/Array/browser.js
diff --git a/js/src/tests/js1_5/Array/regress-101964.js b/js/src/tests/js1_5/Array/regress-101964.js
new file mode 100644
index 000000000..ae3adb72d
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-101964.js
@@ -0,0 +1,86 @@
+// |reftest| random -- bogus perf test (bug 467263)
+/* -*- 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/.
+
+/*
+ * Date: 27 September 2001
+ *
+ * SUMMARY: Performance: truncating even very large arrays should be fast!
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=101964
+ *
+ * Adjust this testcase if necessary. The FAST constant defines
+ * an upper bound in milliseconds for any truncation to take.
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var BUGNUMBER = 101964;
+var summary = 'Performance: truncating even very large arrays should be fast!';
+var BIG = 10000000;
+var LITTLE = 10;
+var FAST = 50; // array truncation should be 50 ms or less to pass the test
+var MSG_FAST = 'Truncation took less than ' + FAST + ' ms';
+var MSG_SLOW = 'Truncation took ';
+var MSG_MS = ' ms';
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+
+
+
+status = inSection(1);
+var arr = Array(BIG);
+var start = new Date();
+arr.length = LITTLE;
+actual = elapsedTime(start);
+expect = FAST;
+addThis();
+
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function elapsedTime(startTime)
+{
+ return new Date() - startTime;
+}
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = isThisFast(actual);
+ expectedvalues[UBound] = isThisFast(expect);
+ UBound++;
+}
+
+
+function isThisFast(ms)
+{
+ if (ms <= FAST)
+ return MSG_FAST;
+ return MSG_SLOW + ms + MSG_MS;
+}
+
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-107138.js b/js/src/tests/js1_5/Array/regress-107138.js
new file mode 100644
index 000000000..ff865b550
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-107138.js
@@ -0,0 +1,177 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+/*
+ * Date: 29 October 2001
+ *
+ * SUMMARY: Regression test for bug 107138
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=107138
+ *
+ * The bug: arr['1'] == undefined instead of arr['1'] == 'one'.
+ * The bug was intermittent and did not always occur...
+ *
+ * The cnSTRESS constant defines how many times to repeat this test.
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var cnSTRESS = 10;
+var cnDASH = '-';
+var BUGNUMBER = 107138;
+var summary = 'Regression test for bug 107138';
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+
+
+var arr = ['zero', 'one', 'two', 'three', 'four', 'five',
+ 'six', 'seven', 'eight', 'nine', 'ten'];
+
+
+// This bug was intermittent. Stress-test it.
+for (var j=0; j<cnSTRESS; j++)
+{
+ status = inSection(j + cnDASH + 1);
+ actual = arr[0];
+ expect = 'zero';
+ addThis();
+
+ status = inSection(j + cnDASH + 2);
+ actual = arr['0'];
+ expect = 'zero';
+ addThis();
+
+ status = inSection(j + cnDASH + 3);
+ actual = arr[1];
+ expect = 'one';
+ addThis();
+
+ status = inSection(j + cnDASH + 4);
+ actual = arr['1'];
+ expect = 'one';
+ addThis();
+
+ status = inSection(j + cnDASH + 5);
+ actual = arr[2];
+ expect = 'two';
+ addThis();
+
+ status = inSection(j + cnDASH + 6);
+ actual = arr['2'];
+ expect = 'two';
+ addThis();
+
+ status = inSection(j + cnDASH + 7);
+ actual = arr[3];
+ expect = 'three';
+ addThis();
+
+ status = inSection(j + cnDASH + 8);
+ actual = arr['3'];
+ expect = 'three';
+ addThis();
+
+ status = inSection(j + cnDASH + 9);
+ actual = arr[4];
+ expect = 'four';
+ addThis();
+
+ status = inSection(j + cnDASH + 10);
+ actual = arr['4'];
+ expect = 'four';
+ addThis();
+
+ status = inSection(j + cnDASH + 11);
+ actual = arr[5];
+ expect = 'five';
+ addThis();
+
+ status = inSection(j + cnDASH + 12);
+ actual = arr['5'];
+ expect = 'five';
+ addThis();
+
+ status = inSection(j + cnDASH + 13);
+ actual = arr[6];
+ expect = 'six';
+ addThis();
+
+ status = inSection(j + cnDASH + 14);
+ actual = arr['6'];
+ expect = 'six';
+ addThis();
+
+ status = inSection(j + cnDASH + 15);
+ actual = arr[7];
+ expect = 'seven';
+ addThis();
+
+ status = inSection(j + cnDASH + 16);
+ actual = arr['7'];
+ expect = 'seven';
+ addThis();
+
+ status = inSection(j + cnDASH + 17);
+ actual = arr[8];
+ expect = 'eight';
+ addThis();
+
+ status = inSection(j + cnDASH + 18);
+ actual = arr['8'];
+ expect = 'eight';
+ addThis();
+
+ status = inSection(j + cnDASH + 19);
+ actual = arr[9];
+ expect = 'nine';
+ addThis();
+
+ status = inSection(j + cnDASH + 20);
+ actual = arr['9'];
+ expect = 'nine';
+ addThis();
+
+ status = inSection(j + cnDASH + 21);
+ actual = arr[10];
+ expect = 'ten';
+ addThis();
+
+ status = inSection(j + cnDASH + 22);
+ actual = arr['10'];
+ expect = 'ten';
+ addThis();
+}
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = actual;
+ expectedvalues[UBound] = expect;
+ UBound++;
+}
+
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-108440.js b/js/src/tests/js1_5/Array/regress-108440.js
new file mode 100644
index 000000000..d83c4164a
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-108440.js
@@ -0,0 +1,77 @@
+// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
+/* -*- 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/. */
+
+/*
+ *
+ * Date: 30 October 2001
+ * SUMMARY: Regression test for bug 108440
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=108440
+ *
+ * We shouldn't crash trying to add an array as an element of itself (!)
+ *
+ * Brendan: "...it appears that Array.prototype.toString is unsafe,
+ * and what's more, ECMA-262 Edition 3 has no helpful words about
+ * avoiding recursive death on a cycle."
+ */
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 108440;
+var summary = "Shouldn't crash trying to add an array as an element of itself";
+var self = this;
+var temp = '';
+
+printBugNumber(BUGNUMBER);
+printStatus(summary);
+
+/*
+ * Explicit test:
+ */
+var a=[];
+temp = (a[a.length]=a);
+
+/*
+ * Implicit test (one of the properties of |self| is |a|)
+ */
+a=[];
+for(var prop in self)
+{
+ temp = prop;
+ temp = (a[a.length] = self[prop]);
+}
+
+/*
+ * Stressful explicit test
+ */
+a=[];
+for (var i=0; i<10; i++)
+{
+ a[a.length] = a;
+}
+
+/*
+ * Test toString()
+ */
+a=[];
+for (var i=0; i<10; i++)
+{
+ a[a.length] = a.toString();
+}
+
+/*
+ * Test toSource() - but Rhino doesn't have this, so try...catch it
+ */
+a=[];
+try
+{
+ for (var i=0; i<10; i++)
+ {
+ a[a.length] = a.toSource();
+ }
+}
+catch(e)
+{
+}
+
+reportCompare('No Crash', 'No Crash', '');
diff --git a/js/src/tests/js1_5/Array/regress-154338.js b/js/src/tests/js1_5/Array/regress-154338.js
new file mode 100644
index 000000000..73b8a7f4b
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-154338.js
@@ -0,0 +1,90 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+/*
+ *
+ * Date: 26 June 2002
+ * SUMMARY: Testing array.join() when separator is a variable, not a literal
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=154338
+ *
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var BUGNUMBER = 154338;
+var summary = 'Test array.join() when separator is a variable, not a literal';
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+
+
+/*
+ * Note that x === 'H' and y === 'ome'.
+ *
+ * Yet for some reason, using |x| or |y| as the separator
+ * in arr.join() was causing out-of-memory errors, whereas
+ * using the literals 'H', 'ome' was not -
+ *
+ */
+var x = 'Home'[0];
+var y = ('Home'.split('H'))[1];
+
+
+status = inSection(1);
+var arr = Array('a', 'b');
+actual = arr.join('H');
+expect = 'aHb';
+addThis();
+
+status = inSection(2);
+arr = Array('a', 'b');
+actual = arr.join(x);
+expect = 'aHb';
+addThis();
+
+status = inSection(3);
+arr = Array('a', 'b');
+actual = arr.join('ome');
+expect = 'aomeb';
+addThis();
+
+status = inSection(4);
+arr = Array('a', 'b');
+actual = arr.join(y);
+expect = 'aomeb';
+addThis();
+
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = actual;
+ expectedvalues[UBound] = expect;
+ UBound++;
+}
+
+
+function test()
+{
+ enterFunc('test');
+ printBugNumber(BUGNUMBER);
+ printStatus(summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-157652.js b/js/src/tests/js1_5/Array/regress-157652.js
new file mode 100644
index 000000000..9d77802ca
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-157652.js
@@ -0,0 +1,122 @@
+// |reftest| skip-if(xulRuntime.XPCOMABI.match(/x86_64|aarch64|ppc64|ppc64le|s390x/)||Android) -- No test results
+/* -*- 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/. */
+
+/*
+ *
+ * Date: 16 July 2002
+ * SUMMARY: Testing that Array.sort() doesn't crash on very large arrays
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=157652
+ *
+ * How large can a JavaScript array be?
+ * ECMA-262 Ed.3 Final, Section 15.4.2.2 : new Array(len)
+ *
+ * This states that |len| must be a a uint32_t (unsigned 32-bit integer).
+ * Note the UBound for uint32's is 2^32 -1 = 0xFFFFFFFF = 4,294,967,295.
+ *
+ * Check:
+ * js> var arr = new Array(0xFFFFFFFF)
+ * js> arr.length
+ * 4294967295
+ *
+ * js> var arr = new Array(0x100000000)
+ * RangeError: invalid array length
+ *
+ *
+ * We'll try the largest possible array first, then a couple others.
+ * We're just testing that we don't crash on Array.sort().
+ *
+ * Try to be good about memory by nulling each array variable after it is
+ * used. This will tell the garbage collector the memory is no longer needed.
+ *
+ * As of 2002-08-13, the JS shell runs out of memory no matter what we do,
+ * when trying to sort such large arrays.
+ *
+ * We only want to test that we don't CRASH on the sort. So it will be OK
+ * if we get the JS "out of memory" error. Note this terminates the test
+ * with exit code 3. Therefore we put
+ *
+ * |expectExitCode(3);|
+ *
+ * The only problem will arise if the JS shell ever DOES have enough memory
+ * to do the sort. Then this test will terminate with the normal exit code 0
+ * and fail.
+ *
+ * Right now, I can't see any other way to do this, because "out of memory"
+ * is not a catchable error: it cannot be trapped with try...catch.
+ *
+ *
+ * FURTHER HEADACHE: Rhino can't seem to handle the largest array: it hangs.
+ * So we skip this case in Rhino. Here is correspondence with Igor Bukanov.
+ * He explains that Rhino isn't actually hanging; it's doing the huge sort:
+ *
+ * Philip Schwartau wrote:
+ *
+ * > Hi,
+ * >
+ * > I'm getting a graceful OOM message on trying to sort certain large
+ * > arrays. But if the array is too big, Rhino simply hangs. Note that ECMA
+ * > allows array lengths to be anything less than Math.pow(2,32), so the
+ * > arrays I'm sorting are legal.
+ * >
+ * > Note below, I'm getting an instantaneous OOM error on arr.sort() for LEN
+ * > = Math.pow(2, 30). So shouldn't I also get one for every LEN between
+ * > that and Math.pow(2, 32)? For some reason, I start to hang with 100% CPU
+ * > as LEN hits, say, Math.pow(2, 31) and higher. SpiderMonkey gives OOM
+ * > messages for all of these. Should I file a bug on this?
+ *
+ * Igor Bukanov wrote:
+ *
+ * This is due to different sorting algorithm Rhino uses when sorting
+ * arrays with length > Integer.MAX_VALUE. If length can fit Java int,
+ * Rhino first copies internal spare array to a temporary buffer, and then
+ * sorts it, otherwise it sorts array directly. In case of very spare
+ * arrays, that Array(big_number) generates, it is rather inefficient and
+ * generates OutOfMemory if length fits int. It may be worth in your case
+ * to optimize sorting to take into account array spareness, but then it
+ * would be a good idea to file a bug about ineficient sorting of spare
+ * arrays both in case of Rhino and SpiderMonkey as SM always uses a
+ * temporary buffer.
+ *
+ */
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 157652;
+var summary = "Testing that Array.sort() doesn't crash on very large arrays";
+var expect = 'No Crash';
+var actual = 'No Crash';
+
+printBugNumber(BUGNUMBER);
+printStatus(summary);
+
+expectExitCode(0);
+expectExitCode(5);
+
+var IN_RHINO = inRhino();
+
+try
+{
+ if (!IN_RHINO)
+ {
+ var a1=Array(0xFFFFFFFF);
+ a1.sort();
+ a1 = null;
+ }
+
+ var a2 = Array(0x40000000);
+ a2.sort();
+ a2=null;
+
+ var a3=Array(0x10000000/4);
+ a3.sort();
+ a3=null;
+}
+catch(ex)
+{
+ // handle changed 1.9 branch behavior. see bug 422348
+ expect = 'InternalError: allocation size overflow';
+ actual = ex + '';
+}
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-178722.js b/js/src/tests/js1_5/Array/regress-178722.js
new file mode 100644
index 000000000..950b1e759
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-178722.js
@@ -0,0 +1,130 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+/*
+ *
+ * Date: 06 November 2002
+ * SUMMARY: arr.sort() should not output |undefined| when |arr| is empty
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=178722
+ *
+ * ECMA-262 Ed.3: 15.4.4.11 Array.prototype.sort (comparefn)
+ *
+ * 1. Call the [[Get]] method of this object with argument "length".
+ * 2. Call ToUint32(Result(1)).
+ * 3. Perform an implementation-dependent sequence of calls to the [[Get]],
+ * [[Put]], and [[Delete]] methods of this object, etc. etc.
+ * 4. Return this object.
+ *
+ *
+ * Note that sort() is done in-place on |arr|. In other words, sort() is a
+ * "destructive" method rather than a "functional" method. The return value
+ * of |arr.sort()| and |arr| are the same object.
+ *
+ * If |arr| is an empty array, the return value of |arr.sort()| should be
+ * an empty array, not the value |undefined| as was occurring in bug 178722.
+ *
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var BUGNUMBER = 178722;
+var summary = 'arr.sort() should not output |undefined| when |arr| is empty';
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+var arr;
+
+
+// create empty array or pseudo-array objects in various ways
+var arr1 = Array();
+var arr2 = new Array();
+var arr3 = [];
+var arr4 = [1];
+arr4.pop();
+
+
+status = inSection(1);
+arr = arr1.sort();
+actual = arr instanceof Array && arr.length === 0 && arr === arr1;
+expect = true;
+addThis();
+
+status = inSection(2);
+arr = arr2.sort();
+actual = arr instanceof Array && arr.length === 0 && arr === arr2;
+expect = true;
+addThis();
+
+status = inSection(3);
+arr = arr3.sort();
+actual = arr instanceof Array && arr.length === 0 && arr === arr3;
+expect = true;
+addThis();
+
+status = inSection(4);
+arr = arr4.sort();
+actual = arr instanceof Array && arr.length === 0 && arr === arr4;
+expect = true;
+addThis();
+
+// now do the same thing, with non-default sorting:
+function g() {return 1;}
+
+status = inSection('1a');
+arr = arr1.sort(g);
+actual = arr instanceof Array && arr.length === 0 && arr === arr1;
+expect = true;
+addThis();
+
+status = inSection('2a');
+arr = arr2.sort(g);
+actual = arr instanceof Array && arr.length === 0 && arr === arr2;
+expect = true;
+addThis();
+
+status = inSection('3a');
+arr = arr3.sort(g);
+actual = arr instanceof Array && arr.length === 0 && arr === arr3;
+expect = true;
+addThis();
+
+status = inSection('4a');
+arr = arr4.sort(g);
+actual = arr instanceof Array && arr.length === 0 && arr === arr4;
+expect = true;
+addThis();
+
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = actual;
+ expectedvalues[UBound] = expect;
+ UBound++;
+}
+
+
+function test()
+{
+ enterFunc('test');
+ printBugNumber(BUGNUMBER);
+ printStatus(summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-255555.js b/js/src/tests/js1_5/Array/regress-255555.js
new file mode 100644
index 000000000..e4b2814b2
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-255555.js
@@ -0,0 +1,32 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 255555;
+var summary = 'Array.prototype.sort(comparefn) never passes undefined to comparefn';
+var actual = 'not undefined';
+var expect = 'not undefined';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+function comparefn(a,b)
+{
+ if (typeof a == 'undefined')
+ {
+ actual = 'undefined';
+ return 1;
+ }
+ if (typeof b == 'undefined')
+ {
+ actual = 'undefined';
+ return -1;
+ }
+ return a - b;
+}
+
+var arry = [ 1, 2, undefined ].sort(comparefn)
+
+ reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-299644.js b/js/src/tests/js1_5/Array/regress-299644.js
new file mode 100644
index 000000000..6a19cf54b
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-299644.js
@@ -0,0 +1,27 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 299644;
+var summary = 'Arrays with holes';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+actual = (new Array(10).concat()).length;
+expect = 10;
+reportCompare(expect, actual, '(new Array(10).concat()).length == 10');
+
+var a = new Array(10);
+actual = true;
+expect = true;
+for (var p in a)
+{
+ actual = false;
+ break;
+}
+reportCompare(expect, actual, 'Array holes are not enumerable');
diff --git a/js/src/tests/js1_5/Array/regress-300858.js b/js/src/tests/js1_5/Array/regress-300858.js
new file mode 100644
index 000000000..278937557
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-300858.js
@@ -0,0 +1,21 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 300858;
+var summary = 'Do not crash when sorting array with holes';
+var actual = 'No Crash';
+var expect = 'No Crash';
+
+var arry = [];
+arry[6] = 'six';
+arry[8] = 'eight';
+arry[9] = 'nine';
+arry[13] = 'thirteen';
+arry[14] = 'fourteen';
+arry[21] = 'twentyone';
+arry.sort();
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-310351.js b/js/src/tests/js1_5/Array/regress-310351.js
new file mode 100644
index 000000000..40401c536
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-310351.js
@@ -0,0 +1,54 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 310351;
+var summary = 'Convert host "list" objects to arrays';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+var nodeList = [];
+if (typeof document != 'undefined')
+{
+ nodeList = document.getElementsByTagName('*');
+}
+else
+{
+ printStatus('test using dummy array since no document available');
+}
+
+var array = Array.prototype.slice.call(nodeList, 0);
+
+expect = 'Array';
+actual = array.constructor.name;
+
+// nodeList is live and may change
+var saveLength = nodeList.length;
+
+reportCompare(expect, actual, summary + ': constructor test');
+
+expect = saveLength;
+actual = array.length;
+
+reportCompare(expect, actual, summary + ': length test');
+expect = true;
+actual = true;
+
+for (var i = 0; i < saveLength; i++)
+{
+ if (array[i] != nodeList[i])
+ {
+ actual = false;
+ summary += ' Comparison failed: array[' + i + ']=' + array[i] +
+ ', nodeList[' + i + ']=' + nodeList[i];
+ break;
+ }
+}
+
+reportCompare(expect, actual, summary + ': identical elements test');
+
diff --git a/js/src/tests/js1_5/Array/regress-311515.js b/js/src/tests/js1_5/Array/regress-311515.js
new file mode 100644
index 000000000..c6d4928ce
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-311515.js
@@ -0,0 +1,20 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 311515;
+var summary = 'Array.sort should skip holes and undefined during sort';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+var a = [, 1, , 2, undefined];
+
+actual = a.sort().toString();
+expect = '1,2,,,';
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-313153.js b/js/src/tests/js1_5/Array/regress-313153.js
new file mode 100644
index 000000000..e6c9c979c
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-313153.js
@@ -0,0 +1,18 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 313153;
+var summary = 'generic native method dispatcher extra actual arguments';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+expect = '1,2,3';
+actual = (function (){return Array.concat.apply([], arguments)})(1,2,3).toString();
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-315509-01.js b/js/src/tests/js1_5/Array/regress-315509-01.js
new file mode 100644
index 000000000..7d29c5946
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-315509-01.js
@@ -0,0 +1,28 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 315509;
+var summary = 'Array.prototype.unshift on Arrays with holes';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+var a = [0,1,2,3,4];
+delete a[1];
+
+expect = '0,,2,3,4';
+actual = a.toString();
+
+reportCompare(expect, actual, summary);
+
+a.unshift('a','b');
+
+expect = 'a,b,0,,2,3,4';
+actual = a.toString();
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-330812.js b/js/src/tests/js1_5/Array/regress-330812.js
new file mode 100644
index 000000000..c48f4c886
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-330812.js
@@ -0,0 +1,33 @@
+// |reftest| skip-if(xulRuntime.XPCOMABI.match(/x86_64|aarch64|ppc64|ppc64le|s390x/)||Android) -- No test results
+/* -*- 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 = 330812;
+var summary = 'Making Array(1<<29).sort() less problematic';
+var actual = 'No Crash';
+var expect = 'No Crash';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+
+expectExitCode(0);
+expectExitCode(3);
+
+printStatus('This test passes if the browser does not hang or crash');
+printStatus('This test expects exit code 0 or 3 to indicate out of memory');
+
+try
+{
+ var result = Array(1 << 29).sort();
+}
+catch(ex)
+{
+ // handle changed 1.9 branch behavior. see bug 422348
+ expect = 'InternalError: allocation size overflow';
+ actual = ex + '';
+}
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-345961.js b/js/src/tests/js1_5/Array/regress-345961.js
new file mode 100644
index 000000000..8c2e03c20
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-345961.js
@@ -0,0 +1,36 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 345961;
+var summary = 'Array.prototype.shift should preserve holes';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ expect = false;
+
+ var array = new Array(2);
+ array.shift();
+ actual = array.hasOwnProperty(0);
+ reportCompare(expect, actual, summary);
+
+ array=Array(1);
+ array.shift(1);
+ actual = array.hasOwnProperty(1);
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-348810.js b/js/src/tests/js1_5/Array/regress-348810.js
new file mode 100644
index 000000000..d5bd2070d
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-348810.js
@@ -0,0 +1,28 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 348810;
+var summary = 'Do not crash when sorting an array of holes';
+var actual = 'No Crash';
+var expect = 'No Crash';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ var a = Array(1);
+ a.sort();
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-350256-01.js b/js/src/tests/js1_5/Array/regress-350256-01.js
new file mode 100644
index 000000000..5f68522f9
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-350256-01.js
@@ -0,0 +1,45 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 350256;
+var summary = 'Array.apply maximum arguments';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test(Math.pow(2, 16));
+//-----------------------------------------------------------------------------
+
+function test(length)
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+
+ var a = new Array();
+ a[length - 2] = 'length-2';
+ a[length - 1] = 'length-1';
+
+ var b = Array.apply(null, a);
+
+ expect = length + ',length-2,length-1';
+ actual = b.length + "," + b[length - 2] + "," + b[length - 1];
+ reportCompare(expect, actual, summary);
+
+ function f() {
+ return arguments.length + "," + arguments[length - 2] + "," +
+ arguments[length - 1];
+ }
+
+ expect = length + ',length-2,length-1';
+ actual = f.apply(null, a);
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-350256-02.js b/js/src/tests/js1_5/Array/regress-350256-02.js
new file mode 100644
index 000000000..81472faa9
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-350256-02.js
@@ -0,0 +1,47 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 350256;
+var summary = 'Array.apply maximum arguments';
+var actual = '';
+var expect = '';
+
+printBugNumber(BUGNUMBER);
+printStatus (summary);
+reportCompare(true, true, "");
+
+//-----------------------------------------------------------------------------
+if (this.getMaxArgs)
+ test(getMaxArgs());
+
+//-----------------------------------------------------------------------------
+
+function test(length)
+{
+ enterFunc ('test');
+
+ var a = new Array();
+ a[length - 2] = 'length-2';
+ a[length - 1] = 'length-1';
+
+ var b = Array.apply(null, a);
+
+ expect = length + ',length-2,length-1';
+ actual = b.length + "," + b[length - 2] + "," + b[length - 1];
+ reportCompare(expect, actual, summary);
+
+ function f() {
+ return arguments.length + "," + arguments[length - 2] + "," +
+ arguments[length - 1];
+ }
+
+ expect = length + ',length-2,length-1';
+ actual = f.apply(null, a);
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-360681-01.js b/js/src/tests/js1_5/Array/regress-360681-01.js
new file mode 100644
index 000000000..ac22e45b4
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-360681-01.js
@@ -0,0 +1,33 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 360681;
+var summary = 'Regression from bug 224128';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ expect = actual = 'No Crash';
+
+ var a = Array(3);
+ a[0] = 1;
+ a[1] = 2;
+ a.sort(function () { gc(); return 1; });
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-360681-02.js b/js/src/tests/js1_5/Array/regress-360681-02.js
new file mode 100644
index 000000000..4ff9ac9cc
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-360681-02.js
@@ -0,0 +1,58 @@
+/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 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 = 360681;
+var summary = 'Regression from bug 224128';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ expect = actual = 'No Crash';
+
+ var N = 1000;
+
+// Make an array with a hole at the end
+ var a = Array(N);
+ for (i = 0; i < N - 1; ++i)
+ a[i] = 1;
+
+// array_sort due for array with N elements with allocates a temporary vector
+// with 2*N. Lets create strings that on 32 and 64 bit CPU cause allocation
+// of the same amount of memory + 1 word for their char arrays. After we GC
+// strings with a reasonable malloc implementation that memory will be most
+// likely reused in array_sort for the temporary vector. Then the bug causes
+// accessing the one-beyond-the-aloocation word and re-interpretation of
+// 0xFFF0FFF0 as GC thing.
+
+ var str1 = Array(2*(2*N + 1) + 1).join(String.fromCharCode(0xFFF0));
+ var str2 = Array(4*(2*N + 1) + 1).join(String.fromCharCode(0xFFF0));
+ gc();
+ str1 = str2 = null;
+ gc();
+
+ var firstCall = true;
+ a.sort(function (a, b) {
+ if (firstCall) {
+ firstCall = false;
+ gc();
+ }
+ return a - b;
+ });
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-364104.js b/js/src/tests/js1_5/Array/regress-364104.js
new file mode 100644
index 000000000..05d8953b6
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-364104.js
@@ -0,0 +1,74 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = "364104";
+var summary = "Array.prototype.indexOf, Array.prototype.lastIndexOf issues " +
+ "with the optional second fromIndex argument";
+var actual, expect;
+
+printBugNumber(BUGNUMBER);
+printStatus(summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+var failed = false;
+
+try
+{
+ // indexOf
+ if ([2].indexOf(2) != 0)
+ throw "indexOf: not finding 2!?";
+ if ([2].indexOf(2, 0) != 0)
+ throw "indexOf: not interpreting explicit second argument 0!";
+ if ([2].indexOf(2, 1) != -1)
+ throw "indexOf: ignoring second argument with value equal to array length!";
+ if ([2].indexOf(2, 2) != -1)
+ throw "indexOf: ignoring second argument greater than array length!";
+ if ([2].indexOf(2, 17) != -1)
+ throw "indexOf: ignoring large second argument!";
+ if ([2].indexOf(2, -5) != 0)
+ throw "indexOf: calculated fromIndex < 0, should search entire array!";
+ if ([2, 3].indexOf(2, -1) != -1)
+ throw "indexOf: not handling index == (-1 + 2), element 2 correctly!";
+ if ([2, 3].indexOf(3, -1) != 1)
+ throw "indexOf: not handling index == (-1 + 2), element 3 correctly!";
+
+ // lastIndexOf
+ if ([2].lastIndexOf(2) != 0)
+ throw "lastIndexOf: not finding 2!?";
+ if ([2].lastIndexOf(2, 1) != 0)
+ throw "lastIndexOf: not interpreting explicit second argument 1!?";
+ if ([2].lastIndexOf(2, 17) != 0)
+ throw "lastIndexOf: should have searched entire array!";
+ if ([2].lastIndexOf(2, -5) != -1)
+ throw "lastIndexOf: -5 + 1 < 0, so array shouldn't be searched!";
+ if ([2].lastIndexOf(2, -2) != -1)
+ throw "lastIndexOf: -2 + 1 < 0, so array shouldn't be searched!";
+ if ([2, 3].lastIndexOf(2, -1) != 0)
+ throw "lastIndexOf: not handling index == (-1 + 2), element 2 correctly!";
+ if ([2, 3].lastIndexOf(3, -1) != 1)
+ throw "lastIndexOf: not handling index == (-1 + 2), element 3 correctly!";
+ if ([2, 3].lastIndexOf(2, -2) != 0)
+ throw "lastIndexOf: not handling index == (-2 + 2), element 2 correctly!";
+ if ([2, 3].lastIndexOf(3, -2) != -1)
+ throw "lastIndexOf: not handling index == (-2 + 2), element 3 correctly!";
+ if ([2, 3].lastIndexOf(2, -3) != -1)
+ throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 2!";
+ if ([2, 3].lastIndexOf(3, -3) != -1)
+ throw "lastIndexOf: calculated fromIndex < 0, shouldn't search array for 3!";
+}
+catch (e)
+{
+ failed = e;
+}
+
+
+expect = false;
+actual = failed;
+
+reportCompare(expect, actual, summary);
diff --git a/js/src/tests/js1_5/Array/regress-422286.js b/js/src/tests/js1_5/Array/regress-422286.js
new file mode 100644
index 000000000..afd18cbe1
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-422286.js
@@ -0,0 +1,34 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 422286;
+var summary = 'Array slice when array\'s length is assigned';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ Array(10000).slice(1);
+ a = Array(1);
+ a.length = 10000;
+ a.slice(1);
+ a = Array(1);
+ a.length = 10000;
+ a.slice(-1);
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-424954.js b/js/src/tests/js1_5/Array/regress-424954.js
new file mode 100644
index 000000000..fa7b59cc5
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-424954.js
@@ -0,0 +1,30 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ * Contributor: Bob Clary
+ */
+
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 424954;
+var summary = 'Do not crash with [].concat(null)';
+var actual = 'No Crash';
+var expect = 'No Crash';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ [].concat(null);
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-451483.js b/js/src/tests/js1_5/Array/regress-451483.js
new file mode 100644
index 000000000..662f31292
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-451483.js
@@ -0,0 +1,31 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 451483;
+var summary = '[].splice.call(0) == []';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ expect = true;
+ var result = [].splice.call(0);
+ print('[].splice.call(0) = ' + result);
+ actual = result instanceof Array && result.length == 0;
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-451906.js b/js/src/tests/js1_5/Array/regress-451906.js
new file mode 100644
index 000000000..64d65692f
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-451906.js
@@ -0,0 +1,30 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 451906;
+var summary = 'Index array by numeric string';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ expect = 1;
+ var s=[1,2,3];
+ actual = s['0'];
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-456845.js b/js/src/tests/js1_5/Array/regress-456845.js
new file mode 100644
index 000000000..dc34935f5
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-456845.js
@@ -0,0 +1,51 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 456845;
+var summary = 'JIT: popArrs[a].pop is not a function';
+var actual = 'No Error';
+var expect = 'No Error';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+
+ try
+ {
+ var chars = '0123456789abcdef';
+ var size = 1000;
+ var mult = 100;
+
+ var arr = [];
+ var lsize = size;
+ while (lsize--) { arr.push(chars); }
+
+ var popArrs = [];
+ for (var i=0; i<mult; i++) { popArrs.push(arr.slice()); }
+
+
+ for(var a=0;a<mult;a++) {
+ var x; while (x = popArrs[a].pop()) { }
+ }
+
+ }
+ catch(ex)
+ {
+ actual = ex + '';
+ }
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-465980-01.js b/js/src/tests/js1_5/Array/regress-465980-01.js
new file mode 100644
index 000000000..fd36febd4
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-465980-01.js
@@ -0,0 +1,35 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ try
+ {
+ var a = new Array(4294967294);
+ a.push("foo", "bar");
+ }
+ catch(ex)
+ {
+ }
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-465980-02.js b/js/src/tests/js1_5/Array/regress-465980-02.js
new file mode 100755
index 000000000..08bab06d4
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-465980-02.js
@@ -0,0 +1,170 @@
+// |reftest| skip -- 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()
+{
+ enterFunc ('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];
+ }
+ }
+ }
+
+ function testArrayUnshift(startLength, unshiftArgs, expectThrow, expectLength)
+ {
+ print("running testArrayUnshift(" +
+ startLength + ", " +
+ "[" + unshiftArgs.join(", ") + "], " +
+ expectThrow + ", " +
+ expectLength + ")...");
+ var a = new Array(startLength);
+ try
+ {
+ unshift.apply(a, unshiftArgs);
+ if (expectThrow)
+ {
+ throw "expected to throw for " +
+ describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
+ expectLength);
+ }
+ }
+ catch (e)
+ {
+ if (!(e instanceof RangeError))
+ {
+ throw "unexpected exception type thrown: " + e + " for " +
+ describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
+ expectLength);
+ }
+ if (!expectThrow)
+ {
+ throw "unexpected exception " + e + " for " +
+ describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
+ expectLength);
+ }
+ }
+
+ if (a.length !== expectLength)
+ {
+ throw "unexpected modified-array length for " +
+ describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
+ expectLength);
+ }
+
+ for (var i = 0, sz = unshiftArgs.length; i < sz; i++)
+ {
+ if (a[i] !== unshiftArgs[i])
+ {
+ throw "unexpected value at index " + i + " during " +
+ describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
+ expectLength);
+ }
+ }
+ }
+
+ 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);
+
+ testArrayUnshift(4294967294, [foo], false, 4294967295);
+ testArrayUnshift(4294967294, [foo, bar], true, 4294967294);
+ testArrayUnshift(4294967294, [foo, bar, baz], true, 4294967294);
+ testArrayUnshift(4294967295, [foo], true, 4294967295);
+ testArrayUnshift(4294967295, [foo, bar], true, 4294967295);
+ testArrayUnshift(4294967295, [foo, bar, baz], true, 4294967295);
+
+ }
+ catch (e)
+ {
+ actual = e + '';
+ }
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-474529.js b/js/src/tests/js1_5/Array/regress-474529.js
new file mode 100644
index 000000000..ee2cb21c1
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-474529.js
@@ -0,0 +1,55 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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 = 474529;
+var summary = 'Do not assert: _buf->_nextPage';
+var actual = '';
+var expect = '';
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ function main() {
+
+ function timeit(N, buildArrayString) {
+ return Function("N",
+ "var d1 = +new Date;" +
+ "while (N--) var x = " + buildArrayString +
+ "; return +new Date - d1")(N);
+ }
+
+ function reportResults(size, N, literalMs, newArrayMs, arrayMs) {
+ print(Array.join(arguments, "\t"));
+ }
+
+ var repetitions = [ 9000, 7000, 4000, 2000, 2000, 2000, 800, 800, 800, 300, 100, 100 ]
+ for (var zeros = "0, ", i = 0; i < repetitions.length; ++i) {
+ var N = repetitions[i];
+ reportResults((1 << i) + 1, N,
+ timeit(N, "[" + zeros + " 0 ]"),
+ timeit(N, "new Array(" + zeros + " 0)"),
+ timeit(N, "Array(" + zeros + " 0)"));
+ zeros += zeros;
+ }
+ }
+
+ gc();
+ print("Size\t\Rep.\t\Literal\tnew Arr\tArray()");
+ print("====\t=====\t=======\t=======\t=======");
+ main();
+
+ reportCompare(expect, actual, summary);
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/regress-94257.js b/js/src/tests/js1_5/Array/regress-94257.js
new file mode 100644
index 000000000..ab95dd3ef
--- /dev/null
+++ b/js/src/tests/js1_5/Array/regress-94257.js
@@ -0,0 +1,86 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+/*
+ * Date: 30 October 2001
+ *
+ * SUMMARY: Regression test for bug 94257
+ * See http://bugzilla.mozilla.org/show_bug.cgi?id=94257
+ *
+ * Rhino used to crash on this code; specifically, on the line
+ *
+ * arr[1+1] += 2;
+ */
+//-----------------------------------------------------------------------------
+var UBound = 0;
+var BUGNUMBER = 94257;
+var summary = "Making sure we don't crash on this code -";
+var status = '';
+var statusitems = [];
+var actual = '';
+var actualvalues = [];
+var expect= '';
+var expectedvalues = [];
+
+
+var arr = new Array(6);
+arr[1+1] = 1;
+arr[1+1] += 2;
+
+
+status = inSection(1);
+actual = arr[1+1];
+expect = 3;
+addThis();
+
+status = inSection(2);
+actual = arr[1+1+1];
+expect = undefined;
+addThis();
+
+status = inSection(3);
+actual = arr[1];
+expect = undefined;
+addThis();
+
+
+arr[1+2] = 'Hello';
+
+
+status = inSection(4);
+actual = arr[1+1+1];
+expect = 'Hello';
+addThis();
+
+
+
+//-----------------------------------------------------------------------------
+test();
+//-----------------------------------------------------------------------------
+
+
+
+function addThis()
+{
+ statusitems[UBound] = status;
+ actualvalues[UBound] = actual;
+ expectedvalues[UBound] = expect;
+ UBound++;
+}
+
+
+function test()
+{
+ enterFunc ('test');
+ printBugNumber(BUGNUMBER);
+ printStatus (summary);
+
+ for (var i=0; i<UBound; i++)
+ {
+ reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
+ }
+
+ exitFunc ('test');
+}
diff --git a/js/src/tests/js1_5/Array/shell.js b/js/src/tests/js1_5/Array/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/js1_5/Array/shell.js