Index: test/cctest/test-strings.cc |
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc |
index 17020a32542342344d5780bce911e3fd44f5725f..55c21417d0edeb5df29090f3280ac9580cc003bd 100644 |
--- a/test/cctest/test-strings.cc |
+++ b/test/cctest/test-strings.cc |
@@ -529,3 +529,32 @@ TEST(TrivialSlice) { |
CHECK(string->IsSlicedString()); |
CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
} |
+ |
+ |
+TEST(SliceFromSlice) { |
+ // This tests whether a slice that contains the entire parent string |
+ // actually creates a new string (it should not). |
+ FLAG_string_slices = true; |
+ InitializeVM(); |
+ HandleScope scope; |
+ v8::Local<v8::Value> result; |
+ Handle<String> string; |
+ const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
+ const char* slice = "var slice = str.slice(1,-1); slice"; |
+ const char* slice_from_slice = "slice.slice(1,-1);"; |
+ |
+ CompileRun(init); |
+ result = CompileRun(slice); |
+ CHECK(result->IsString()); |
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
+ CHECK(string->IsSlicedString()); |
+ CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
+ CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
+ |
+ result = CompileRun(slice_from_slice); |
+ CHECK(result->IsString()); |
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
+ CHECK(string->IsSlicedString()); |
+ CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
+ CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); |
+} |