1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is
18 * Portions created by the Initial Developer are Copyright (C) 2008
19 * the Initial Developer. All Rights Reserved.
22 * <x00000000@freenet.de>
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 ***** */
38 var BUGNUMBER = 392378;
39 var summary = '15.5.4.11 - String.prototype.replace';
44 String.prototype.replace.length,
50 String.prototype.replace.call(123, "123", "321"),
68 "xyz".replace("y", null),
74 "xyz".replace("yz", 123),
80 "xxx".replace(/x/g, /x/g),
86 "undefined".replace(undefined, "ok"),
92 "null".replace(null, "ok"),
98 "123".replace(123, "ok"),
104 "xyzxyz".replace("yz", "zy"),
110 "(xyz)".replace("(xyz)", "ok"),
116 "xyzxyz".replace("x", "*$$&"),
122 "xyz".replace("z", "*$&*"),
128 "xyzxyzxyz".replace("zxy", "$`"),
134 "xyzxyz".replace("xy", "$'xyz"),
140 "xyzxyz".replace("xyzxyz", "$"),
146 "xyzxyz".replace("yz", "$0$00"),
150 // Result for $1/$01 .. $99 is implementation-defined if searchValue is no
151 // regular expression. $+ is a non-standard Mozilla extension.
154 "$!$\"$-1$*$#$.$xyz$$",
155 "xyzxyz$$".replace("xyz", "$!$\"$-1$*$#$.$"),
161 "$$$&".replace("$$", "$$$$$$&$&$$&"),
167 "xxx".replace(/x/, "y"),
173 "xxx".replace(/x/g, "y"),
177 rex = /x/, rex.lastIndex = 1;
180 "xxx".replace(rex, "y") + rex.lastIndex,
184 rex = /x/g, rex.lastIndex = 1;
187 "xxx".replace(rex, "y") + rex.lastIndex,
191 rex = /y/, rex.lastIndex = 1;
194 "xxx".replace(rex, "y") + rex.lastIndex,
198 rex = /y/g, rex.lastIndex = 1;
201 "xxx".replace(rex, "y") + rex.lastIndex,
205 rex = /x?/, rex.lastIndex = 1;
208 "xxx".replace(rex, "($&)") + rex.lastIndex,
212 rex = /x?/g, rex.lastIndex = 1;
215 "xxx".replace(rex, "($&)") + rex.lastIndex,
219 rex = /y?/, rex.lastIndex = 1;
222 "xxx".replace(rex, "($&)") + rex.lastIndex,
226 rex = /y?/g, rex.lastIndex = 1;
229 "xxx".replace(rex, "($&)") + rex.lastIndex,
234 "xy$0xy$zxy$zxyz$zxyz",
235 "xyzxyzxyz".replace(/zxy/, "$0$`$$$&$$$'$"),
240 "xy$0xy$zxy$zxyz$$0xyzxy$zxy$z$z",
241 "xyzxyzxyz".replace(/zxy/g, "$0$`$$$&$$$'$"),
247 "xyzxyz".replace(/(((x)(y)()()))()()()(z)/g, "$01$2$3$04$5$6$7$8$09$10"),
252 "()()()()()()()()()()" +
253 "()()()()()()()()()()" +
254 "()()()()()()()()()()" +
255 "()()()()()()()()()()" +
256 "()()()()()()()()()()" +
257 "()()()()()()()()()()" +
258 "()()()()()()()()()()" +
259 "()()()()()()()()()()" +
260 "()()()()()()()()()()" +
261 "()()()()()()()()(y)");
264 "xyz".replace(rex, "($99)"),
269 "()()()()()()()()()(x)" +
270 "()()()()()()()()()()" +
271 "()()()()()()()()()()" +
272 "()()()()()()()()()()" +
273 "()()()()()()()()()()" +
274 "()()()()()()()()()()" +
275 "()()()()()()()()()()" +
276 "()()()()()()()()()()" +
277 "()()()()()()()()()()" +
278 "()()()()()()()()()(y)");
281 "xyz".replace(rex, "($100)"),
287 "xyzXYZ".replace(/XYZ/g, "($&)"),
293 "xyzXYZ".replace(/xYz/gi, "($&)"),
299 "xyz\rxyz\n".replace(/xyz$/g, "($&)"),
305 "xyz\rxyz\n".replace(/xyz$/gm, "($&)"),
309 f = function () { return "failure" };
313 "ok".replace("x", f),
319 "ok".replace(/(?=k)ok/, f),
325 "ok".replace(/(?!)ok/, f),
331 "ok".replace(/ok(?!$)/, f),
335 f = function (sub, offs, str) {
336 return ["", sub, typeof sub, offs, typeof offs, str, typeof str, ""]
341 "x|y|string|1|number|xyz|string|z",
342 "xyz".replace("y", f),
347 "x|(y)|string|1|number|x(y)z|string|z",
348 "x(y)z".replace("(y)", f),
353 "x|y*|string|1|number|xy*z|string|z",
354 "xy*z".replace("y*", f),
359 "12|3|string|2|number|12345|string|45",
360 String.prototype.replace.call(1.2345e4, 3, f),
365 "|x|string|0|number|xxx|string|xx",
366 "xxx".replace(/^x/g, f),
371 "xx|x|string|2|number|xxx|string|",
372 "xxx".replace(/x$/g, f),
376 f = function (sub, paren, offs, str) {
377 return ["", sub, typeof sub, paren, typeof paren, offs, typeof offs,
378 str, typeof str, ""].join("|");
382 "xy|z|string|z|string|2|number|xyz|string|",
383 "xyz".replace(/(z)/g, f),
388 "xyz||string||string|3|number|xyz|string|",
389 "xyz".replace(/($)/g, f),
394 "|xy|string|y|string|0|number|xyz|string|z",
395 "xyz".replace(/(?:x)(y)/g, f),
400 "|x|string|x|string|0|number|xyz|string|yz",
401 "xyz".replace(/((?=xy)x)/g, f),
406 "|x|string|x|string|0|number|xyz|string|yz",
407 "xyz".replace(/(x(?=y))/g, f),
412 "x|y|string|y|string|1|number|xyz|string|z",
413 "xyz".replace(/((?!x)y)/g, f),
418 "|x|string|x|string|0|number|xyz|string|" +
419 "|y|string||undefined|1|number|xyz|string|z",
420 "xyz".replace(/y|(x)/g, f),
425 "xy|z|string||string|2|number|xyz|string|",
426 "xyz".replace(/(z?)z/, f),
431 "xy|z|string||undefined|2|number|xyz|string|",
432 "xyz".replace(/(z)?z/, f),
437 "xy|z|string||undefined|2|number|xyz|string|",
438 "xyz".replace(/(z)?\1z/, f),
443 "xy|z|string||undefined|2|number|xyz|string|",
444 "xyz".replace(/\1(z)?z/, f),
449 "xy|z|string||string|2|number|xyz|string|",
450 "xyz".replace(/(z?\1)z/, f),
454 f = function (sub, paren1, paren2, offs, str) {
455 return ["", sub, typeof sub, paren1, typeof paren1, paren2, typeof paren2,
456 offs, typeof offs, str, typeof str, ""].join("|");
460 "x|y|string|y|string||undefined|1|number|xyz|string|z",
461 "xyz".replace(/(y)(\1)?/, f),
466 "x|yy|string|y|string|y|string|1|number|xyyz|string|z",
467 "xyyz".replace(/(y)(\1)?/g, f),
472 "x|y|string|y|string||undefined|1|number|xyyz|string|" +
473 "|y|string|y|string||undefined|2|number|xyyz|string|z",
474 "xyyz".replace(/(y)(\1)??/g, f),
479 "x|y|string|y|string|y|string|1|number|xyz|string|z",
480 "xyz".replace(/(?=(y))(\1)?/, f),
485 "xyy|z|string||undefined||string|3|number|xyyz|string|",
486 "xyyz".replace(/(?!(y)y)(\1)z/, f),
491 "()()()()()()()()()()" +
492 "()()()()()()()()()()" +
493 "()()()()()()()()()()" +
494 "()()()()()()()()()()" +
495 "()()()()()()()()()()" +
496 "()()()()()()()()()()" +
497 "()()()()()()()()()()" +
498 "()()()()()()()()()()" +
499 "()()()()()()()()()()" +
500 "()()()()()()()()()()(z)?(y)");
502 for (i = 1; i <= 102; ++i)
506 a[105] = "return ['', sub, typeof sub, offs, typeof offs, str, typeof str, " +
507 "p100, typeof p100, p101, typeof p101, p102, typeof p102, ''].join('|');";
508 f = Function.apply(null, a);
510 "x|y|string|1|number|xyz|string||string||undefined|y|string|z",
511 "xyz".replace(rex, f),
517 "".replace(/.*/g, function () {}),
522 "nullxnullynullznull",
523 "xyz".replace(/.??/g, function () { return null; }),
529 "xyz".replace(/./g, function () { return 1; }),