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

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

Issue 12254007: Make the Isolate parameter mandatory for internal HandleScopes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 7 years, 10 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-serialize.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 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 // StringCharacterStram. Check that Get(int) works on very deep stacks 4 // StringCharacterStram. 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 static v8::Persistent<v8::Context> env; 73 static v8::Persistent<v8::Context> env;
74 74
75 75
76 static void InitializeVM() { 76 static void InitializeVM() {
77 if (env.IsEmpty()) { 77 if (env.IsEmpty()) {
78 v8::HandleScope scope; 78 v8::HandleScope scope;
79 const char* extensions[] = { "v8/print" }; 79 const char* extensions[] = { "v8/print" };
80 v8::ExtensionConfiguration config(1, extensions); 80 v8::ExtensionConfiguration config(1, extensions);
81 env = v8::Context::New(&config); 81 env = v8::Context::New(&config);
82 } 82 }
83 v8::HandleScope scope;
84 env->Enter(); 83 env->Enter();
85 } 84 }
86 85
87 86
88 static const int DEEP_DEPTH = 8 * 1024; 87 static const int DEEP_DEPTH = 8 * 1024;
89 static const int SUPER_DEEP_DEPTH = 80 * 1024; 88 static const int SUPER_DEEP_DEPTH = 80 * 1024;
90 89
91 90
92 class Resource: public v8::String::ExternalStringResource, 91 class Resource: public v8::String::ExternalStringResource,
93 public ZoneObject { 92 public ZoneObject {
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString()); 1091 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString());
1093 CHECK(slice->IsFlat()); 1092 CHECK(slice->IsFlat());
1094 } 1093 }
1095 1094
1096 1095
1097 TEST(TrivialSlice) { 1096 TEST(TrivialSlice) {
1098 // This tests whether a slice that contains the entire parent string 1097 // This tests whether a slice that contains the entire parent string
1099 // actually creates a new string (it should not). 1098 // actually creates a new string (it should not).
1100 FLAG_string_slices = true; 1099 FLAG_string_slices = true;
1101 InitializeVM(); 1100 InitializeVM();
1102 HandleScope scope; 1101 v8::HandleScope scope;
1103 v8::Local<v8::Value> result; 1102 v8::Local<v8::Value> result;
1104 Handle<String> string; 1103 Handle<String> string;
1105 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; 1104 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
1106 const char* check = "str.slice(0,26)"; 1105 const char* check = "str.slice(0,26)";
1107 const char* crosscheck = "str.slice(1,25)"; 1106 const char* crosscheck = "str.slice(1,25)";
1108 1107
1109 CompileRun(init); 1108 CompileRun(init);
1110 1109
1111 result = CompileRun(check); 1110 result = CompileRun(check);
1112 CHECK(result->IsString()); 1111 CHECK(result->IsString());
1113 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1112 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1114 CHECK(!string->IsSlicedString()); 1113 CHECK(!string->IsSlicedString());
1115 1114
1116 string = FACTORY->NewSubString(string, 0, 26); 1115 string = FACTORY->NewSubString(string, 0, 26);
1117 CHECK(!string->IsSlicedString()); 1116 CHECK(!string->IsSlicedString());
1118 result = CompileRun(crosscheck); 1117 result = CompileRun(crosscheck);
1119 CHECK(result->IsString()); 1118 CHECK(result->IsString());
1120 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1119 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1121 CHECK(string->IsSlicedString()); 1120 CHECK(string->IsSlicedString());
1122 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); 1121 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
1123 } 1122 }
1124 1123
1125 1124
1126 TEST(SliceFromSlice) { 1125 TEST(SliceFromSlice) {
1127 // This tests whether a slice that contains the entire parent string 1126 // This tests whether a slice that contains the entire parent string
1128 // actually creates a new string (it should not). 1127 // actually creates a new string (it should not).
1129 FLAG_string_slices = true; 1128 FLAG_string_slices = true;
1130 InitializeVM(); 1129 InitializeVM();
1131 HandleScope scope; 1130 v8::HandleScope scope;
1132 v8::Local<v8::Value> result; 1131 v8::Local<v8::Value> result;
1133 Handle<String> string; 1132 Handle<String> string;
1134 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; 1133 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
1135 const char* slice = "var slice = str.slice(1,-1); slice"; 1134 const char* slice = "var slice = str.slice(1,-1); slice";
1136 const char* slice_from_slice = "slice.slice(1,-1);"; 1135 const char* slice_from_slice = "slice.slice(1,-1);";
1137 1136
1138 CompileRun(init); 1137 CompileRun(init);
1139 result = CompileRun(slice); 1138 result = CompileRun(slice);
1140 CHECK(result->IsString()); 1139 CHECK(result->IsString());
1141 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1140 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // An empty handle is returned upon exception. 1188 // An empty handle is returned upon exception.
1190 CHECK(CompileRun(source).IsEmpty()); 1189 CHECK(CompileRun(source).IsEmpty());
1191 } 1190 }
1192 1191
1193 1192
1194 TEST(RobustSubStringStub) { 1193 TEST(RobustSubStringStub) {
1195 // This tests whether the SubStringStub can handle unsafe arguments. 1194 // This tests whether the SubStringStub can handle unsafe arguments.
1196 // If not recognized, those unsafe arguments lead to out-of-bounds reads. 1195 // If not recognized, those unsafe arguments lead to out-of-bounds reads.
1197 FLAG_allow_natives_syntax = true; 1196 FLAG_allow_natives_syntax = true;
1198 InitializeVM(); 1197 InitializeVM();
1199 HandleScope scope; 1198 v8::HandleScope scope;
1200 v8::Local<v8::Value> result; 1199 v8::Local<v8::Value> result;
1201 Handle<String> string; 1200 Handle<String> string;
1202 CompileRun("var short = 'abcdef';"); 1201 CompileRun("var short = 'abcdef';");
1203 1202
1204 // Invalid indices. 1203 // Invalid indices.
1205 CheckException("%_SubString(short, 0, 10000);"); 1204 CheckException("%_SubString(short, 0, 10000);");
1206 CheckException("%_SubString(short, -1234, 5);"); 1205 CheckException("%_SubString(short, -1234, 5);");
1207 CheckException("%_SubString(short, 5, 2);"); 1206 CheckException("%_SubString(short, 5, 2);");
1208 // Special HeapNumbers. 1207 // Special HeapNumbers.
1209 CheckException("%_SubString(short, 1, Infinity);"); 1208 CheckException("%_SubString(short, 1, Infinity);");
(...skipping 23 matching lines...) Expand all
1233 // Test that out-of-bounds substring of a slice fails when the indices 1232 // Test that out-of-bounds substring of a slice fails when the indices
1234 // would have been valid for the underlying string. 1233 // would have been valid for the underlying string.
1235 CompileRun("var slice = long.slice(1, 15);"); 1234 CompileRun("var slice = long.slice(1, 15);");
1236 CheckException("%_SubString(slice, 0, 17);"); 1235 CheckException("%_SubString(slice, 0, 17);");
1237 } 1236 }
1238 1237
1239 1238
1240 TEST(RegExpOverflow) { 1239 TEST(RegExpOverflow) {
1241 // Result string has the length 2^32, causing a 32-bit integer overflow. 1240 // Result string has the length 2^32, causing a 32-bit integer overflow.
1242 InitializeVM(); 1241 InitializeVM();
1243 HandleScope scope; 1242 v8::HandleScope scope;
1244 LocalContext context; 1243 LocalContext context;
1245 v8::V8::IgnoreOutOfMemoryException(); 1244 v8::V8::IgnoreOutOfMemoryException();
1246 v8::Local<v8::Value> result = CompileRun( 1245 v8::Local<v8::Value> result = CompileRun(
1247 "var a = 'a'; " 1246 "var a = 'a'; "
1248 "for (var i = 0; i < 16; i++) { " 1247 "for (var i = 0; i < 16; i++) { "
1249 " a += a; " 1248 " a += a; "
1250 "} " 1249 "} "
1251 "a.replace(/a/g, a); "); 1250 "a.replace(/a/g, a); ");
1252 CHECK(result.IsEmpty()); 1251 CHECK(result.IsEmpty());
1253 CHECK(context->HasOutOfMemoryException()); 1252 CHECK(context->HasOutOfMemoryException());
1254 } 1253 }
1255 1254
1256 1255
1257 TEST(StringReplaceAtomTwoByteResult) { 1256 TEST(StringReplaceAtomTwoByteResult) {
1258 InitializeVM(); 1257 InitializeVM();
1259 HandleScope scope; 1258 v8::HandleScope scope;
1260 LocalContext context; 1259 LocalContext context;
1261 v8::Local<v8::Value> result = CompileRun( 1260 v8::Local<v8::Value> result = CompileRun(
1262 "var subject = 'ascii~only~string~'; " 1261 "var subject = 'ascii~only~string~'; "
1263 "var replace = '\x80'; " 1262 "var replace = '\x80'; "
1264 "subject.replace(/~/g, replace); "); 1263 "subject.replace(/~/g, replace); ");
1265 CHECK(result->IsString()); 1264 CHECK(result->IsString());
1266 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1265 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1267 CHECK(string->IsSeqTwoByteString()); 1266 CHECK(string->IsSeqTwoByteString());
1268 1267
1269 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); 1268 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 continue; 1326 continue;
1328 } 1327 }
1329 if (upper != c && lower != c) { 1328 if (upper != c && lower != c) {
1330 CheckCanonicalEquivalence(c, test); 1329 CheckCanonicalEquivalence(c, test);
1331 continue; 1330 continue;
1332 } 1331 }
1333 CHECK_EQ(Min(upper, lower), test); 1332 CHECK_EQ(Min(upper, lower), test);
1334 } 1333 }
1335 } 1334 }
1336 #endif // ENABLE_LATIN_1 1335 #endif // ENABLE_LATIN_1
OLDNEW
« no previous file with comments | « test/cctest/test-serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698