1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/String/replace-math.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,38 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +var BUGNUMBER = 805121; 1.10 +var summary = "Be more careful with string math to avoid wrong results"; 1.11 + 1.12 +print(BUGNUMBER + ": " + summary); 1.13 + 1.14 +/******************************************************************************/ 1.15 + 1.16 +function puff(x, n) 1.17 +{ 1.18 + while(x.length < n) 1.19 + x += x; 1.20 + return x.substring(0, n); 1.21 +} 1.22 + 1.23 +var x = puff("1", 1 << 20); 1.24 +var rep = puff("$1", 1 << 16); 1.25 + 1.26 +try 1.27 +{ 1.28 + var y = x.replace(/(.+)/g, rep); 1.29 + assertEq(y.length, Math.pow(2, 36)); 1.30 +} 1.31 +catch (e) 1.32 +{ 1.33 + // OOM also acceptable 1.34 +} 1.35 + 1.36 +/******************************************************************************/ 1.37 + 1.38 +if (typeof reportCompare === "function") 1.39 + reportCompare(true, true); 1.40 + 1.41 +print("Tests complete");