diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
| commit | 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (patch) | |
| tree | 11425ea0b299d6fb89c6d3618a22d97d5bf68d0f /JavaScriptCore/tests/mozilla/ecma_3/Array | |
| parent | 648161bb0edfc3d43db63caed5cc5213bc6cb78f (diff) | |
| download | external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.zip external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.gz external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.bz2 | |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'JavaScriptCore/tests/mozilla/ecma_3/Array')
4 files changed, 579 insertions, 0 deletions
diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.3-1.js b/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.3-1.js new file mode 100644 index 0000000..7b5fdbd --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.3-1.js @@ -0,0 +1,66 @@ +/* +* The contents of this file are subject to the Netscape Public +* License Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS +* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is mozilla.org code. +* +* The Initial Developer of the Original Code is Netscape +* Communications Corporation. Portions created by Netscape are +* Copyright (C) 1998 Netscape Communications Corporation. +* All Rights Reserved. +* +* Contributor(s): pschwartau@netscape.com +* Date: 12 Mar 2001 +* +* +* SUMMARY: Testing Array.prototype.toLocaleString() +* See http://bugzilla.mozilla.org/show_bug.cgi?id=56883 +* See http://bugzilla.mozilla.org/show_bug.cgi?id=58031 +* +* By ECMA3 15.4.4.3, myArray.toLocaleString() means that toLocaleString() +* should be applied to each element of the array, and the results should be +* concatenated with an implementation-specific delimiter. For example: +* +* myArray[0].toLocaleString() + ',' + myArray[1].toLocaleString() + etc. +* +* In this testcase toLocaleString is a user-defined property of each array element; +* therefore it is the function that should be invoked. This function increments a +* global variable. Therefore the end value of this variable should be myArray.length. +*/ +//------------------------------------------------------------------------------------------------- +var bug = 56883; +var summary = 'Testing Array.prototype.toLocaleString() -'; +var actual = ''; +var expect = ''; +var n = 0; +var obj = {toLocaleString: function() {n++}}; +var myArray = [obj, obj, obj]; + + +myArray.toLocaleString(); +actual = n; +expect = 3; // (see explanation above) + + +//------------------------------------------------------------------------------------------------- +test(); +//------------------------------------------------------------------------------------------------- + + +function test() +{ + enterFunc ('test'); + printBugNumber (bug); + printStatus (summary); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.4-001.js b/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.4-001.js new file mode 100644 index 0000000..6d99159 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Array/15.4.4.4-001.js @@ -0,0 +1,148 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* Version: NPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Netscape Public License +* Version 1.1 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +* for the specific language governing rights and limitations under the +* License. +* +* The Original Code is JavaScript Engine testing utilities. +* +* The Initial Developer of the Original Code is Netscape Communications Corp. +* Portions created by the Initial Developer are Copyright (C) 2002 +* the Initial Developer. All Rights Reserved. +* +* Contributor(s): george@vanous.com, igor@icesoft.no, pschwartau@netscape.com +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 2 or later (the "GPL"), or +* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +* in which case the provisions of the GPL or the LGPL are applicable instead +* of those above. If you wish to allow use of your version of this file only +* under the terms of either the GPL or the LGPL, and not to allow others to +* use your version of this file under the terms of the NPL, indicate your +* decision by deleting the provisions above and replace them with the notice +* and other provisions required by the GPL or the LGPL. If you do not delete +* the provisions above, a recipient may use your version of this file under +* the terms of any one of the NPL, the GPL or the LGPL. +* +* ***** END LICENSE BLOCK ***** +* +* +* Date: 19 September 2002 +* SUMMARY: Testing Array.prototype.concat() +* See http://bugzilla.mozilla.org/show_bug.cgi?id=169795 +* +*/ +//----------------------------------------------------------------------------- +var UBound = 0; +var bug = 169795; +var summary = 'Testing Array.prototype.concat()'; +var status = ''; +var statusitems = []; +var actual = ''; +var actualvalues = []; +var expect= ''; +var expectedvalues = []; +var x; + + +status = inSection(1); +x = "Hello"; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(2); +x = 999; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(3); +x = /Hello/g; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(4); +x = new Error("Hello"); +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(5); +x = function() {return "Hello";}; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(6); +x = [function() {return "Hello";}]; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(7); +x = [1,2,3].concat([4,5,6]); +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(8); +x = eval('this'); +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +/* + * The next two sections are by igor@icesoft.no; see + * http://bugzilla.mozilla.org/show_bug.cgi?id=169795#c3 + */ +status = inSection(9); +x={length:0}; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + +status = inSection(10); +x={length:2, 0:0, 1:1}; +actual = [].concat(x).toString(); +expect = x.toString(); +addThis(); + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + + +function addThis() +{ + statusitems[UBound] = status; + actualvalues[UBound] = actual; + expectedvalues[UBound] = expect; + UBound++; +} + + +function test() +{ + enterFunc('test'); + printBugNumber(bug); + printStatus(summary); + + for (var i=0; i<UBound; i++) + { + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); + } + + exitFunc ('test'); +} diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-101488.js b/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-101488.js new file mode 100644 index 0000000..73c22c9 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-101488.js @@ -0,0 +1,151 @@ +/* +* The contents of this file are subject to the Netscape Public +* License Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. You may obtain a copy of +* the License at http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS +* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +* implied. See the License for the specific language governing +* rights and limitations under the License. +* +* The Original Code is mozilla.org code. +* +* The Initial Developer of the Original Code is Netscape +* Communications Corporation. Portions created by Netscape are +* Copyright (C) 1998 Netscape Communications Corporation. +* All Rights Reserved. +* +* Contributor(s): igor@icesoft.no, pschwartau@netscape.com +* Date: 24 September 2001 +* +* SUMMARY: Try assigning arr.length = new Number(n) +* From correspondence with Igor Bukanov <igor@icesoft.no> +* See http://bugzilla.mozilla.org/show_bug.cgi?id=101488 +* +* Without the "new" keyword, assigning arr.length = Number(n) worked. +* But with it, Rhino was giving an error "Inappropriate array length" +* and SpiderMonkey was exiting without giving any error or return value - +* +* Comments on the Rhino code by igor@icesoft.no: +* +* jsSet_length requires that the new length value should be an instance +* of Number. But according to Ecma 15.4.5.1, item 12-13, an error should +* be thrown only if ToUint32(length_value) != ToNumber(length_value) +*/ +//----------------------------------------------------------------------------- +var UBound = 0; +var bug = 101488; +var summary = 'Try assigning arr.length = new Number(n)'; +var status = ''; +var statusitems = []; +var actual = ''; +var actualvalues = []; +var expect= ''; +var expectedvalues = []; +var arr = []; + + +status = inSection(1); +arr = Array(); +tryThis('arr.length = new Number(1);'); +actual = arr.length; +expect = 1; +addThis(); + +status = inSection(2); +arr = Array(5); +tryThis('arr.length = new Number(1);'); +actual = arr.length; +expect = 1; +addThis(); + +status = inSection(3); +arr = Array(); +tryThis('arr.length = new Number(17);'); +actual = arr.length; +expect = 17; +addThis(); + +status = inSection(4); +arr = Array(5); +tryThis('arr.length = new Number(17);'); +actual = arr.length; +expect = 17; +addThis(); + + +/* + * Also try the above with the "new" keyword before Array(). + * Array() and new Array() should be equivalent, by ECMA 15.4.1.1 + */ +status = inSection(5); +arr = new Array(); +tryThis('arr.length = new Number(1);'); +actual = arr.length; +expect = 1; +addThis(); + +status = inSection(6); +arr = new Array(5); +tryThis('arr.length = new Number(1);'); +actual = arr.length; +expect = 1; +addThis(); + +arr = new Array(); +tryThis('arr.length = new Number(17);'); +actual = arr.length; +expect = 17; +addThis(); + +status = inSection(7); +arr = new Array(5); +tryThis('arr.length = new Number(17);'); +actual = arr.length; +expect = 17; +addThis(); + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + + +function tryThis(s) +{ + try + { + eval(s); + } + catch(e) + { + // keep going + } +} + + +function addThis() +{ + statusitems[UBound] = status; + actualvalues[UBound] = actual; + expectedvalues[UBound] = expect; + UBound++; +} + + +function test() +{ + enterFunc ('test'); + printBugNumber (bug); + printStatus (summary); + + for (var i=0; i<UBound; i++) + { + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); + } + + exitFunc ('test'); +} diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-130451.js b/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-130451.js new file mode 100644 index 0000000..7cc5051 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Array/regress-130451.js @@ -0,0 +1,214 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* Version: NPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Netscape Public License +* Version 1.1 (the "License"); you may not use this file except in +* compliance with the License. You may obtain a copy of the License at +* http://www.mozilla.org/NPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +* for the specific language governing rights and limitations under the +* License. +* +* The Original Code is JavaScript Engine testing utilities. +* +* The Initial Developer of the Original Code is Netscape Communications Corp. +* Portions created by the Initial Developer are Copyright (C) 2002 +* the Initial Developer. All Rights Reserved. +* +* Contributor(s): brendan@mozilla.org, pschwartau@netscape.com +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 2 or later (the "GPL"), or +* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +* in which case the provisions of the GPL or the LGPL are applicable instead +* of those above. If you wish to allow use of your version of this file only +* under the terms of either the GPL or the LGPL, and not to allow others to +* use your version of this file under the terms of the NPL, indicate your +* decision by deleting the provisions above and replace them with the notice +* and other provisions required by the GPL or the LGPL. If you do not delete +* the provisions above, a recipient may use your version of this file under +* the terms of any one of the NPL, the GPL or the LGPL. +* +* ***** END LICENSE BLOCK ***** +* +* +* Date: 25 Mar 2002 +* SUMMARY: Array.prototype.sort() should not (re-)define .length +* See http://bugzilla.mozilla.org/show_bug.cgi?id=130451 +* +* From the ECMA-262 Edition 3 Final spec: +* +* NOTE: The sort function is intentionally generic; it does not require that +* its |this| value be an Array object. Therefore, it can be transferred to +* other kinds of objects for use as a method. Whether the sort function can +* be applied successfully to a host object is implementation-dependent. +* +* The interesting parts of this testcase are the contrasting expectations for +* Brendan's test below, when applied to Array objects vs. non-Array objects. +* +*/ +//----------------------------------------------------------------------------- +var UBound = 0; +var bug = 130451; +var summary = 'Array.prototype.sort() should not (re-)define .length'; +var status = ''; +var statusitems = []; +var actual = ''; +var actualvalues = []; +var expect= ''; +var expectedvalues = []; +var arr = []; +var cmp = new Function(); + + +/* + * First: test Array.prototype.sort() on Array objects + */ +status = inSection(1); +arr = [0,1,2,3]; +cmp = function(x,y) {return x-y;}; +actual = arr.sort(cmp).length; +expect = 4; +addThis(); + +status = inSection(2); +arr = [0,1,2,3]; +cmp = function(x,y) {return y-x;}; +actual = arr.sort(cmp).length; +expect = 4; +addThis(); + +status = inSection(3); +arr = [0,1,2,3]; +cmp = function(x,y) {return x-y;}; +arr.length = 1; +actual = arr.sort(cmp).length; +expect = 1; +addThis(); + +/* + * This test is by Brendan. Setting arr.length to + * 2 and then 4 should cause elements to be deleted. + */ +arr = [0,1,2,3]; +cmp = function(x,y) {return x-y;}; +arr.sort(cmp); + +status = inSection(4); +actual = arr.join(); +expect = '0,1,2,3'; +addThis(); + +status = inSection(5); +actual = arr.length; +expect = 4; +addThis(); + +status = inSection(6); +arr.length = 2; +actual = arr.join(); +expect = '0,1'; +addThis(); + +status = inSection(7); +arr.length = 4; +actual = arr.join(); +expect = '0,1,,'; //<---- see how 2,3 have been lost +addThis(); + + + +/* + * Now test Array.prototype.sort() on non-Array objects + */ +status = inSection(8); +var obj = new Object(); +obj.sort = Array.prototype.sort; +obj.length = 4; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +cmp = function(x,y) {return x-y;}; +actual = obj.sort(cmp).length; +expect = 4; +addThis(); + + +/* + * Here again is Brendan's test. Unlike the array case + * above, the setting of obj.length to 2 and then 4 + * should NOT cause elements to be deleted + */ +obj = new Object(); +obj.sort = Array.prototype.sort; +obj.length = 4; +obj[0] = 3; +obj[1] = 2; +obj[2] = 1; +obj[3] = 0; +cmp = function(x,y) {return x-y;}; +obj.sort(cmp); //<---- this is what triggered the buggy behavior below +obj.join = Array.prototype.join; + +status = inSection(9); +actual = obj.join(); +expect = '0,1,2,3'; +addThis(); + +status = inSection(10); +actual = obj.length; +expect = 4; +addThis(); + +status = inSection(11); +obj.length = 2; +actual = obj.join(); +expect = '0,1'; +addThis(); + +/* + * Before this bug was fixed, |actual| held the value '0,1,,' + * as in the Array-object case at top. This bug only occurred + * if Array.prototype.sort() had been applied to |obj|, + * as we have done higher up. + */ +status = inSection(12); +obj.length = 4; +actual = obj.join(); +expect = '0,1,2,3'; +addThis(); + + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + + +function addThis() +{ + statusitems[UBound] = status; + actualvalues[UBound] = actual; + expectedvalues[UBound] = expect; + UBound++; +} + + +function test() +{ + enterFunc('test'); + printBugNumber(bug); + printStatus(summary); + + for (var i=0; i<UBound; i++) + { + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); + } + + exitFunc ('test'); +} |
