Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / RegExp / regress-617935.js
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/licenses/publicdomain/
4  *
5  * Author: Christian Holler <decoder@own-hero.net>
6  */
7
8 /* Length of 32 */
9 var foo = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
10
11 /* Make len(foo) 32768 */
12 for (i = 0; i < 10; ++i) {
13     foo += foo;
14 }
15
16 /* Add one "a" to cause overflow later */
17 foo += "a";
18
19 var bar = "bbbbbbbbbbbbbbbb";
20
21 /* Make len(bar) 65536 */
22 for (i = 0; i < 12; ++i) {
23     bar += bar;
24 }
25
26 /* 
27  * Resulting string should be 
28  * len(foo)*len(bar) = (2^10 * 32 + 1) * 65536 = 2147549184 
29  * which will be negative as jsint
30  */
31 try {
32     foo.replace(/[a]/g, bar);
33 } catch (e) {
34     reportCompare(e instanceof InternalError, true, "Internal error due to overallocation is ok.");
35 }
36 reportCompare(true, true, "No crash occurred.");
37
38 print("All tests passed!");