Home | History | Annotate | Download | only in resources
      1 description(
      2 'This test checks if repeated string concatenation causes an exception (and not a crash). From WebKit Bug <a href="http://bugs.webkit.org/show_bug.cgi?id=11131">Repeated string concatenation results in OOM crash</a>.'
      3 );
      4 
      5 shouldThrow('s = "a"; while (1) { s += s; }', '"Error: Out of memory"'); // Expand at end of string
      6 shouldThrow('s = "a"; while (1) { s += ("a" + s); }', '"Error: Out of memory"'); // Expand at beginning of string
      7 shouldThrow('s = "a"; while (1) { s = [s, s].join(); }', '"Error: Out of memory"'); // Expand using UString::append.
      8 
      9 debug('');
     10 debug(
     11 'We also verify that the the string is stil functional after the out of memory exception is raised.  In <a href="rdar://problem/5352887">rdar://problem/5352887</a>, accessing the string after the exception would crash.'
     12 );
     13 
     14 function ensureStringIsUsable(testName, stringName, str) {
     15     str[str.length - 1];
     16     try { [str, str].join(str); } catch (o) { }
     17     try { "a" + str; } catch (o) { }
     18     try { str + "a"; } catch (o) { }
     19     debug('PASS: String ' + stringName + ' was functional after ' + testName + ' raised out of memory exception.');
     20 }
     21 
     22 var s = "a";
     23 try {
     24     while (1)
     25         s += s; // This will expand the string at the end using UString::expandCapacity
     26 } catch (o) {
     27     ensureStringIsUsable('expandCapacity', 's', s);
     28 }
     29 
     30 s = "a";
     31 var t = "";
     32 try {
     33     while (1) {
     34         t = "a" + s;
     35         s += t; // This will expand the string at the beginning using UString::expandPreCapacity
     36     }
     37 } catch (o) {
     38     // Ensure both strings involved are unharmed
     39     ensureStringIsUsable('expandPreCapacity', 's', s);
     40     ensureStringIsUsable('expandPreCapacity', 't', t);
     41 }
     42 delete t;
     43 
     44 s = "a";
     45 try {
     46     while (1)
     47         s = [s, s].join(); // This will expand the string using UString::append.
     48 } catch (o) {
     49     ensureStringIsUsable('append', 's', s);
     50 }
     51 
     52 var successfullyParsed = true;
     53