1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 * Date: 06 November 2002
42 * SUMMARY: arr.sort() should not output |undefined| when |arr| is empty
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=178722
45 * ECMA-262 Ed.3: 15.4.4.11 Array.prototype.sort (comparefn)
47 * 1. Call the [[Get]] method of this object with argument "length".
48 * 2. Call ToUint32(Result(1)).
49 * 3. Perform an implementation-dependent sequence of calls to the [[Get]],
50 * [[Put]], and [[Delete]] methods of this object, etc. etc.
51 * 4. Return this object.
54 * Note that sort() is done in-place on |arr|. In other words, sort() is a
55 * "destructive" method rather than a "functional" method. The return value
56 * of |arr.sort()| and |arr| are the same object.
58 * If |arr| is an empty array, the return value of |arr.sort()| should be
59 * an empty array, not the value |undefined| as was occurring in bug 178722.
62 //-----------------------------------------------------------------------------
63 var gTestfile
= 'regress-178722.js';
65 var BUGNUMBER
= 178722;
66 var summary
= 'arr.sort() should not output |undefined| when |arr| is empty';
70 var actualvalues
= [];
72 var expectedvalues
= [];
76 // create empty array or pseudo-array objects in various ways
78 var arr2
= new Array();
84 status
= inSection(1);
86 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr1
;
90 status
= inSection(2);
92 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr2
;
96 status
= inSection(3);
98 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr3
;
102 status
= inSection(4);
104 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr4
;
108 // now do the same thing, with non-default sorting:
109 function g() {return 1;}
111 status
= inSection('1a');
113 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr1
;
117 status
= inSection('2a');
119 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr2
;
123 status
= inSection('3a');
125 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr3
;
129 status
= inSection('4a');
131 actual
= arr
instanceof Array
&& arr
.length
=== 0 && arr
=== arr4
;
137 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
145 statusitems
[UBound
] = status
;
146 actualvalues
[UBound
] = actual
;
147 expectedvalues
[UBound
] = expect
;
155 printBugNumber(BUGNUMBER
);
156 printStatus(summary
);
158 for (var i
=0; i
<UBound
; i
++)
160 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);