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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 char* buf = NewArray<char>(len); | 110 char* buf = NewArray<char>(len); |
111 for (int j = 0; j < len; j++) { | 111 for (int j = 0; j < len; j++) { |
112 buf[j] = gen() % 128; | 112 buf[j] = gen() % 128; |
113 } | 113 } |
114 building_blocks[i] = | 114 building_blocks[i] = |
115 Factory::NewStringFromAscii(Vector<const char>(buf, len)); | 115 Factory::NewStringFromAscii(Vector<const char>(buf, len)); |
116 for (int j = 0; j < len; j++) { | 116 for (int j = 0; j < len; j++) { |
117 StringShape shape(*building_blocks[i]); | 117 StringShape shape(*building_blocks[i]); |
118 CHECK_EQ(buf[j], building_blocks[i]->Get(shape, j)); | 118 CHECK_EQ(buf[j], building_blocks[i]->Get(shape, j)); |
119 } | 119 } |
| 120 DeleteArray<char>(buf); |
120 break; | 121 break; |
121 } | 122 } |
122 } | 123 } |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 | 127 |
127 static Handle<String> ConstructLeft( | 128 static Handle<String> ConstructLeft( |
128 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], | 129 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], |
129 int depth) { | 130 int depth) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 358 } |
358 Handle<String> flat_string = Factory::NewConsString(string, | 359 Handle<String> flat_string = Factory::NewConsString(string, |
359 StringShape(*string), | 360 StringShape(*string), |
360 foo_string, | 361 foo_string, |
361 StringShape(*foo_string)); | 362 StringShape(*foo_string)); |
362 FlattenString(flat_string); | 363 FlattenString(flat_string); |
363 | 364 |
364 for (int i = 0; i < 500; i++) { | 365 for (int i = 0; i < 500; i++) { |
365 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); | 366 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); |
366 } | 367 } |
| 368 DeleteArray<char>(foo); |
367 } | 369 } |
368 | 370 |
369 | 371 |
370 TEST(Utf8Conversion) { | 372 TEST(Utf8Conversion) { |
371 // Smoke test for converting strings to utf-8. | 373 // Smoke test for converting strings to utf-8. |
372 InitializeVM(); | 374 InitializeVM(); |
373 v8::HandleScope handle_scope; | 375 v8::HandleScope handle_scope; |
374 // A simple ascii string | 376 // A simple ascii string |
375 const char* ascii_string = "abcdef12345"; | 377 const char* ascii_string = "abcdef12345"; |
376 int len = v8::String::New(ascii_string, strlen(ascii_string))->Utf8Length(); | 378 int len = v8::String::New(ascii_string, strlen(ascii_string))->Utf8Length(); |
(...skipping 22 matching lines...) Expand all Loading... |
399 int written = mixed->WriteUtf8(buffer, i); | 401 int written = mixed->WriteUtf8(buffer, i); |
400 CHECK_EQ(lengths[i], written); | 402 CHECK_EQ(lengths[i], written); |
401 // Check that the contents are correct | 403 // Check that the contents are correct |
402 for (int j = 0; j < lengths[i]; j++) | 404 for (int j = 0; j < lengths[i]; j++) |
403 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); | 405 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); |
404 // Check that the rest of the buffer hasn't been touched | 406 // Check that the rest of the buffer hasn't been touched |
405 for (int j = lengths[i]; j < 11; j++) | 407 for (int j = lengths[i]; j < 11; j++) |
406 CHECK_EQ(kNoChar, buffer[j]); | 408 CHECK_EQ(kNoChar, buffer[j]); |
407 } | 409 } |
408 } | 410 } |
OLD | NEW |