js/src/tests/ecma_3/String/15.5.4.11.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 // |reftest| fails
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 var BUGNUMBER = 392378;
michael@0 7 var summary = '15.5.4.11 - String.prototype.replace';
michael@0 8 var rex, f, a, i;
michael@0 9
michael@0 10 reportCompare(
michael@0 11 2,
michael@0 12 String.prototype.replace.length,
michael@0 13 "Section 1"
michael@0 14 );
michael@0 15
michael@0 16 reportCompare(
michael@0 17 "321",
michael@0 18 String.prototype.replace.call(123, "123", "321"),
michael@0 19 "Section 2"
michael@0 20 );
michael@0 21
michael@0 22 reportCompare(
michael@0 23 "ok",
michael@0 24 "ok".replace(),
michael@0 25 "Section 3"
michael@0 26 );
michael@0 27
michael@0 28 reportCompare(
michael@0 29 "undefined**",
michael@0 30 "***".replace("*"),
michael@0 31 "Section 4"
michael@0 32 );
michael@0 33
michael@0 34 reportCompare(
michael@0 35 "xnullz",
michael@0 36 "xyz".replace("y", null),
michael@0 37 "Section 5"
michael@0 38 );
michael@0 39
michael@0 40 reportCompare(
michael@0 41 "x123",
michael@0 42 "xyz".replace("yz", 123),
michael@0 43 "Section 6"
michael@0 44 );
michael@0 45
michael@0 46 reportCompare(
michael@0 47 "/x/g/x/g/x/g",
michael@0 48 "xxx".replace(/x/g, /x/g),
michael@0 49 "Section 7"
michael@0 50 );
michael@0 51
michael@0 52 reportCompare(
michael@0 53 "ok",
michael@0 54 "undefined".replace(undefined, "ok"),
michael@0 55 "Section 8"
michael@0 56 );
michael@0 57
michael@0 58 reportCompare(
michael@0 59 "ok",
michael@0 60 "null".replace(null, "ok"),
michael@0 61 "Section 9"
michael@0 62 );
michael@0 63
michael@0 64 reportCompare(
michael@0 65 "ok",
michael@0 66 "123".replace(123, "ok"),
michael@0 67 "Section 10"
michael@0 68 );
michael@0 69
michael@0 70 reportCompare(
michael@0 71 "xzyxyz",
michael@0 72 "xyzxyz".replace("yz", "zy"),
michael@0 73 "Section 11"
michael@0 74 );
michael@0 75
michael@0 76 reportCompare(
michael@0 77 "ok",
michael@0 78 "(xyz)".replace("(xyz)", "ok"),
michael@0 79 "Section 12"
michael@0 80 );
michael@0 81
michael@0 82 reportCompare(
michael@0 83 "*$&yzxyz",
michael@0 84 "xyzxyz".replace("x", "*$$&"),
michael@0 85 "Section 13"
michael@0 86 );
michael@0 87
michael@0 88 reportCompare(
michael@0 89 "xy*z*",
michael@0 90 "xyz".replace("z", "*$&*"),
michael@0 91 "Section 14"
michael@0 92 );
michael@0 93
michael@0 94 reportCompare(
michael@0 95 "xyxyzxyz",
michael@0 96 "xyzxyzxyz".replace("zxy", "$`"),
michael@0 97 "Section 15"
michael@0 98 );
michael@0 99
michael@0 100 reportCompare(
michael@0 101 "zxyzxyzzxyz",
michael@0 102 "xyzxyz".replace("xy", "$'xyz"),
michael@0 103 "Section 16"
michael@0 104 );
michael@0 105
michael@0 106 reportCompare(
michael@0 107 "$",
michael@0 108 "xyzxyz".replace("xyzxyz", "$"),
michael@0 109 "Section 17"
michael@0 110 );
michael@0 111
michael@0 112 reportCompare(
michael@0 113 "x$0$00xyz",
michael@0 114 "xyzxyz".replace("yz", "$0$00"),
michael@0 115 "Section 18"
michael@0 116 );
michael@0 117
michael@0 118 // Result for $1/$01 .. $99 is implementation-defined if searchValue is no
michael@0 119 // regular expression. $+ is a non-standard Mozilla extension.
michael@0 120
michael@0 121 reportCompare(
michael@0 122 "$!$\"$-1$*$#$.$xyz$$",
michael@0 123 "xyzxyz$$".replace("xyz", "$!$\"$-1$*$#$.$"),
michael@0 124 "Section 19"
michael@0 125 );
michael@0 126
michael@0 127 reportCompare(
michael@0 128 "$$$&$$$&$&",
michael@0 129 "$$$&".replace("$$", "$$$$$$&$&$$&"),
michael@0 130 "Section 20"
michael@0 131 );
michael@0 132
michael@0 133 reportCompare(
michael@0 134 "yxx",
michael@0 135 "xxx".replace(/x/, "y"),
michael@0 136 "Section 21"
michael@0 137 );
michael@0 138
michael@0 139 reportCompare(
michael@0 140 "yyy",
michael@0 141 "xxx".replace(/x/g, "y"),
michael@0 142 "Section 22"
michael@0 143 );
michael@0 144
michael@0 145 rex = /x/, rex.lastIndex = 1;
michael@0 146 reportCompare(
michael@0 147 "yxx1",
michael@0 148 "xxx".replace(rex, "y") + rex.lastIndex,
michael@0 149 "Section 23"
michael@0 150 );
michael@0 151
michael@0 152 rex = /x/g, rex.lastIndex = 1;
michael@0 153 reportCompare(
michael@0 154 "yyy0",
michael@0 155 "xxx".replace(rex, "y") + rex.lastIndex,
michael@0 156 "Section 24"
michael@0 157 );
michael@0 158
michael@0 159 rex = /y/, rex.lastIndex = 1;
michael@0 160 reportCompare(
michael@0 161 "xxx1",
michael@0 162 "xxx".replace(rex, "y") + rex.lastIndex,
michael@0 163 "Section 25"
michael@0 164 );
michael@0 165
michael@0 166 rex = /y/g, rex.lastIndex = 1;
michael@0 167 reportCompare(
michael@0 168 "xxx0",
michael@0 169 "xxx".replace(rex, "y") + rex.lastIndex,
michael@0 170 "Section 26"
michael@0 171 );
michael@0 172
michael@0 173 rex = /x?/, rex.lastIndex = 1;
michael@0 174 reportCompare(
michael@0 175 "(x)xx1",
michael@0 176 "xxx".replace(rex, "($&)") + rex.lastIndex,
michael@0 177 "Section 27"
michael@0 178 );
michael@0 179
michael@0 180 rex = /x?/g, rex.lastIndex = 1;
michael@0 181 reportCompare(
michael@0 182 "(x)(x)(x)()0",
michael@0 183 "xxx".replace(rex, "($&)") + rex.lastIndex,
michael@0 184 "Section 28"
michael@0 185 );
michael@0 186
michael@0 187 rex = /y?/, rex.lastIndex = 1;
michael@0 188 reportCompare(
michael@0 189 "()xxx1",
michael@0 190 "xxx".replace(rex, "($&)") + rex.lastIndex,
michael@0 191 "Section 29"
michael@0 192 );
michael@0 193
michael@0 194 rex = /y?/g, rex.lastIndex = 1;
michael@0 195 reportCompare(
michael@0 196 "()x()x()x()0",
michael@0 197 "xxx".replace(rex, "($&)") + rex.lastIndex,
michael@0 198 "Section 30"
michael@0 199 );
michael@0 200
michael@0 201 reportCompare(
michael@0 202 "xy$0xy$zxy$zxyz$zxyz",
michael@0 203 "xyzxyzxyz".replace(/zxy/, "$0$`$$$&$$$'$"),
michael@0 204 "Section 31"
michael@0 205 );
michael@0 206
michael@0 207 reportCompare(
michael@0 208 "xy$0xy$zxy$zxyz$$0xyzxy$zxy$z$z",
michael@0 209 "xyzxyzxyz".replace(/zxy/g, "$0$`$$$&$$$'$"),
michael@0 210 "Section 32"
michael@0 211 );
michael@0 212
michael@0 213 reportCompare(
michael@0 214 "xyxyxyzxyxyxyz",
michael@0 215 "xyzxyz".replace(/(((x)(y)()()))()()()(z)/g, "$01$2$3$04$5$6$7$8$09$10"),
michael@0 216 "Section 33"
michael@0 217 );
michael@0 218
michael@0 219 rex = RegExp(
michael@0 220 "()()()()()()()()()()" +
michael@0 221 "()()()()()()()()()()" +
michael@0 222 "()()()()()()()()()()" +
michael@0 223 "()()()()()()()()()()" +
michael@0 224 "()()()()()()()()()()" +
michael@0 225 "()()()()()()()()()()" +
michael@0 226 "()()()()()()()()()()" +
michael@0 227 "()()()()()()()()()()" +
michael@0 228 "()()()()()()()()()()" +
michael@0 229 "()()()()()()()()(y)");
michael@0 230 reportCompare(
michael@0 231 "x(y)z",
michael@0 232 "xyz".replace(rex, "($99)"),
michael@0 233 "Section 34"
michael@0 234 );
michael@0 235
michael@0 236 rex = RegExp(
michael@0 237 "()()()()()()()()()(x)" +
michael@0 238 "()()()()()()()()()()" +
michael@0 239 "()()()()()()()()()()" +
michael@0 240 "()()()()()()()()()()" +
michael@0 241 "()()()()()()()()()()" +
michael@0 242 "()()()()()()()()()()" +
michael@0 243 "()()()()()()()()()()" +
michael@0 244 "()()()()()()()()()()" +
michael@0 245 "()()()()()()()()()()" +
michael@0 246 "()()()()()()()()()(y)");
michael@0 247 reportCompare(
michael@0 248 "(x0)z",
michael@0 249 "xyz".replace(rex, "($100)"),
michael@0 250 "Section 35"
michael@0 251 );
michael@0 252
michael@0 253 reportCompare(
michael@0 254 "xyz(XYZ)",
michael@0 255 "xyzXYZ".replace(/XYZ/g, "($&)"),
michael@0 256 "Section 36"
michael@0 257 );
michael@0 258
michael@0 259 reportCompare(
michael@0 260 "(xyz)(XYZ)",
michael@0 261 "xyzXYZ".replace(/xYz/gi, "($&)"),
michael@0 262 "Section 37"
michael@0 263 );
michael@0 264
michael@0 265 reportCompare(
michael@0 266 "xyz\rxyz\n",
michael@0 267 "xyz\rxyz\n".replace(/xyz$/g, "($&)"),
michael@0 268 "Section 38"
michael@0 269 );
michael@0 270
michael@0 271 reportCompare(
michael@0 272 "(xyz)\r(xyz)\n",
michael@0 273 "xyz\rxyz\n".replace(/xyz$/gm, "($&)"),
michael@0 274 "Section 39"
michael@0 275 );
michael@0 276
michael@0 277 f = function () { return "failure" };
michael@0 278
michael@0 279 reportCompare(
michael@0 280 "ok",
michael@0 281 "ok".replace("x", f),
michael@0 282 "Section 40"
michael@0 283 );
michael@0 284
michael@0 285 reportCompare(
michael@0 286 "ok",
michael@0 287 "ok".replace(/(?=k)ok/, f),
michael@0 288 "Section 41"
michael@0 289 );
michael@0 290
michael@0 291 reportCompare(
michael@0 292 "ok",
michael@0 293 "ok".replace(/(?!)ok/, f),
michael@0 294 "Section 42"
michael@0 295 );
michael@0 296
michael@0 297 reportCompare(
michael@0 298 "ok",
michael@0 299 "ok".replace(/ok(?!$)/, f),
michael@0 300 "Section 43"
michael@0 301 );
michael@0 302
michael@0 303 f = function (sub, offs, str) {
michael@0 304 return ["", sub, typeof sub, offs, typeof offs, str, typeof str, ""]
michael@0 305 .join("|");
michael@0 306 };
michael@0 307
michael@0 308 reportCompare(
michael@0 309 "x|y|string|1|number|xyz|string|z",
michael@0 310 "xyz".replace("y", f),
michael@0 311 "Section 44"
michael@0 312 );
michael@0 313
michael@0 314 reportCompare(
michael@0 315 "x|(y)|string|1|number|x(y)z|string|z",
michael@0 316 "x(y)z".replace("(y)", f),
michael@0 317 "Section 45"
michael@0 318 );
michael@0 319
michael@0 320 reportCompare(
michael@0 321 "x|y*|string|1|number|xy*z|string|z",
michael@0 322 "xy*z".replace("y*", f),
michael@0 323 "Section 46"
michael@0 324 );
michael@0 325
michael@0 326 reportCompare(
michael@0 327 "12|3|string|2|number|12345|string|45",
michael@0 328 String.prototype.replace.call(1.2345e4, 3, f),
michael@0 329 "Section 47"
michael@0 330 );
michael@0 331
michael@0 332 reportCompare(
michael@0 333 "|x|string|0|number|xxx|string|xx",
michael@0 334 "xxx".replace(/^x/g, f),
michael@0 335 "Section 48"
michael@0 336 );
michael@0 337
michael@0 338 reportCompare(
michael@0 339 "xx|x|string|2|number|xxx|string|",
michael@0 340 "xxx".replace(/x$/g, f),
michael@0 341 "Section 49"
michael@0 342 );
michael@0 343
michael@0 344 f = function (sub, paren, offs, str) {
michael@0 345 return ["", sub, typeof sub, paren, typeof paren, offs, typeof offs,
michael@0 346 str, typeof str, ""].join("|");
michael@0 347 };
michael@0 348
michael@0 349 reportCompare(
michael@0 350 "xy|z|string|z|string|2|number|xyz|string|",
michael@0 351 "xyz".replace(/(z)/g, f),
michael@0 352 "Section 50"
michael@0 353 );
michael@0 354
michael@0 355 reportCompare(
michael@0 356 "xyz||string||string|3|number|xyz|string|",
michael@0 357 "xyz".replace(/($)/g, f),
michael@0 358 "Section 51"
michael@0 359 );
michael@0 360
michael@0 361 reportCompare(
michael@0 362 "|xy|string|y|string|0|number|xyz|string|z",
michael@0 363 "xyz".replace(/(?:x)(y)/g, f),
michael@0 364 "Section 52"
michael@0 365 );
michael@0 366
michael@0 367 reportCompare(
michael@0 368 "|x|string|x|string|0|number|xyz|string|yz",
michael@0 369 "xyz".replace(/((?=xy)x)/g, f),
michael@0 370 "Section 53"
michael@0 371 );
michael@0 372
michael@0 373 reportCompare(
michael@0 374 "|x|string|x|string|0|number|xyz|string|yz",
michael@0 375 "xyz".replace(/(x(?=y))/g, f),
michael@0 376 "Section 54"
michael@0 377 );
michael@0 378
michael@0 379 reportCompare(
michael@0 380 "x|y|string|y|string|1|number|xyz|string|z",
michael@0 381 "xyz".replace(/((?!x)y)/g, f),
michael@0 382 "Section 55"
michael@0 383 );
michael@0 384
michael@0 385 reportCompare(
michael@0 386 "|x|string|x|string|0|number|xyz|string|" +
michael@0 387 "|y|string||undefined|1|number|xyz|string|z",
michael@0 388 "xyz".replace(/y|(x)/g, f),
michael@0 389 "Section 56"
michael@0 390 );
michael@0 391
michael@0 392 reportCompare(
michael@0 393 "xy|z|string||string|2|number|xyz|string|",
michael@0 394 "xyz".replace(/(z?)z/, f),
michael@0 395 "Section 57"
michael@0 396 );
michael@0 397
michael@0 398 reportCompare(
michael@0 399 "xy|z|string||undefined|2|number|xyz|string|",
michael@0 400 "xyz".replace(/(z)?z/, f),
michael@0 401 "Section 58"
michael@0 402 );
michael@0 403
michael@0 404 reportCompare(
michael@0 405 "xy|z|string||undefined|2|number|xyz|string|",
michael@0 406 "xyz".replace(/(z)?\1z/, f),
michael@0 407 "Section 59"
michael@0 408 );
michael@0 409
michael@0 410 reportCompare(
michael@0 411 "xy|z|string||undefined|2|number|xyz|string|",
michael@0 412 "xyz".replace(/\1(z)?z/, f),
michael@0 413 "Section 60"
michael@0 414 );
michael@0 415
michael@0 416 reportCompare(
michael@0 417 "xy|z|string||string|2|number|xyz|string|",
michael@0 418 "xyz".replace(/(z?\1)z/, f),
michael@0 419 "Section 61"
michael@0 420 );
michael@0 421
michael@0 422 f = function (sub, paren1, paren2, offs, str) {
michael@0 423 return ["", sub, typeof sub, paren1, typeof paren1, paren2, typeof paren2,
michael@0 424 offs, typeof offs, str, typeof str, ""].join("|");
michael@0 425 };
michael@0 426
michael@0 427 reportCompare(
michael@0 428 "x|y|string|y|string||undefined|1|number|xyz|string|z",
michael@0 429 "xyz".replace(/(y)(\1)?/, f),
michael@0 430 "Section 62"
michael@0 431 );
michael@0 432
michael@0 433 reportCompare(
michael@0 434 "x|yy|string|y|string|y|string|1|number|xyyz|string|z",
michael@0 435 "xyyz".replace(/(y)(\1)?/g, f),
michael@0 436 "Section 63"
michael@0 437 );
michael@0 438
michael@0 439 reportCompare(
michael@0 440 "x|y|string|y|string||undefined|1|number|xyyz|string|" +
michael@0 441 "|y|string|y|string||undefined|2|number|xyyz|string|z",
michael@0 442 "xyyz".replace(/(y)(\1)??/g, f),
michael@0 443 "Section 64"
michael@0 444 );
michael@0 445
michael@0 446 reportCompare(
michael@0 447 "x|y|string|y|string|y|string|1|number|xyz|string|z",
michael@0 448 "xyz".replace(/(?=(y))(\1)?/, f),
michael@0 449 "Section 65"
michael@0 450 );
michael@0 451
michael@0 452 reportCompare(
michael@0 453 "xyy|z|string||undefined||string|3|number|xyyz|string|",
michael@0 454 "xyyz".replace(/(?!(y)y)(\1)z/, f),
michael@0 455 "Section 66"
michael@0 456 );
michael@0 457
michael@0 458 rex = RegExp(
michael@0 459 "()()()()()()()()()()" +
michael@0 460 "()()()()()()()()()()" +
michael@0 461 "()()()()()()()()()()" +
michael@0 462 "()()()()()()()()()()" +
michael@0 463 "()()()()()()()()()()" +
michael@0 464 "()()()()()()()()()()" +
michael@0 465 "()()()()()()()()()()" +
michael@0 466 "()()()()()()()()()()" +
michael@0 467 "()()()()()()()()()()" +
michael@0 468 "()()()()()()()()()()(z)?(y)");
michael@0 469 a = ["sub"];
michael@0 470 for (i = 1; i <= 102; ++i)
michael@0 471 a[i] = "p" + i;
michael@0 472 a[103] = "offs";
michael@0 473 a[104] = "str";
michael@0 474 a[105] = "return ['', sub, typeof sub, offs, typeof offs, str, typeof str, " +
michael@0 475 "p100, typeof p100, p101, typeof p101, p102, typeof p102, ''].join('|');";
michael@0 476 f = Function.apply(null, a);
michael@0 477 reportCompare(
michael@0 478 "x|y|string|1|number|xyz|string||string||undefined|y|string|z",
michael@0 479 "xyz".replace(rex, f),
michael@0 480 "Section 67"
michael@0 481 );
michael@0 482
michael@0 483 reportCompare(
michael@0 484 "undefined",
michael@0 485 "".replace(/.*/g, function () {}),
michael@0 486 "Section 68"
michael@0 487 );
michael@0 488
michael@0 489 reportCompare(
michael@0 490 "nullxnullynullznull",
michael@0 491 "xyz".replace(/.??/g, function () { return null; }),
michael@0 492 "Section 69"
michael@0 493 );
michael@0 494
michael@0 495 reportCompare(
michael@0 496 "111",
michael@0 497 "xyz".replace(/./g, function () { return 1; }),
michael@0 498 "Section 70"
michael@0 499 );

mercurial