Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / Array / regress-101488.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   igor@icesoft.no, pschwartau@netscape.com
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  * Date: 24 September 2001
41  *
42  * SUMMARY: Try assigning arr.length = new Number(n)
43  * From correspondence with Igor Bukanov <igor@icesoft.no>
44  * See http://bugzilla.mozilla.org/show_bug.cgi?id=101488
45  *
46  * Without the "new" keyword, assigning arr.length = Number(n) worked.
47  * But with it, Rhino was giving an error "Inappropriate array length"
48  * and SpiderMonkey was exiting without giving any error or return value -
49  *
50  * Comments on the Rhino code by igor@icesoft.no:
51  *
52  * jsSet_length requires that the new length value should be an instance
53  * of Number. But according to Ecma 15.4.5.1, item 12-13, an error should
54  * be thrown only if ToUint32(length_value) != ToNumber(length_value)
55  */
56 //-----------------------------------------------------------------------------
57 var UBound = 0;
58 var BUGNUMBER = 101488;
59 var summary = 'Try assigning arr.length = new Number(n)';
60 var status = '';
61 var statusitems = [];
62 var actual = '';
63 var actualvalues = [];
64 var expect= '';
65 var expectedvalues = [];
66 var arr = [];
67
68
69 status = inSection(1);
70 arr = Array();
71 tryThis('arr.length = new Number(1);');
72 actual = arr.length;
73 expect = 1;
74 addThis();
75
76 status = inSection(2);
77 arr = Array(5);
78 tryThis('arr.length = new Number(1);');
79 actual = arr.length;
80 expect = 1;
81 addThis();
82
83 status = inSection(3);
84 arr = Array();
85 tryThis('arr.length = new Number(17);');
86 actual = arr.length;
87 expect = 17;
88 addThis();
89
90 status = inSection(4);
91 arr = Array(5);
92 tryThis('arr.length = new Number(17);');
93 actual = arr.length;
94 expect = 17;
95 addThis();
96
97
98 /*
99  * Also try the above with the "new" keyword before Array().
100  * Array() and new Array() should be equivalent, by ECMA 15.4.1.1
101  */
102 status = inSection(5);
103 arr = new Array();
104 tryThis('arr.length = new Number(1);');
105 actual = arr.length;
106 expect = 1;
107 addThis();
108
109 status = inSection(6);
110 arr = new Array(5);
111 tryThis('arr.length = new Number(1);');
112 actual = arr.length;
113 expect = 1;
114 addThis();
115
116 arr = new Array();
117 tryThis('arr.length = new Number(17);');
118 actual = arr.length;
119 expect = 17;
120 addThis();
121
122 status = inSection(7);
123 arr = new Array(5);
124 tryThis('arr.length = new Number(17);');
125 actual = arr.length;
126 expect = 17;
127 addThis();
128
129
130
131 //-----------------------------------------------------------------------------
132 test();
133 //-----------------------------------------------------------------------------
134
135
136
137 function tryThis(s)
138 {
139   try
140   {
141     eval(s);
142   }
143   catch(e)
144   {
145     // keep going
146   }
147 }
148
149
150 function addThis()
151 {
152   statusitems[UBound] = status;
153   actualvalues[UBound] = actual;
154   expectedvalues[UBound] = expect;
155   UBound++;
156 }
157
158
159 function test()
160 {
161   enterFunc ('test');
162   printBugNumber(BUGNUMBER);
163   printStatus (summary);
164
165   for (var i=0; i<UBound; i++)
166   {
167     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
168   }
169
170   exitFunc ('test');
171 }