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

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

Issue 7860035: Merge bleeding edge up to 9192 into the GC branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Created 9 years, 3 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-regexp.cc ('k') | test/es5conform/es5conform.status » ('j') | 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 " if (ascii[i] != (ascii[j] + external_ascii[i - j])) return 10;" 423 " if (ascii[i] != (ascii[j] + external_ascii[i - j])) return 10;"
424 " if (non_ascii[i] !=" 424 " if (non_ascii[i] !="
425 " (external_non_ascii[j] + non_ascii[i - j])) return 11;" 425 " (external_non_ascii[j] + non_ascii[i - j])) return 11;"
426 " if (non_ascii[i] !=" 426 " if (non_ascii[i] !="
427 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" 427 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
428 " }" 428 " }"
429 " }" 429 " }"
430 " return 0;" 430 " return 0;"
431 "};" 431 "};"
432 "test()"; 432 "test()";
433 CHECK_EQ(0, 433 CHECK_EQ(0, CompileRun(source)->Int32Value());
434 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value());
435 } 434 }
436 435
437 436
438 TEST(CachedHashOverflow) { 437 TEST(CachedHashOverflow) {
439 // We incorrectly allowed strings to be tagged as array indices even if their 438 // We incorrectly allowed strings to be tagged as array indices even if their
440 // values didn't fit in the hash field. 439 // values didn't fit in the hash field.
441 // See http://code.google.com/p/v8/issues/detail?id=728 440 // See http://code.google.com/p/v8/issues/detail?id=728
442 ZoneScope zone(Isolate::Current(), DELETE_ON_EXIT); 441 ZoneScope zone(Isolate::Current(), DELETE_ON_EXIT);
443 442
444 InitializeVM(); 443 InitializeVM();
(...skipping 29 matching lines...) Expand all
474 v8::Local<v8::Value> result = 473 v8::Local<v8::Value> result =
475 v8::Script::Compile(v8::String::New(line))->Run(); 474 v8::Script::Compile(v8::String::New(line))->Run();
476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); 475 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined());
477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); 476 CHECK_EQ(results[i]->IsNumber(), result->IsNumber());
478 if (result->IsNumber()) { 477 if (result->IsNumber()) {
479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), 478 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(),
480 result->ToInt32()->Value()); 479 result->ToInt32()->Value());
481 } 480 }
482 } 481 }
483 } 482 }
483
484
485 TEST(SliceFromCons) {
486 FLAG_string_slices = true;
487 InitializeVM();
488 v8::HandleScope scope;
489 Handle<String> string =
490 FACTORY->NewStringFromAscii(CStrVector("parentparentparent"));
491 Handle<String> parent = FACTORY->NewConsString(string, string);
492 CHECK(parent->IsConsString());
493 CHECK(!parent->IsFlat());
494 Handle<String> slice = FACTORY->NewSubString(parent, 1, 25);
495 // After slicing, the original string becomes a flat cons.
496 CHECK(parent->IsFlat());
497 CHECK(slice->IsSlicedString());
498 CHECK_EQ(SlicedString::cast(*slice)->parent(),
499 ConsString::cast(*parent)->first());
500 CHECK(SlicedString::cast(*slice)->parent()->IsSeqString());
501 CHECK(slice->IsFlat());
502 }
503
504
505 TEST(TrivialSlice) {
506 // This tests whether a slice that contains the entire parent string
507 // actually creates a new string (it should not).
508 FLAG_string_slices = true;
509 InitializeVM();
510 HandleScope scope;
511 v8::Local<v8::Value> result;
512 Handle<String> string;
513 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
514 const char* check = "str.slice(0,26)";
515 const char* crosscheck = "str.slice(1,25)";
516
517 CompileRun(init);
518
519 result = CompileRun(check);
520 CHECK(result->IsString());
521 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
522 CHECK(!string->IsSlicedString());
523
524 string = FACTORY->NewSubString(string, 0, 26);
525 CHECK(!string->IsSlicedString());
526 result = CompileRun(crosscheck);
527 CHECK(result->IsString());
528 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
529 CHECK(string->IsSlicedString());
530 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
531 }
532
533
534 TEST(SliceFromSlice) {
535 // This tests whether a slice that contains the entire parent string
536 // actually creates a new string (it should not).
537 FLAG_string_slices = true;
538 InitializeVM();
539 HandleScope scope;
540 v8::Local<v8::Value> result;
541 Handle<String> string;
542 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
543 const char* slice = "var slice = str.slice(1,-1); slice";
544 const char* slice_from_slice = "slice.slice(1,-1);";
545
546 CompileRun(init);
547 result = CompileRun(slice);
548 CHECK(result->IsString());
549 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
550 CHECK(string->IsSlicedString());
551 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
552 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
553
554 result = CompileRun(slice_from_slice);
555 CHECK(result->IsString());
556 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
557 CHECK(string->IsSlicedString());
558 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
559 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString()));
560 }
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/es5conform/es5conform.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698