]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_6/Array/regress-304828.js
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_6 / Array / regress-304828.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 JavaScript Engine testing utilities.
16 *
17 * The Initial Developer of the Original Code is
18 * Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37 //-----------------------------------------------------------------------------
38 var bug = 304828;
39 var summary = 'Array Generic Methods';
40 var actual = '';
41 var expect = '';
42 printBugNumber (bug);
43 printStatus (summary);
44
45 var value;
46
47 // use Array methods on a String
48 // join
49 value = '123';
50 expect = '1,2,3';
51 try
52 {
53 actual = Array.prototype.join.call(value);
54 }
55 catch(e)
56 {
57 actual = e + '';
58 }
59 reportCompare(expect, actual, summary + ': join');
60
61 // reverse
62 value = '123';
63 expect = 'TypeError: Attempted to assign to readonly property.';
64 try
65 {
66 actual = Array.prototype.reverse.call(value) + '';
67 }
68 catch(e)
69 {
70 actual = e + '';
71 }
72 reportCompare(expect, actual, summary + ': reverse');
73
74 // sort
75 value = 'cba';
76 expect = 'TypeError: Attempted to assign to readonly property.';
77 try
78 {
79 actual = Array.prototype.sort.call(value) + '';
80 }
81 catch(e)
82 {
83 actual = e + '';
84 }
85 reportCompare(expect, actual, summary + ': sort');
86
87 // push
88 value = 'abc';
89 expect = 6;
90 try
91 {
92 actual = Array.prototype.push.call(value, 'd', 'e', 'f');
93 }
94 catch(e)
95 {
96 actual = e + '';
97 }
98 reportCompare(expect, actual, summary + ': push');
99 reportCompare('abc', value, summary + ': push');
100
101 // pop
102 value = 'abc';
103 expect = 'TypeError: Unable to delete property.';
104 try
105 {
106 actual = Array.prototype.pop.call(value);
107 }
108 catch(e)
109 {
110 actual = e + '';
111 }
112 reportCompare(expect, actual, summary + ': pop');
113 reportCompare('abc', value, summary + ': pop');
114
115 // unshift
116 value = 'def';
117 expect = "TypeError: Attempted to assign to readonly property.";
118 try
119 {
120 actual = Array.prototype.unshift.call(value, 'a', 'b', 'c');
121 }
122 catch(e)
123 {
124 actual = e + '';
125 }
126 reportCompare(expect, actual, summary + ': unshift');
127 reportCompare('def', value, summary + ': unshift');
128
129 // shift
130 value = 'abc';
131 expect = 'TypeError: Attempted to assign to readonly property.';
132 try
133 {
134 actual = Array.prototype.shift.call(value);
135 }
136 catch(e)
137 {
138 actual = e + '';
139 }
140 reportCompare(expect, actual, summary + ': shift');
141 reportCompare('abc', value, summary + ': shift');
142
143 // splice
144 value = 'abc';
145 expect = 'TypeError: Attempted to assign to readonly property.';
146 try
147 {
148 actual = Array.prototype.splice.call(value, 1, 1) + '';
149 }
150 catch(e)
151 {
152 actual = e + '';
153 }
154 reportCompare(expect, actual, summary + ': splice');
155
156 // concat
157 value = 'abc';
158 expect = 'abc,d,e,f';
159 try
160 {
161 actual = Array.prototype.concat.call(value, 'd', 'e', 'f') + '';
162 }
163 catch(e)
164 {
165 actual = e + '';
166 }
167 reportCompare(expect, actual, summary + ': concat');
168
169 // slice
170 value = 'abc';
171 expect = 'b';
172 try
173 {
174 actual = Array.prototype.slice.call(value, 1, 2) + '';
175 }
176 catch(e)
177 {
178 actual = e + '';
179 }
180 reportCompare(expect, actual, summary + ': slice');
181
182 // indexOf
183 value = 'abc';
184 expect = 1;
185 try
186 {
187 actual = Array.prototype.indexOf.call(value, 'b');
188 }
189 catch(e)
190 {
191 actual = e + '';
192 }
193 reportCompare(expect, actual, summary + ': indexOf');
194
195 // lastIndexOf
196 value = 'abcabc';
197 expect = 4;
198 try
199 {
200 actual = Array.prototype.lastIndexOf.call(value, 'b');
201 }
202 catch(e)
203 {
204 actual = e + '';
205 }
206 reportCompare(expect, actual, summary + ': lastIndexOf');
207
208 // forEach
209 value = 'abc';
210 expect = 'ABC';
211 actual = '';
212 try
213 {
214 Array.prototype.forEach.call(value,
215 function (v, index, array)
216 {actual += array[index].toUpperCase();});
217 }
218 catch(e)
219 {
220 actual = e + '';
221 }
222 reportCompare(expect, actual, summary + ': forEach');
223
224 // map
225 value = 'abc';
226 expect = 'A,B,C';
227 try
228 {
229 actual = Array.prototype.map.call(value,
230 function (v, index, array)
231 {return v.toUpperCase();}) + '';
232 }
233 catch(e)
234 {
235 actual = e + '';
236 }
237 reportCompare(expect, actual, summary + ': map');
238
239 // filter
240 value = '1234567890';
241 expect = '2,4,6,8,0';
242 try
243 {
244 actual = Array.prototype.filter.call(value,
245 function (v, index, array)
246 {return array[index] % 2 == 0;}) + '';
247 }
248 catch(e)
249 {
250 actual = e + '';
251 }
252 reportCompare(expect, actual, summary + ': filter');
253
254 // every
255 value = '1234567890';
256 expect = false;
257 try
258 {
259 actual = Array.prototype.every.call(value,
260 function (v, index, array)
261 {return array[index] % 2 == 0;});
262 }
263 catch(e)
264 {
265 actual = e + '';
266 }
267 reportCompare(expect, actual, summary + ': every');
268
269
270