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

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

Issue 7832002: Enable slices of external strings (in the tentative implementation). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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
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 484 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) {
Vitaly Repeshko 2011/09/13 18:20:25 Do we have a test for the case of the underlying s
Yang 2011/09/15 11:01:22 Both the cctest test-api/MorphCompositeStringTest
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 // After slicing, the original string becomes a flat cons.
Vitaly Repeshko 2011/09/13 18:20:25 Update the comment.
527 CHECK(slice->IsSlicedString());
528 CHECK(string->IsExternalString());
529 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string);
530 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString());
531 CHECK(slice->IsFlat());
532 }
533
534
505 TEST(TrivialSlice) { 535 TEST(TrivialSlice) {
506 // This tests whether a slice that contains the entire parent string 536 // This tests whether a slice that contains the entire parent string
507 // actually creates a new string (it should not). 537 // actually creates a new string (it should not).
508 FLAG_string_slices = true; 538 FLAG_string_slices = true;
509 InitializeVM(); 539 InitializeVM();
510 HandleScope scope; 540 HandleScope scope;
511 v8::Local<v8::Value> result; 541 v8::Local<v8::Value> result;
512 Handle<String> string; 542 Handle<String> string;
513 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; 543 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
514 const char* check = "str.slice(0,26)"; 544 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()); 581 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
552 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); 582 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString()));
553 583
554 result = CompileRun(slice_from_slice); 584 result = CompileRun(slice_from_slice);
555 CHECK(result->IsString()); 585 CHECK(result->IsString());
556 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 586 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
557 CHECK(string->IsSlicedString()); 587 CHECK(string->IsSlicedString());
558 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); 588 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
559 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); 589 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString()));
560 } 590 }
OLDNEW
« src/heap.cc ('K') | « src/runtime.cc ('k') | test/mjsunit/string-slices.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698