Debian Codegraph @

rhino/testsrc/tests/js1_5/Array/regress-178722.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 *
8 * Date: 06 November 2002
9 * SUMMARY: arr.sort() should not output |undefined| when |arr| is empty
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=178722
11 *
12 * ECMA-262 Ed.3: 15.4.4.11 Array.prototype.sort (comparefn)
13 *
14 * 1. Call the [[Get]] method of this object with argument "length".
15 * 2. Call ToUint32(Result(1)).
16 * 3. Perform an implementation-dependent sequence of calls to the [[Get]],
17 * [[Put]], and [[Delete]] methods of this object, etc. etc.
18 * 4. Return this object.
19 *
20 *
21 * Note that sort() is done in-place on |arr|. In other words, sort() is a
22 * "destructive" method rather than a "functional" method. The return value
23 * of |arr.sort()| and |arr| are the same object.
24 *
25 * If |arr| is an empty array, the return value of |arr.sort()| should be
26 * an empty array, not the value |undefined| as was occurring in bug 178722.
27 *
28 */
29 //-----------------------------------------------------------------------------
30 var gTestfile = 'regress-178722.js';
31 var UBound = 0;
32 var BUGNUMBER = 178722;
33 var summary = 'arr.sort() should not output |undefined| when |arr| is empty';
34 var status = '';
35 var statusitems = [];
36 var actual = '';
37 var actualvalues = [];
38 var expect= '';
39 var expectedvalues = [];
40 var arr;
41
42
43 // create empty array or pseudo-array objects in various ways
44 var arr1 = Array();
45 var arr2 = new Array();
46 var arr3 = [];
47 var arr4 = [1];
48 arr4.pop();
49
50
51 status = inSection(1);
52 arr = arr1.sort();
53 actual = arr instanceof Array && arr.length === 0 && arr === arr1;
54 expect = true;
55 addThis();
56
57 status = inSection(2);
58 arr = arr2.sort();
59 actual = arr instanceof Array && arr.length === 0 && arr === arr2;
60 expect = true;
61 addThis();
62
63 status = inSection(3);
64 arr = arr3.sort();
65 actual = arr instanceof Array && arr.length === 0 && arr === arr3;
66 expect = true;
67 addThis();
68
69 status = inSection(4);
70 arr = arr4.sort();
71 actual = arr instanceof Array && arr.length === 0 && arr === arr4;
72 expect = true;
73 addThis();
74
75 // now do the same thing, with non-default sorting:
76 function g() {return 1;}
77
78 status = inSection('1a');
79 arr = arr1.sort(g);
80 actual = arr instanceof Array && arr.length === 0 && arr === arr1;
81 expect = true;
82 addThis();
83
84 status = inSection('2a');
85 arr = arr2.sort(g);
86 actual = arr instanceof Array && arr.length === 0 && arr === arr2;
87 expect = true;
88 addThis();
89
90 status = inSection('3a');
91 arr = arr3.sort(g);
92 actual = arr instanceof Array && arr.length === 0 && arr === arr3;
93 expect = true;
94 addThis();
95
96 status = inSection('4a');
97 arr = arr4.sort(g);
98 actual = arr instanceof Array && arr.length === 0 && arr === arr4;
99 expect = true;
100 addThis();
101
102
103
104 //-----------------------------------------------------------------------------
105 test();
106 //-----------------------------------------------------------------------------
107
108
109
110 function addThis()
111 {
112 statusitems[UBound] = status;
113 actualvalues[UBound] = actual;
114 expectedvalues[UBound] = expect;
115 UBound++;
116 }
117
118
119 function test()
120 {
121 enterFunc('test');
122 printBugNumber(BUGNUMBER);
123 printStatus(summary);
124
125 for (var i=0; i<UBound; i++)
126 {
127 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
128 }
129
130 exitFunc ('test');
131 }