OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 CHECK(!string->IsSlicedString()); | 522 CHECK(!string->IsSlicedString()); |
523 | 523 |
524 string = FACTORY->NewSubString(string, 0, 26); | 524 string = FACTORY->NewSubString(string, 0, 26); |
525 CHECK(!string->IsSlicedString()); | 525 CHECK(!string->IsSlicedString()); |
526 result = CompileRun(crosscheck); | 526 result = CompileRun(crosscheck); |
527 CHECK(result->IsString()); | 527 CHECK(result->IsString()); |
528 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 528 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
529 CHECK(string->IsSlicedString()); | 529 CHECK(string->IsSlicedString()); |
530 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); | 530 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
531 } | 531 } |
| 532 |
| 533 |
| 534 TEST(SliceFromSlice) { |
| 535 // This tests whether a slice that contains the entire parent string |
| 536 // actually creates a new string (it should not). |
| 537 FLAG_string_slices = true; |
| 538 InitializeVM(); |
| 539 HandleScope scope; |
| 540 v8::Local<v8::Value> result; |
| 541 Handle<String> string; |
| 542 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
| 543 const char* slice = "var slice = str.slice(1,-1); slice"; |
| 544 const char* slice_from_slice = "slice.slice(1,-1);"; |
| 545 |
| 546 CompileRun(init); |
| 547 result = CompileRun(slice); |
| 548 CHECK(result->IsString()); |
| 549 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| 550 CHECK(string->IsSlicedString()); |
| 551 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
| 552 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
| 553 |
| 554 result = CompileRun(slice_from_slice); |
| 555 CHECK(result->IsString()); |
| 556 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| 557 CHECK(string->IsSlicedString()); |
| 558 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
| 559 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); |
| 560 } |
OLD | NEW |