OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 | 193 |
194 static Handle<String> ConstructBalanced( | 194 static Handle<String> ConstructBalanced( |
195 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { | 195 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { |
196 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH); | 196 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH); |
197 } | 197 } |
198 | 198 |
199 | 199 |
200 static StringInputBuffer buffer; | 200 static StringInputBuffer buffer; |
201 | 201 static ConsStringIteratorOp consStringIteratorOp; |
202 | 202 |
203 static void Traverse(Handle<String> s1, Handle<String> s2) { | 203 static void Traverse(Handle<String> s1, Handle<String> s2) { |
204 int i = 0; | 204 int i = 0; |
205 buffer.Reset(*s1); | 205 buffer.Reset(*s1); |
| 206 StringCharacterStream characterStream(*s1, 0, &consStringIteratorOp); |
206 StringInputBuffer buffer2(*s2); | 207 StringInputBuffer buffer2(*s2); |
207 while (buffer.has_more()) { | 208 while (buffer.has_more()) { |
208 CHECK(buffer2.has_more()); | 209 CHECK(buffer2.has_more()); |
| 210 CHECK(characterStream.HasMore()); |
209 uint16_t c = buffer.GetNext(); | 211 uint16_t c = buffer.GetNext(); |
210 CHECK_EQ(c, buffer2.GetNext()); | 212 CHECK_EQ(c, buffer2.GetNext()); |
| 213 CHECK_EQ(c, characterStream.GetNext()); |
211 i++; | 214 i++; |
212 } | 215 } |
| 216 CHECK(!characterStream.HasMore()); |
213 CHECK_EQ(s1->length(), i); | 217 CHECK_EQ(s1->length(), i); |
214 CHECK_EQ(s2->length(), i); | 218 CHECK_EQ(s2->length(), i); |
215 } | 219 } |
216 | 220 |
217 | 221 |
218 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { | 222 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { |
219 int i = 0; | 223 int i = 0; |
220 buffer.Reset(*s1); | 224 buffer.Reset(*s1); |
221 StringInputBuffer buffer2(*s2); | 225 StringInputBuffer buffer2(*s2); |
| 226 StringCharacterStream characterStream(*s1, 0, &consStringIteratorOp); |
222 while (buffer.has_more() && i < chars) { | 227 while (buffer.has_more() && i < chars) { |
223 CHECK(buffer2.has_more()); | 228 CHECK(buffer2.has_more()); |
| 229 CHECK(characterStream.HasMore()); |
224 uint16_t c = buffer.GetNext(); | 230 uint16_t c = buffer.GetNext(); |
225 CHECK_EQ(c, buffer2.GetNext()); | 231 CHECK_EQ(c, buffer2.GetNext()); |
| 232 CHECK_EQ(c, characterStream.GetNext()); |
226 i++; | 233 i++; |
227 } | 234 } |
228 s1->Get(s1->length() - 1); | 235 s1->Get(s1->length() - 1); |
229 s2->Get(s2->length() - 1); | 236 s2->Get(s2->length() - 1); |
230 } | 237 } |
231 | 238 |
232 | 239 |
233 TEST(Traverse) { | 240 TEST(Traverse) { |
234 printf("TestTraverse\n"); | 241 printf("TestTraverse\n"); |
235 InitializeVM(); | 242 InitializeVM(); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 715 |
709 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); | 716 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); |
710 CHECK(expected->Equals(result)); | 717 CHECK(expected->Equals(result)); |
711 } | 718 } |
712 | 719 |
713 | 720 |
714 TEST(IsAscii) { | 721 TEST(IsAscii) { |
715 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); | 722 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); |
716 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); | 723 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); |
717 } | 724 } |
OLD | NEW |