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 //-----------------------------------------------------------------------------
64 var BUGNUMBER = 178722;
65 var summary = 'arr.sort() should not output |undefined| when |arr| is empty';
69 var actualvalues = [];
71 var expectedvalues = [];
75 // create empty array or pseudo-array objects in various ways
77 var arr2 = new Array();
83 status = inSection(1);
85 actual = arr instanceof Array && arr.length === 0 && arr === arr1;
89 status = inSection(2);
91 actual = arr instanceof Array && arr.length === 0 && arr === arr2;
95 status = inSection(3);
97 actual = arr instanceof Array && arr.length === 0 && arr === arr3;
101 status = inSection(4);
103 actual = arr instanceof Array && arr.length === 0 && arr === arr4;
107 // now do the same thing, with non-default sorting:
108 function g() {return 1;}
110 status = inSection('1a');
112 actual = arr instanceof Array && arr.length === 0 && arr === arr1;
116 status = inSection('2a');
118 actual = arr instanceof Array && arr.length === 0 && arr === arr2;
122 status = inSection('3a');
124 actual = arr instanceof Array && arr.length === 0 && arr === arr3;
128 status = inSection('4a');
130 actual = arr instanceof Array && arr.length === 0 && arr === arr4;
136 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
144 statusitems[UBound] = status;
145 actualvalues[UBound] = actual;
146 expectedvalues[UBound] = expect;
154 printBugNumber(BUGNUMBER);
155 printStatus(summary);
157 for (var i=0; i<UBound; i++)
159 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);