Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: test/cctest/test-strings.cc

Issue 7860035: Merge bleeding edge up to 9192 into the GC branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/es5conform/es5conform.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 4d9b264e93f4099f28be3142fcd820fba365a10f..55c21417d0edeb5df29090f3280ac9580cc003bd 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -430,8 +430,7 @@ TEST(ExternalShortStringAdd) {
" return 0;"
"};"
"test()";
- CHECK_EQ(0,
- v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
+ CHECK_EQ(0, CompileRun(source)->Int32Value());
}
@@ -481,3 +480,81 @@ TEST(CachedHashOverflow) {
}
}
}
+
+
+TEST(SliceFromCons) {
+ FLAG_string_slices = true;
+ InitializeVM();
+ v8::HandleScope scope;
+ Handle<String> string =
+ FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
+ Handle<String> parent = FACTORY->NewConsString(string, string);
+ CHECK(parent->IsConsString());
+ CHECK(!parent->IsFlat());
+ Handle<String> slice = FACTORY->NewSubString(parent, 1, 25);
+ // After slicing, the original string becomes a flat cons.
+ CHECK(parent->IsFlat());
+ CHECK(slice->IsSlicedString());
+ CHECK_EQ(SlicedString::cast(*slice)->parent(),
+ ConsString::cast(*parent)->first());
+ CHECK(SlicedString::cast(*slice)->parent()->IsSeqString());
+ CHECK(slice->IsFlat());
+}
+
+
+TEST(TrivialSlice) {
+ // 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* check = "str.slice(0,26)";
+ const char* crosscheck = "str.slice(1,25)";
+
+ CompileRun(init);
+
+ result = CompileRun(check);
+ CHECK(result->IsString());
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result));
+ CHECK(!string->IsSlicedString());
+
+ string = FACTORY->NewSubString(string, 0, 26);
+ CHECK(!string->IsSlicedString());
+ result = CompileRun(crosscheck);
+ CHECK(result->IsString());
+ string = v8::Utils::OpenHandle(v8::String::Cast(*result));
+ 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()));
+}
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/es5conform/es5conform.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698