OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 | 2 |
3 // Check that we can traverse very deep stacks of ConsStrings using | 3 // Check that we can traverse very deep stacks of ConsStrings using |
4 // StringInputBuffer. Check that Get(int) works on very deep stacks | 4 // StringInputBuffer. Check that Get(int) works on very deep stacks |
5 // of ConsStrings. These operations may not be very fast, but they | 5 // of ConsStrings. These operations may not be very fast, but they |
6 // should be possible without getting errors due to too deep recursion. | 6 // should be possible without getting errors due to too deep recursion. |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "v8.h" | 10 #include "v8.h" |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); | 580 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
581 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); | 581 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
582 | 582 |
583 result = CompileRun(slice_from_slice); | 583 result = CompileRun(slice_from_slice); |
584 CHECK(result->IsString()); | 584 CHECK(result->IsString()); |
585 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 585 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
586 CHECK(string->IsSlicedString()); | 586 CHECK(string->IsSlicedString()); |
587 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); | 587 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
588 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); | 588 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); |
589 } | 589 } |
| 590 |
| 591 |
| 592 // string s is made of 2^17 = 131072 'c' characters. |
| 593 // a is an array starting with 'bad', followed by 2^14 times the string s. |
| 594 // That means the total length of the concatenated strings is 2^31 + 3. |
| 595 // So on 32bits systems summing the lengths of the strings (as smis) overflows |
| 596 // and wraps. |
| 597 static const char* join_causing_out_of_memory = |
| 598 "var two_14 = Math.pow(2, 14);" |
| 599 "var two_17 = Math.pow(2, 17);" |
| 600 "var s = Array(two_17 + 1).join('c');" |
| 601 "var a = ['bad'];" |
| 602 "for (var i = 1; i <= two_14; i++) a.push(s);" |
| 603 "a.join("");"; |
| 604 |
| 605 |
| 606 TEST(AsciiArrayJoin) { |
| 607 // Set heap limits. |
| 608 static const int K = 1024; |
| 609 v8::ResourceConstraints constraints; |
| 610 constraints.set_max_young_space_size(256 * K); |
| 611 constraints.set_max_old_space_size(4 * K * K); |
| 612 v8::SetResourceConstraints(&constraints); |
| 613 |
| 614 v8::HandleScope scope; |
| 615 LocalContext context; |
| 616 v8::V8::IgnoreOutOfMemoryException(); |
| 617 v8::Local<v8::Script> script = |
| 618 v8::Script::Compile(v8::String::New(join_causing_out_of_memory)); |
| 619 v8::Local<v8::Value> result = script->Run(); |
| 620 |
| 621 // Check for out of memory state. |
| 622 CHECK(result.IsEmpty()); |
| 623 CHECK(context->HasOutOfMemoryException()); |
| 624 } |
OLD | NEW |