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

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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