]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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
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
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
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.
36 * ***** END LICENSE BLOCK ***** */
37 //-----------------------------------------------------------------------------
39 var summary
= 'Array Generic Methods';
43 printStatus (summary
);
47 // use Array methods on a String
53 actual
= Array
.prototype.join
.call(value
);
59 reportCompare(expect
, actual
, summary
+ ': join');
63 expect
= 'TypeError: Attempted to assign to readonly property.';
66 actual
= Array
.prototype.reverse
.call(value
) + '';
72 reportCompare(expect
, actual
, summary
+ ': reverse');
76 expect
= 'TypeError: Attempted to assign to readonly property.';
79 actual
= Array
.prototype.sort
.call(value
) + '';
85 reportCompare(expect
, actual
, summary
+ ': sort');
92 actual
= Array
.prototype.push
.call(value
, 'd', 'e', 'f');
98 reportCompare(expect
, actual
, summary
+ ': push');
99 reportCompare('abc', value
, summary
+ ': push');
103 expect
= 'TypeError: Unable to delete property.';
106 actual
= Array
.prototype.pop
.call(value
);
112 reportCompare(expect
, actual
, summary
+ ': pop');
113 reportCompare('abc', value
, summary
+ ': pop');
117 expect
= "TypeError: Attempted to assign to readonly property.";
120 actual
= Array
.prototype.unshift
.call(value
, 'a', 'b', 'c');
126 reportCompare(expect
, actual
, summary
+ ': unshift');
127 reportCompare('def', value
, summary
+ ': unshift');
131 expect
= 'TypeError: Attempted to assign to readonly property.';
134 actual
= Array
.prototype.shift
.call(value
);
140 reportCompare(expect
, actual
, summary
+ ': shift');
141 reportCompare('abc', value
, summary
+ ': shift');
145 expect
= 'TypeError: Attempted to assign to readonly property.';
148 actual
= Array
.prototype.splice
.call(value
, 1, 1) + '';
154 reportCompare(expect
, actual
, summary
+ ': splice');
158 expect
= 'abc,d,e,f';
161 actual
= Array
.prototype.concat
.call(value
, 'd', 'e', 'f') + '';
167 reportCompare(expect
, actual
, summary
+ ': concat');
174 actual
= Array
.prototype.slice
.call(value
, 1, 2) + '';
180 reportCompare(expect
, actual
, summary
+ ': slice');
187 actual
= Array
.prototype.indexOf
.call(value
, 'b');
193 reportCompare(expect
, actual
, summary
+ ': indexOf');
200 actual
= Array
.prototype.lastIndexOf
.call(value
, 'b');
206 reportCompare(expect
, actual
, summary
+ ': lastIndexOf');
214 Array
.prototype.forEach
.call(value
,
215 function (v
, index
, array
)
216 {actual
+= array
[index
].toUpperCase();});
222 reportCompare(expect
, actual
, summary
+ ': forEach');
229 actual
= Array
.prototype.map
.call(value
,
230 function (v
, index
, array
)
231 {return v
.toUpperCase();}) + '';
237 reportCompare(expect
, actual
, summary
+ ': map');
240 value
= '1234567890';
241 expect
= '2,4,6,8,0';
244 actual
= Array
.prototype.filter
.call(value
,
245 function (v
, index
, array
)
246 {return array
[index
] % 2 == 0;}) + '';
252 reportCompare(expect
, actual
, summary
+ ': filter');
255 value
= '1234567890';
259 actual
= Array
.prototype.every
.call(value
,
260 function (v
, index
, array
)
261 {return array
[index
] % 2 == 0;});
267 reportCompare(expect
, actual
, summary
+ ': every');