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.

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

mercurial