]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Array/regress-178722.js
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Netscape Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is Netscape Communications Corp.
17 * Portions created by the Initial Developer are Copyright (C) 2002
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s): pschwartau@netscape.com
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the NPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the NPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK *****
37 * Date: 06 November 2002
38 * SUMMARY: arr.sort() should not output |undefined| when |arr| is empty
39 * See http://bugzilla.mozilla.org/show_bug.cgi?id=178722
41 * ECMA-262 Ed.3: 15.4.4.11 Array.prototype.sort (comparefn)
43 * 1. Call the [[Get]] method of this object with argument "length".
44 * 2. Call ToUint32(Result(1)).
45 * 3. Perform an implementation-dependent sequence of calls to the [[Get]],
46 * [[Put]], and [[Delete]] methods of this object, etc. etc.
47 * 4. Return this object.
50 * Note that sort() is done in-place on |arr|. In other words, sort() is a
51 * "destructive" method rather than a "functional" method. The return value
52 * of |arr.sort()| and |arr| are the same object.
54 * If |arr| is an empty array, the return value of |arr.sort()| should be
55 * an empty array, not the value |undefined| as was occurring in bug 178722.
58 //-----------------------------------------------------------------------------
61 var summary
= 'arr.sort() should not output |undefined| when |arr| is empty';
65 var actualvalues
= [];
67 var expectedvalues
= [];
71 // create empty array or pseudo-array objects in various ways
73 var arr2
= new Array();
77 function f () {return arguments
};
79 arr5
.__proto__
= Array
.prototype;
82 status
= inSection(1);
84 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr1
;
88 status
= inSection(2);
90 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr2
;
94 status
= inSection(3);
96 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr3
;
100 status
= inSection(4);
102 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr4
;
106 status
= inSection(5);
108 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr5
;
113 // now do the same thing, with non-default sorting:
114 function g() {return 1;}
116 status
= inSection('1a');
118 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr1
;
122 status
= inSection('2a');
124 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr2
;
128 status
= inSection('3a');
130 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr3
;
134 status
= inSection('4a');
136 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr4
;
140 status
= inSection('5a');
142 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr5
;
148 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------
156 statusitems
[UBound
] = status
;
157 actualvalues
[UBound
] = actual
;
158 expectedvalues
[UBound
] = expect
;
167 printStatus(summary
);
169 for (var i
=0; i
<UBound
; i
++)
171 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);