| Index: test/cctest/test-strings.cc
|
| ===================================================================
|
| --- test/cctest/test-strings.cc (revision 9531)
|
| +++ test/cctest/test-strings.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
| +// Copyright 2011 the V8 project authors. All rights reserved.
|
|
|
| // Check that we can traverse very deep stacks of ConsStrings using
|
| // StringInputBuffer. Check that Get(int) works on very deep stacks
|
| @@ -502,6 +502,35 @@
|
| }
|
|
|
|
|
| +class AsciiVectorResource : public v8::String::ExternalAsciiStringResource {
|
| + public:
|
| + explicit AsciiVectorResource(i::Vector<const char> vector)
|
| + : data_(vector) {}
|
| + virtual ~AsciiVectorResource() {}
|
| + virtual size_t length() const { return data_.length(); }
|
| + virtual const char* data() const { return data_.start(); }
|
| + private:
|
| + i::Vector<const char> data_;
|
| +};
|
| +
|
| +
|
| +TEST(SliceFromExternal) {
|
| + FLAG_string_slices = true;
|
| + InitializeVM();
|
| + v8::HandleScope scope;
|
| + AsciiVectorResource resource(
|
| + i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26));
|
| + Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource);
|
| + CHECK(string->IsExternalString());
|
| + Handle<String> slice = FACTORY->NewSubString(string, 1, 25);
|
| + CHECK(slice->IsSlicedString());
|
| + CHECK(string->IsExternalString());
|
| + CHECK_EQ(SlicedString::cast(*slice)->parent(), *string);
|
| + CHECK(SlicedString::cast(*slice)->parent()->IsExternalString());
|
| + CHECK(slice->IsFlat());
|
| +}
|
| +
|
| +
|
| TEST(TrivialSlice) {
|
| // This tests whether a slice that contains the entire parent string
|
| // actually creates a new string (it should not).
|
|
|