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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { | 208 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { |
209 int i = 0; | 209 int i = 0; |
210 buffer.Reset(*s1); | 210 buffer.Reset(*s1); |
211 StringInputBuffer buffer2(*s2); | 211 StringInputBuffer buffer2(*s2); |
212 while (buffer.has_more() && i < chars) { | 212 while (buffer.has_more() && i < chars) { |
213 CHECK(buffer2.has_more()); | 213 CHECK(buffer2.has_more()); |
214 uint16_t c = buffer.GetNext(); | 214 uint16_t c = buffer.GetNext(); |
215 CHECK_EQ(c, buffer2.GetNext()); | 215 CHECK_EQ(c, buffer2.GetNext()); |
216 i++; | 216 i++; |
217 } | 217 } |
218 StringShape shape1(*s1); | 218 s1->Get(StringShape(*s1), s1->length() - 1); |
219 StringShape shape2(*s2); | 219 s2->Get(StringShape(*s2), s2->length() - 1); |
220 s1->Get(shape1, s1->length(shape1) - 1); | |
221 s2->Get(shape2, s2->length(shape2) - 1); | |
222 } | 220 } |
223 | 221 |
224 | 222 |
225 TEST(Traverse) { | 223 TEST(Traverse) { |
226 printf("TestTraverse\n"); | 224 printf("TestTraverse\n"); |
227 InitializeVM(); | 225 InitializeVM(); |
228 v8::HandleScope scope; | 226 v8::HandleScope scope; |
229 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; | 227 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; |
230 InitializeBuildingBlocks(building_blocks); | 228 InitializeBuildingBlocks(building_blocks); |
231 Handle<String> flat = ConstructBalanced(building_blocks); | 229 Handle<String> flat = ConstructBalanced(building_blocks); |
(...skipping 12 matching lines...) Expand all Loading... |
244 ConstructLeft(building_blocks, SUPER_DEEP_DEPTH); | 242 ConstructLeft(building_blocks, SUPER_DEEP_DEPTH); |
245 Handle<String> right_deep_asymmetric = | 243 Handle<String> right_deep_asymmetric = |
246 ConstructRight(building_blocks, SUPER_DEEP_DEPTH); | 244 ConstructRight(building_blocks, SUPER_DEEP_DEPTH); |
247 printf("5\n"); | 245 printf("5\n"); |
248 TraverseFirst(left_asymmetric, left_deep_asymmetric, 1050); | 246 TraverseFirst(left_asymmetric, left_deep_asymmetric, 1050); |
249 printf("6\n"); | 247 printf("6\n"); |
250 TraverseFirst(left_asymmetric, right_deep_asymmetric, 65536); | 248 TraverseFirst(left_asymmetric, right_deep_asymmetric, 65536); |
251 printf("7\n"); | 249 printf("7\n"); |
252 Handle<String> right_deep_slice = | 250 Handle<String> right_deep_slice = |
253 Factory::NewStringSlice(left_deep_asymmetric, | 251 Factory::NewStringSlice(left_deep_asymmetric, |
254 StringShape(*left_deep_asymmetric), | |
255 left_deep_asymmetric->length() - 1050, | 252 left_deep_asymmetric->length() - 1050, |
256 left_deep_asymmetric->length() - 50); | 253 left_deep_asymmetric->length() - 50); |
257 Handle<String> left_deep_slice = | 254 Handle<String> left_deep_slice = |
258 Factory::NewStringSlice(right_deep_asymmetric, | 255 Factory::NewStringSlice(right_deep_asymmetric, |
259 StringShape(*right_deep_asymmetric), | |
260 right_deep_asymmetric->length() - 1050, | 256 right_deep_asymmetric->length() - 1050, |
261 right_deep_asymmetric->length() - 50); | 257 right_deep_asymmetric->length() - 50); |
262 printf("8\n"); | 258 printf("8\n"); |
263 Traverse(right_deep_slice, left_deep_slice); | 259 Traverse(right_deep_slice, left_deep_slice); |
264 printf("9\n"); | 260 printf("9\n"); |
265 FlattenString(left_asymmetric); | 261 FlattenString(left_asymmetric); |
266 printf("10\n"); | 262 printf("10\n"); |
267 Traverse(flat, left_asymmetric); | 263 Traverse(flat, left_asymmetric); |
268 printf("11\n"); | 264 printf("11\n"); |
269 FlattenString(right_asymmetric); | 265 FlattenString(right_asymmetric); |
270 printf("12\n"); | 266 printf("12\n"); |
271 Traverse(flat, right_asymmetric); | 267 Traverse(flat, right_asymmetric); |
272 printf("14\n"); | 268 printf("14\n"); |
273 FlattenString(symmetric); | 269 FlattenString(symmetric); |
274 printf("15\n"); | 270 printf("15\n"); |
275 Traverse(flat, symmetric); | 271 Traverse(flat, symmetric); |
276 printf("16\n"); | 272 printf("16\n"); |
277 FlattenString(left_deep_asymmetric); | 273 FlattenString(left_deep_asymmetric); |
278 printf("18\n"); | 274 printf("18\n"); |
279 } | 275 } |
280 | 276 |
281 | 277 |
282 static Handle<String> SliceOf(Handle<String> underlying) { | 278 static Handle<String> SliceOf(Handle<String> underlying) { |
283 int start = gen() % underlying->length(); | 279 int start = gen() % underlying->length(); |
284 int end = start + gen() % (underlying->length() - start); | 280 int end = start + gen() % (underlying->length() - start); |
285 return Factory::NewStringSlice(underlying, | 281 return Factory::NewStringSlice(underlying, |
286 StringShape(*underlying), | |
287 start, | 282 start, |
288 end); | 283 end); |
289 } | 284 } |
290 | 285 |
291 | 286 |
292 static Handle<String> ConstructSliceTree( | 287 static Handle<String> ConstructSliceTree( |
293 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], | 288 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], |
294 int from, | 289 int from, |
295 int to) { | 290 int to) { |
296 ASSERT(to > from); | 291 ASSERT(to > from); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 int written = mixed->WriteUtf8(buffer, i); | 399 int written = mixed->WriteUtf8(buffer, i); |
405 CHECK_EQ(lengths[i], written); | 400 CHECK_EQ(lengths[i], written); |
406 // Check that the contents are correct | 401 // Check that the contents are correct |
407 for (int j = 0; j < lengths[i]; j++) | 402 for (int j = 0; j < lengths[i]; j++) |
408 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); | 403 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); |
409 // Check that the rest of the buffer hasn't been touched | 404 // Check that the rest of the buffer hasn't been touched |
410 for (int j = lengths[i]; j < 11; j++) | 405 for (int j = lengths[i]; j < 11; j++) |
411 CHECK_EQ(kNoChar, buffer[j]); | 406 CHECK_EQ(kNoChar, buffer[j]); |
412 } | 407 } |
413 } | 408 } |
OLD | NEW |