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

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

Issue 1609021: Expose a hint which communicates that string might be written many times. (Closed)
Patch Set: Created 10 years, 8 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
« no previous file with comments | « src/api.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 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Check that the contents are correct 340 // Check that the contents are correct
341 for (int j = 0; j < lengths[i]; j++) 341 for (int j = 0; j < lengths[i]; j++)
342 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); 342 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j]));
343 // Check that the rest of the buffer hasn't been touched 343 // Check that the rest of the buffer hasn't been touched
344 for (int j = lengths[i]; j < 11; j++) 344 for (int j = lengths[i]; j < 11; j++)
345 CHECK_EQ(kNoChar, buffer[j]); 345 CHECK_EQ(kNoChar, buffer[j]);
346 } 346 }
347 } 347 }
348 348
349 349
350 TEST(StringConcatFlatten) {
351 InitializeVM();
352 v8::HandleScope handle_scope;
353
354 const char* stringA = "0123456789";
355 const char* stringB = "ABCDEFGHIJ";
356
357 v8::Local<v8::String> a = v8::String::New(stringA);
358 v8::Local<v8::String> b = v8::String::New(stringB);
359
360 v8::Local<v8::String> cons = v8::String::Concat(a, b);
361
362 i::Handle<i::String> str = v8::Utils::OpenHandle(*cons);
363 CHECK(!str->IsFlat());
364
365 cons->Flatten();
366
367 CHECK(str->IsFlat());
368
369 char buffer[21];
370 cons->WriteUtf8(buffer);
371
372 for (int i = 0; i < 10; i++) {
373 CHECK_EQ(stringA[i], buffer[i]);
374 }
375
376 for (int i = 0; i < 10; i++) {
377 CHECK_EQ(stringB[i], buffer[i + 10]);
378 }
379 }
380
381
382 TEST(ExternalShortStringAdd) { 350 TEST(ExternalShortStringAdd) {
383 ZoneScope zone(DELETE_ON_EXIT); 351 ZoneScope zone(DELETE_ON_EXIT);
384 352
385 InitializeVM(); 353 InitializeVM();
386 v8::HandleScope handle_scope; 354 v8::HandleScope handle_scope;
387 355
388 // Make sure we cover all always-flat lengths and at least one above. 356 // Make sure we cover all always-flat lengths and at least one above.
389 static const int kMaxLength = 20; 357 static const int kMaxLength = 20;
390 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength); 358 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength);
391 359
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 " if (non_ascii[i] !=" 426 " if (non_ascii[i] !="
459 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" 427 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
460 " }" 428 " }"
461 " }" 429 " }"
462 " return 0;" 430 " return 0;"
463 "};" 431 "};"
464 "test()"; 432 "test()";
465 CHECK_EQ(0, 433 CHECK_EQ(0,
466 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); 434 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
467 } 435 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698