Chromium Code Reviews| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // Check that the contents are correct | 337 // Check that the contents are correct |
| 338 for (int j = 0; j < lengths[i]; j++) | 338 for (int j = 0; j < lengths[i]; j++) |
| 339 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); | 339 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); |
| 340 // Check that the rest of the buffer hasn't been touched | 340 // Check that the rest of the buffer hasn't been touched |
| 341 for (int j = lengths[i]; j < 11; j++) | 341 for (int j = lengths[i]; j < 11; j++) |
| 342 CHECK_EQ(kNoChar, buffer[j]); | 342 CHECK_EQ(kNoChar, buffer[j]); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 | 346 |
| 347 TEST(StringConcatFlatten) { | |
| 348 InitializeVM(); | |
| 349 v8::HandleScope handle_scope; | |
| 350 | |
| 351 const char* stringA = "0123456789"; | |
| 352 const char* stringB = "ABCDEFGHIJ"; | |
| 353 | |
| 354 v8::Local<v8::String> a = v8::String::New(stringA); | |
| 355 v8::Local<v8::String> b = v8::String::New(stringB); | |
| 356 | |
| 357 v8::Local<v8::String> cons = v8::String::Concat(a,b); | |
| 358 | |
| 359 i::Handle<i::String> str = v8::Utils::OpenHandle(*cons); | |
| 360 CHECK_EQ(false, str->IsFlat()); | |
|
antonm
2010/04/08 11:23:41
would you mind if I change that to CHECK(!str->IsF
| |
| 361 | |
| 362 cons->Flatten(); | |
| 363 | |
| 364 CHECK_EQ(true, str->IsFlat()); | |
|
antonm
2010/04/08 11:23:41
would you mind if I change that to CHECK(str->IsFl
| |
| 365 | |
| 366 char buffer[21]; | |
| 367 cons->WriteUtf8(buffer); | |
| 368 | |
| 369 for (int j = 0; j < 10; j++) { | |
|
antonm
2010/04/08 11:23:41
why j, not i? :) I could change to i when landing
| |
| 370 CHECK_EQ(stringA[j], buffer[j]); | |
| 371 } | |
| 372 | |
| 373 for (int j = 0; j < 10; j++) { | |
| 374 CHECK_EQ(stringB[j], buffer[j+10]); | |
| 375 } | |
| 376 } | |
| 377 | |
| 378 | |
| 347 TEST(ExternalShortStringAdd) { | 379 TEST(ExternalShortStringAdd) { |
| 348 ZoneScope zone(DELETE_ON_EXIT); | 380 ZoneScope zone(DELETE_ON_EXIT); |
| 349 | 381 |
| 350 InitializeVM(); | 382 InitializeVM(); |
| 351 v8::HandleScope handle_scope; | 383 v8::HandleScope handle_scope; |
| 352 | 384 |
| 353 // Make sure we cover all always-flat lengths and at least one above. | 385 // Make sure we cover all always-flat lengths and at least one above. |
| 354 static const int kMaxLength = 20; | 386 static const int kMaxLength = 20; |
| 355 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength); | 387 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength); |
| 356 | 388 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 " if (non_ascii[i] !=" | 455 " if (non_ascii[i] !=" |
| 424 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" | 456 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" |
| 425 " }" | 457 " }" |
| 426 " }" | 458 " }" |
| 427 " return 0;" | 459 " return 0;" |
| 428 "};" | 460 "};" |
| 429 "test()"; | 461 "test()"; |
| 430 CHECK_EQ(0, | 462 CHECK_EQ(0, |
| 431 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); | 463 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); |
| 432 } | 464 } |
| OLD | NEW |