js/src/tests/ecma_5/String/replace-math.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 var BUGNUMBER = 805121;
     7 var summary = "Be more careful with string math to avoid wrong results";
     9 print(BUGNUMBER + ": " + summary);
    11 /******************************************************************************/
    13 function puff(x, n)
    14 {
    15   while(x.length < n)
    16     x += x;
    17   return x.substring(0, n);
    18 }
    20 var x = puff("1", 1 << 20);
    21 var rep = puff("$1", 1 << 16);
    23 try
    24 {
    25   var y = x.replace(/(.+)/g, rep);
    26   assertEq(y.length, Math.pow(2, 36));
    27 }
    28 catch (e)
    29 {
    30   // OOM also acceptable
    31 }
    33 /******************************************************************************/
    35 if (typeof reportCompare === "function")
    36   reportCompare(true, true);
    38 print("Tests complete");

mercurial