michael@0: // |reftest| skip-if(!xulRuntime.shell&&(Android||xulRuntime.OS=="WINNT")) silentfail michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * michael@0: * Author: Christian Holler michael@0: */ michael@0: michael@0: expectExitCode(0); michael@0: expectExitCode(5); michael@0: michael@0: /* Length of 32 */ michael@0: var foo = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; michael@0: michael@0: /* Make len(foo) 32768 */ michael@0: for (i = 0; i < 10; ++i) { michael@0: foo += foo; michael@0: } michael@0: michael@0: /* Add one "a" to cause overflow later */ michael@0: foo += "a"; michael@0: michael@0: var bar = "bbbbbbbbbbbbbbbb"; michael@0: michael@0: /* Make len(bar) 8192 */ michael@0: for (i = 0; i < 9; ++i) { michael@0: bar += bar; michael@0: } michael@0: michael@0: /* michael@0: * Resulting string should be michael@0: * len(foo) * len(bar) = (2**10 * 32 + 1) * 8192 = 268443648 michael@0: * which will be larger than the max string length (2**28, or 268435456). michael@0: */ michael@0: try { michael@0: foo.replace(/[a]/g, bar); michael@0: } catch (e) { michael@0: reportCompare(e instanceof InternalError, true, "Internal error due to overallocation is ok."); michael@0: } michael@0: reportCompare(true, true, "No crash occurred."); michael@0: michael@0: print("Tests complete");