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

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

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 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-spaces.cc ('k') | test/cctest/test-threads.cc » ('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 2011 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"
11 11
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 // After slicing, the original string becomes a flat cons. 495 // After slicing, the original string becomes a flat cons.
496 CHECK(parent->IsFlat()); 496 CHECK(parent->IsFlat());
497 CHECK(slice->IsSlicedString()); 497 CHECK(slice->IsSlicedString());
498 CHECK_EQ(SlicedString::cast(*slice)->parent(), 498 CHECK_EQ(SlicedString::cast(*slice)->parent(),
499 ConsString::cast(*parent)->first()); 499 ConsString::cast(*parent)->first());
500 CHECK(SlicedString::cast(*slice)->parent()->IsSeqString()); 500 CHECK(SlicedString::cast(*slice)->parent()->IsSeqString());
501 CHECK(slice->IsFlat()); 501 CHECK(slice->IsFlat());
502 } 502 }
503 503
504 504
505 class AsciiVectorResource : public v8::String::ExternalAsciiStringResource {
506 public:
507 explicit AsciiVectorResource(i::Vector<const char> vector)
508 : data_(vector) {}
509 virtual ~AsciiVectorResource() {}
510 virtual size_t length() const { return data_.length(); }
511 virtual const char* data() const { return data_.start(); }
512 private:
513 i::Vector<const char> data_;
514 };
515
516
517 TEST(SliceFromExternal) {
518 FLAG_string_slices = true;
519 InitializeVM();
520 v8::HandleScope scope;
521 AsciiVectorResource resource(
522 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26));
523 Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource);
524 CHECK(string->IsExternalString());
525 Handle<String> slice = FACTORY->NewSubString(string, 1, 25);
526 CHECK(slice->IsSlicedString());
527 CHECK(string->IsExternalString());
528 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string);
529 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString());
530 CHECK(slice->IsFlat());
531 }
532
533
505 TEST(TrivialSlice) { 534 TEST(TrivialSlice) {
506 // This tests whether a slice that contains the entire parent string 535 // This tests whether a slice that contains the entire parent string
507 // actually creates a new string (it should not). 536 // actually creates a new string (it should not).
508 FLAG_string_slices = true; 537 FLAG_string_slices = true;
509 InitializeVM(); 538 InitializeVM();
510 HandleScope scope; 539 HandleScope scope;
511 v8::Local<v8::Value> result; 540 v8::Local<v8::Value> result;
512 Handle<String> string; 541 Handle<String> string;
513 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; 542 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
514 const char* check = "str.slice(0,26)"; 543 const char* check = "str.slice(0,26)";
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); 580 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
552 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); 581 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
553 582
554 result = CompileRun(slice_from_slice); 583 result = CompileRun(slice_from_slice);
555 CHECK(result->IsString()); 584 CHECK(result->IsString());
556 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 585 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
557 CHECK(string->IsSlicedString()); 586 CHECK(string->IsSlicedString());
558 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); 587 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
559 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); 588 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString()));
560 } 589 }
OLDNEW
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698