1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_6/Array/regress-304828.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,256 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 304828; 1.11 +var summary = 'Array Generic Methods'; 1.12 +var actual = ''; 1.13 +var expect = ''; 1.14 +printBugNumber(BUGNUMBER); 1.15 +printStatus (summary); 1.16 + 1.17 +var value; 1.18 + 1.19 +// use Array methods on a String 1.20 +// join 1.21 +value = '123'; 1.22 +expect = '1,2,3'; 1.23 +try 1.24 +{ 1.25 + actual = Array.prototype.join.call(value); 1.26 +} 1.27 +catch(e) 1.28 +{ 1.29 + actual = e + ''; 1.30 +} 1.31 +reportCompare(expect, actual, summary + ': join'); 1.32 + 1.33 +// reverse 1.34 +value = '123'; 1.35 +expect = 'TypeError: Array.prototype.reverse.call(...) is read-only'; 1.36 +try 1.37 +{ 1.38 + actual = Array.prototype.reverse.call(value) + ''; 1.39 +} 1.40 +catch(e) 1.41 +{ 1.42 + actual = e + ''; 1.43 +} 1.44 +reportCompare(expect, actual, summary + ': reverse'); 1.45 + 1.46 +// sort 1.47 +value = 'cba'; 1.48 +expect = 'TypeError: Array.prototype.sort.call(...) is read-only'; 1.49 +try 1.50 +{ 1.51 + actual = Array.prototype.sort.call(value) + ''; 1.52 +} 1.53 +catch(e) 1.54 +{ 1.55 + actual = e + ''; 1.56 +} 1.57 +reportCompare(expect, actual, summary + ': sort'); 1.58 + 1.59 +// push 1.60 +value = 'abc'; 1.61 +expect = 6; 1.62 +try 1.63 +{ 1.64 + Array.prototype.push.call(value, 'd', 'e', 'f'); 1.65 + throw new Error("didn't throw"); 1.66 +} 1.67 +catch(e) 1.68 +{ 1.69 + reportCompare(true, e instanceof TypeError, 1.70 + "push on a string primitive should throw TypeError"); 1.71 +} 1.72 +reportCompare('abc', value, summary + ': push string primitive'); 1.73 + 1.74 +value = new String("abc"); 1.75 +expect = 6; 1.76 +try 1.77 +{ 1.78 + Array.prototype.push.call(value, 'd', 'e', 'f'); 1.79 + throw new Error("didn't throw"); 1.80 +} 1.81 +catch(e) 1.82 +{ 1.83 + reportCompare(true, e instanceof TypeError, 1.84 + "push on a String object should throw TypeError"); 1.85 +} 1.86 +reportCompare("d", value[3], summary + ': push String object index 3'); 1.87 +reportCompare("e", value[4], summary + ': push String object index 4'); 1.88 +reportCompare("f", value[5], summary + ': push String object index 5'); 1.89 + 1.90 +// pop 1.91 +value = 'abc'; 1.92 +expect = "TypeError: property Array.prototype.pop.call(...) is non-configurable and can't be deleted"; 1.93 +try 1.94 +{ 1.95 + actual = Array.prototype.pop.call(value); 1.96 +} 1.97 +catch(e) 1.98 +{ 1.99 + actual = e + ''; 1.100 +} 1.101 +reportCompare(expect, actual, summary + ': pop'); 1.102 +reportCompare('abc', value, summary + ': pop'); 1.103 + 1.104 +// unshift 1.105 +value = 'def'; 1.106 +expect = 'TypeError: Array.prototype.unshift.call(...) is read-only'; 1.107 +try 1.108 +{ 1.109 + actual = Array.prototype.unshift.call(value, 'a', 'b', 'c'); 1.110 +} 1.111 +catch(e) 1.112 +{ 1.113 + actual = e + ''; 1.114 +} 1.115 +reportCompare(expect, actual, summary + ': unshift'); 1.116 +reportCompare('def', value, summary + ': unshift'); 1.117 + 1.118 +// shift 1.119 +value = 'abc'; 1.120 +expect = 'TypeError: Array.prototype.shift.call(...) is read-only'; 1.121 +try 1.122 +{ 1.123 + actual = Array.prototype.shift.call(value); 1.124 +} 1.125 +catch(e) 1.126 +{ 1.127 + actual = e + ''; 1.128 +} 1.129 +reportCompare(expect, actual, summary + ': shift'); 1.130 +reportCompare('abc', value, summary + ': shift'); 1.131 + 1.132 +// splice 1.133 +value = 'abc'; 1.134 +expect = 'TypeError: Array.prototype.splice.call(...) is read-only'; 1.135 +try 1.136 +{ 1.137 + actual = Array.prototype.splice.call(value, 1, 1) + ''; 1.138 +} 1.139 +catch(e) 1.140 +{ 1.141 + actual = e + ''; 1.142 +} 1.143 +reportCompare(expect, actual, summary + ': splice'); 1.144 + 1.145 +// concat 1.146 +value = 'abc'; 1.147 +expect = 'abc,d,e,f'; 1.148 +try 1.149 +{ 1.150 + actual = Array.prototype.concat.call(value, 'd', 'e', 'f') + ''; 1.151 +} 1.152 +catch(e) 1.153 +{ 1.154 + actual = e + ''; 1.155 +} 1.156 +reportCompare(expect, actual, summary + ': concat'); 1.157 + 1.158 +// slice 1.159 +value = 'abc'; 1.160 +expect = 'b'; 1.161 +try 1.162 +{ 1.163 + actual = Array.prototype.slice.call(value, 1, 2) + ''; 1.164 +} 1.165 +catch(e) 1.166 +{ 1.167 + actual = e + ''; 1.168 +} 1.169 +reportCompare(expect, actual, summary + ': slice'); 1.170 + 1.171 +// indexOf 1.172 +value = 'abc'; 1.173 +expect = 1; 1.174 +try 1.175 +{ 1.176 + actual = Array.prototype.indexOf.call(value, 'b'); 1.177 +} 1.178 +catch(e) 1.179 +{ 1.180 + actual = e + ''; 1.181 +} 1.182 +reportCompare(expect, actual, summary + ': indexOf'); 1.183 + 1.184 +// lastIndexOf 1.185 +value = 'abcabc'; 1.186 +expect = 4; 1.187 +try 1.188 +{ 1.189 + actual = Array.prototype.lastIndexOf.call(value, 'b'); 1.190 +} 1.191 +catch(e) 1.192 +{ 1.193 + actual = e + ''; 1.194 +} 1.195 +reportCompare(expect, actual, summary + ': lastIndexOf'); 1.196 + 1.197 +// forEach 1.198 +value = 'abc'; 1.199 +expect = 'ABC'; 1.200 +actual = ''; 1.201 +try 1.202 +{ 1.203 + Array.prototype.forEach.call(value, 1.204 + function (v, index, array) 1.205 + {actual += array[index].toUpperCase();}); 1.206 +} 1.207 +catch(e) 1.208 +{ 1.209 + actual = e + ''; 1.210 +} 1.211 +reportCompare(expect, actual, summary + ': forEach'); 1.212 + 1.213 +// map 1.214 +value = 'abc'; 1.215 +expect = 'A,B,C'; 1.216 +try 1.217 +{ 1.218 + actual = Array.prototype.map.call(value, 1.219 + function (v, index, array) 1.220 + {return v.toUpperCase();}) + ''; 1.221 +} 1.222 +catch(e) 1.223 +{ 1.224 + actual = e + ''; 1.225 +} 1.226 +reportCompare(expect, actual, summary + ': map'); 1.227 + 1.228 +// filter 1.229 +value = '1234567890'; 1.230 +expect = '2,4,6,8,0'; 1.231 +try 1.232 +{ 1.233 + actual = Array.prototype.filter.call(value, 1.234 + function (v, index, array) 1.235 + {return array[index] % 2 == 0;}) + ''; 1.236 +} 1.237 +catch(e) 1.238 +{ 1.239 + actual = e + ''; 1.240 +} 1.241 +reportCompare(expect, actual, summary + ': filter'); 1.242 + 1.243 +// every 1.244 +value = '1234567890'; 1.245 +expect = false; 1.246 +try 1.247 +{ 1.248 + actual = Array.prototype.every.call(value, 1.249 + function (v, index, array) 1.250 + {return array[index] % 2 == 0;}); 1.251 +} 1.252 +catch(e) 1.253 +{ 1.254 + actual = e + ''; 1.255 +} 1.256 +reportCompare(expect, actual, summary + ': every'); 1.257 + 1.258 + 1.259 +