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

Side by Side Diff: test/cctest/test-strings.cc

Issue 23519010: cleanup cctest generally and remove ctest::context (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: arm fix Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 for (int j = lengths[i]; j < 11; j++) 926 for (int j = lengths[i]; j < 11; j++)
927 CHECK_EQ(kNoChar, buffer[j]); 927 CHECK_EQ(kNoChar, buffer[j]);
928 } 928 }
929 } 929 }
930 930
931 931
932 TEST(ExternalShortStringAdd) { 932 TEST(ExternalShortStringAdd) {
933 Isolate* isolate = CcTest::i_isolate(); 933 Isolate* isolate = CcTest::i_isolate();
934 Zone zone(isolate); 934 Zone zone(isolate);
935 935
936 CcTest::InitializeVM(); 936 LocalContext context;
937 v8::HandleScope handle_scope(CcTest::isolate()); 937 v8::HandleScope handle_scope(CcTest::isolate());
938 938
939 // Make sure we cover all always-flat lengths and at least one above. 939 // Make sure we cover all always-flat lengths and at least one above.
940 static const int kMaxLength = 20; 940 static const int kMaxLength = 20;
941 CHECK_GT(kMaxLength, i::ConsString::kMinLength); 941 CHECK_GT(kMaxLength, i::ConsString::kMinLength);
942 942
943 // Allocate two JavaScript arrays for holding short strings. 943 // Allocate two JavaScript arrays for holding short strings.
944 v8::Handle<v8::Array> ascii_external_strings = 944 v8::Handle<v8::Array> ascii_external_strings =
945 v8::Array::New(kMaxLength + 1); 945 v8::Array::New(kMaxLength + 1);
946 v8::Handle<v8::Array> non_ascii_external_strings = 946 v8::Handle<v8::Array> non_ascii_external_strings =
(...skipping 20 matching lines...) Expand all
967 // Terminating '\0' is left out on purpose. It is not required for external 967 // Terminating '\0' is left out on purpose. It is not required for external
968 // string data. 968 // string data.
969 Resource* resource = new(&zone) Resource(Vector<const uc16>(non_ascii, i)); 969 Resource* resource = new(&zone) Resource(Vector<const uc16>(non_ascii, i));
970 v8::Local<v8::String> non_ascii_external_string = 970 v8::Local<v8::String> non_ascii_external_string =
971 v8::String::NewExternal(resource); 971 v8::String::NewExternal(resource);
972 non_ascii_external_strings->Set(v8::Integer::New(i), 972 non_ascii_external_strings->Set(v8::Integer::New(i),
973 non_ascii_external_string); 973 non_ascii_external_string);
974 } 974 }
975 975
976 // Add the arrays with the short external strings in the global object. 976 // Add the arrays with the short external strings in the global object.
977 v8::Handle<v8::Object> global = CcTest::env()->Global(); 977 v8::Handle<v8::Object> global = context->Global();
978 global->Set(v8_str("external_ascii"), ascii_external_strings); 978 global->Set(v8_str("external_ascii"), ascii_external_strings);
979 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings); 979 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings);
980 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength)); 980 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength));
981 981
982 // Add short external ascii and non-ascii strings checking the result. 982 // Add short external ascii and non-ascii strings checking the result.
983 static const char* source = 983 static const char* source =
984 "function test() {" 984 "function test() {"
985 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';" 985 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';"
986 " var non_ascii_chars = '\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\ \u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1 234\\u1234';" //NOLINT 986 " var non_ascii_chars = '\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\ \u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1 234\\u1234';" //NOLINT
987 " if (ascii_chars.length != max_length) return 1;" 987 " if (ascii_chars.length != max_length) return 1;"
(...skipping 23 matching lines...) Expand all
1011 " }" 1011 " }"
1012 " }" 1012 " }"
1013 " return 0;" 1013 " return 0;"
1014 "};" 1014 "};"
1015 "test()"; 1015 "test()";
1016 CHECK_EQ(0, CompileRun(source)->Int32Value()); 1016 CHECK_EQ(0, CompileRun(source)->Int32Value());
1017 } 1017 }
1018 1018
1019 1019
1020 TEST(JSONStringifySliceMadeExternal) { 1020 TEST(JSONStringifySliceMadeExternal) {
1021 CcTest::InitializeVM();
1021 Isolate* isolate = CcTest::i_isolate(); 1022 Isolate* isolate = CcTest::i_isolate();
1022 Zone zone(isolate); 1023 Zone zone(isolate);
1023 CcTest::InitializeVM();
1024 // Create a sliced string from a one-byte string. The latter is turned 1024 // Create a sliced string from a one-byte string. The latter is turned
1025 // into a two-byte external string. Check that JSON.stringify works. 1025 // into a two-byte external string. Check that JSON.stringify works.
1026 v8::HandleScope handle_scope(CcTest::isolate()); 1026 v8::HandleScope handle_scope(CcTest::isolate());
1027 v8::Handle<v8::String> underlying = 1027 v8::Handle<v8::String> underlying =
1028 CompileRun("var underlying = 'abcdefghijklmnopqrstuvwxyz';" 1028 CompileRun("var underlying = 'abcdefghijklmnopqrstuvwxyz';"
1029 "underlying")->ToString(); 1029 "underlying")->ToString();
1030 v8::Handle<v8::String> slice = 1030 v8::Handle<v8::String> slice =
1031 CompileRun("var slice = underlying.slice(1);" 1031 CompileRun("var slice = underlying.slice(1);"
1032 "slice")->ToString(); 1032 "slice")->ToString();
1033 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); 1033 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1034 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString()); 1034 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString());
1035 1035
1036 int length = underlying->Length(); 1036 int length = underlying->Length();
1037 uc16* two_byte = zone.NewArray<uc16>(length + 1); 1037 uc16* two_byte = zone.NewArray<uc16>(length + 1);
1038 underlying->Write(two_byte); 1038 underlying->Write(two_byte);
1039 Resource* resource = 1039 Resource* resource =
1040 new(&zone) Resource(Vector<const uc16>(two_byte, length)); 1040 new(&zone) Resource(Vector<const uc16>(two_byte, length));
1041 CHECK(underlying->MakeExternal(resource)); 1041 CHECK(underlying->MakeExternal(resource));
1042 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); 1042 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1043 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString()); 1043 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString());
1044 1044
1045 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"", 1045 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"",
1046 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)"))); 1046 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)")));
1047 } 1047 }
1048 1048
1049 1049
1050 TEST(CachedHashOverflow) { 1050 TEST(CachedHashOverflow) {
1051 CcTest::InitializeVM();
1051 // We incorrectly allowed strings to be tagged as array indices even if their 1052 // We incorrectly allowed strings to be tagged as array indices even if their
1052 // values didn't fit in the hash field. 1053 // values didn't fit in the hash field.
1053 // See http://code.google.com/p/v8/issues/detail?id=728 1054 // See http://code.google.com/p/v8/issues/detail?id=728
1054 Isolate* isolate = CcTest::i_isolate(); 1055 Isolate* isolate = CcTest::i_isolate();
1055 Zone zone(isolate); 1056 Zone zone(isolate);
1056 1057
1057 CcTest::InitializeVM();
1058 v8::HandleScope handle_scope(CcTest::isolate()); 1058 v8::HandleScope handle_scope(CcTest::isolate());
1059 // Lines must be executed sequentially. Combining them into one script 1059 // Lines must be executed sequentially. Combining them into one script
1060 // makes the bug go away. 1060 // makes the bug go away.
1061 const char* lines[] = { 1061 const char* lines[] = {
1062 "var x = [];", 1062 "var x = [];",
1063 "x[4] = 42;", 1063 "x[4] = 42;",
1064 "var s = \"1073741828\";", 1064 "var s = \"1073741828\";",
1065 "x[s];", 1065 "x[s];",
1066 "x[s] = 37;", 1066 "x[s] = 37;",
1067 "x[4];", 1067 "x[4];",
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 CheckCanonicalEquivalence(c, test); 1379 CheckCanonicalEquivalence(c, test);
1380 continue; 1380 continue;
1381 } 1381 }
1382 if (upper != c && lower != c) { 1382 if (upper != c && lower != c) {
1383 CheckCanonicalEquivalence(c, test); 1383 CheckCanonicalEquivalence(c, test);
1384 continue; 1384 continue;
1385 } 1385 }
1386 CHECK_EQ(Min(upper, lower), test); 1386 CHECK_EQ(Min(upper, lower), test);
1387 } 1387 }
1388 } 1388 }
OLDNEW
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698