js/src/tests/js1_6/Array/regress-304828.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 var BUGNUMBER = 304828;
michael@0 8 var summary = 'Array Generic Methods';
michael@0 9 var actual = '';
michael@0 10 var expect = '';
michael@0 11 printBugNumber(BUGNUMBER);
michael@0 12 printStatus (summary);
michael@0 13
michael@0 14 var value;
michael@0 15
michael@0 16 // use Array methods on a String
michael@0 17 // join
michael@0 18 value = '123';
michael@0 19 expect = '1,2,3';
michael@0 20 try
michael@0 21 {
michael@0 22 actual = Array.prototype.join.call(value);
michael@0 23 }
michael@0 24 catch(e)
michael@0 25 {
michael@0 26 actual = e + '';
michael@0 27 }
michael@0 28 reportCompare(expect, actual, summary + ': join');
michael@0 29
michael@0 30 // reverse
michael@0 31 value = '123';
michael@0 32 expect = 'TypeError: Array.prototype.reverse.call(...) is read-only';
michael@0 33 try
michael@0 34 {
michael@0 35 actual = Array.prototype.reverse.call(value) + '';
michael@0 36 }
michael@0 37 catch(e)
michael@0 38 {
michael@0 39 actual = e + '';
michael@0 40 }
michael@0 41 reportCompare(expect, actual, summary + ': reverse');
michael@0 42
michael@0 43 // sort
michael@0 44 value = 'cba';
michael@0 45 expect = 'TypeError: Array.prototype.sort.call(...) is read-only';
michael@0 46 try
michael@0 47 {
michael@0 48 actual = Array.prototype.sort.call(value) + '';
michael@0 49 }
michael@0 50 catch(e)
michael@0 51 {
michael@0 52 actual = e + '';
michael@0 53 }
michael@0 54 reportCompare(expect, actual, summary + ': sort');
michael@0 55
michael@0 56 // push
michael@0 57 value = 'abc';
michael@0 58 expect = 6;
michael@0 59 try
michael@0 60 {
michael@0 61 Array.prototype.push.call(value, 'd', 'e', 'f');
michael@0 62 throw new Error("didn't throw");
michael@0 63 }
michael@0 64 catch(e)
michael@0 65 {
michael@0 66 reportCompare(true, e instanceof TypeError,
michael@0 67 "push on a string primitive should throw TypeError");
michael@0 68 }
michael@0 69 reportCompare('abc', value, summary + ': push string primitive');
michael@0 70
michael@0 71 value = new String("abc");
michael@0 72 expect = 6;
michael@0 73 try
michael@0 74 {
michael@0 75 Array.prototype.push.call(value, 'd', 'e', 'f');
michael@0 76 throw new Error("didn't throw");
michael@0 77 }
michael@0 78 catch(e)
michael@0 79 {
michael@0 80 reportCompare(true, e instanceof TypeError,
michael@0 81 "push on a String object should throw TypeError");
michael@0 82 }
michael@0 83 reportCompare("d", value[3], summary + ': push String object index 3');
michael@0 84 reportCompare("e", value[4], summary + ': push String object index 4');
michael@0 85 reportCompare("f", value[5], summary + ': push String object index 5');
michael@0 86
michael@0 87 // pop
michael@0 88 value = 'abc';
michael@0 89 expect = "TypeError: property Array.prototype.pop.call(...) is non-configurable and can't be deleted";
michael@0 90 try
michael@0 91 {
michael@0 92 actual = Array.prototype.pop.call(value);
michael@0 93 }
michael@0 94 catch(e)
michael@0 95 {
michael@0 96 actual = e + '';
michael@0 97 }
michael@0 98 reportCompare(expect, actual, summary + ': pop');
michael@0 99 reportCompare('abc', value, summary + ': pop');
michael@0 100
michael@0 101 // unshift
michael@0 102 value = 'def';
michael@0 103 expect = 'TypeError: Array.prototype.unshift.call(...) is read-only';
michael@0 104 try
michael@0 105 {
michael@0 106 actual = Array.prototype.unshift.call(value, 'a', 'b', 'c');
michael@0 107 }
michael@0 108 catch(e)
michael@0 109 {
michael@0 110 actual = e + '';
michael@0 111 }
michael@0 112 reportCompare(expect, actual, summary + ': unshift');
michael@0 113 reportCompare('def', value, summary + ': unshift');
michael@0 114
michael@0 115 // shift
michael@0 116 value = 'abc';
michael@0 117 expect = 'TypeError: Array.prototype.shift.call(...) is read-only';
michael@0 118 try
michael@0 119 {
michael@0 120 actual = Array.prototype.shift.call(value);
michael@0 121 }
michael@0 122 catch(e)
michael@0 123 {
michael@0 124 actual = e + '';
michael@0 125 }
michael@0 126 reportCompare(expect, actual, summary + ': shift');
michael@0 127 reportCompare('abc', value, summary + ': shift');
michael@0 128
michael@0 129 // splice
michael@0 130 value = 'abc';
michael@0 131 expect = 'TypeError: Array.prototype.splice.call(...) is read-only';
michael@0 132 try
michael@0 133 {
michael@0 134 actual = Array.prototype.splice.call(value, 1, 1) + '';
michael@0 135 }
michael@0 136 catch(e)
michael@0 137 {
michael@0 138 actual = e + '';
michael@0 139 }
michael@0 140 reportCompare(expect, actual, summary + ': splice');
michael@0 141
michael@0 142 // concat
michael@0 143 value = 'abc';
michael@0 144 expect = 'abc,d,e,f';
michael@0 145 try
michael@0 146 {
michael@0 147 actual = Array.prototype.concat.call(value, 'd', 'e', 'f') + '';
michael@0 148 }
michael@0 149 catch(e)
michael@0 150 {
michael@0 151 actual = e + '';
michael@0 152 }
michael@0 153 reportCompare(expect, actual, summary + ': concat');
michael@0 154
michael@0 155 // slice
michael@0 156 value = 'abc';
michael@0 157 expect = 'b';
michael@0 158 try
michael@0 159 {
michael@0 160 actual = Array.prototype.slice.call(value, 1, 2) + '';
michael@0 161 }
michael@0 162 catch(e)
michael@0 163 {
michael@0 164 actual = e + '';
michael@0 165 }
michael@0 166 reportCompare(expect, actual, summary + ': slice');
michael@0 167
michael@0 168 // indexOf
michael@0 169 value = 'abc';
michael@0 170 expect = 1;
michael@0 171 try
michael@0 172 {
michael@0 173 actual = Array.prototype.indexOf.call(value, 'b');
michael@0 174 }
michael@0 175 catch(e)
michael@0 176 {
michael@0 177 actual = e + '';
michael@0 178 }
michael@0 179 reportCompare(expect, actual, summary + ': indexOf');
michael@0 180
michael@0 181 // lastIndexOf
michael@0 182 value = 'abcabc';
michael@0 183 expect = 4;
michael@0 184 try
michael@0 185 {
michael@0 186 actual = Array.prototype.lastIndexOf.call(value, 'b');
michael@0 187 }
michael@0 188 catch(e)
michael@0 189 {
michael@0 190 actual = e + '';
michael@0 191 }
michael@0 192 reportCompare(expect, actual, summary + ': lastIndexOf');
michael@0 193
michael@0 194 // forEach
michael@0 195 value = 'abc';
michael@0 196 expect = 'ABC';
michael@0 197 actual = '';
michael@0 198 try
michael@0 199 {
michael@0 200 Array.prototype.forEach.call(value,
michael@0 201 function (v, index, array)
michael@0 202 {actual += array[index].toUpperCase();});
michael@0 203 }
michael@0 204 catch(e)
michael@0 205 {
michael@0 206 actual = e + '';
michael@0 207 }
michael@0 208 reportCompare(expect, actual, summary + ': forEach');
michael@0 209
michael@0 210 // map
michael@0 211 value = 'abc';
michael@0 212 expect = 'A,B,C';
michael@0 213 try
michael@0 214 {
michael@0 215 actual = Array.prototype.map.call(value,
michael@0 216 function (v, index, array)
michael@0 217 {return v.toUpperCase();}) + '';
michael@0 218 }
michael@0 219 catch(e)
michael@0 220 {
michael@0 221 actual = e + '';
michael@0 222 }
michael@0 223 reportCompare(expect, actual, summary + ': map');
michael@0 224
michael@0 225 // filter
michael@0 226 value = '1234567890';
michael@0 227 expect = '2,4,6,8,0';
michael@0 228 try
michael@0 229 {
michael@0 230 actual = Array.prototype.filter.call(value,
michael@0 231 function (v, index, array)
michael@0 232 {return array[index] % 2 == 0;}) + '';
michael@0 233 }
michael@0 234 catch(e)
michael@0 235 {
michael@0 236 actual = e + '';
michael@0 237 }
michael@0 238 reportCompare(expect, actual, summary + ': filter');
michael@0 239
michael@0 240 // every
michael@0 241 value = '1234567890';
michael@0 242 expect = false;
michael@0 243 try
michael@0 244 {
michael@0 245 actual = Array.prototype.every.call(value,
michael@0 246 function (v, index, array)
michael@0 247 {return array[index] % 2 == 0;});
michael@0 248 }
michael@0 249 catch(e)
michael@0 250 {
michael@0 251 actual = e + '';
michael@0 252 }
michael@0 253 reportCompare(expect, actual, summary + ': every');
michael@0 254
michael@0 255
michael@0 256

mercurial