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

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

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 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-thread-termination.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 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (len > 14) { 87 if (len > 14) {
88 len += 1234; 88 len += 1234;
89 } 89 }
90 switch (gen() % 4) { 90 switch (gen() % 4) {
91 case 0: { 91 case 0: {
92 uc16 buf[2000]; 92 uc16 buf[2000];
93 for (int j = 0; j < len; j++) { 93 for (int j = 0; j < len; j++) {
94 buf[j] = gen() % 65536; 94 buf[j] = gen() % 65536;
95 } 95 }
96 building_blocks[i] = 96 building_blocks[i] =
97 Factory::NewStringFromTwoByte(Vector<const uc16>(buf, len)); 97 FACTORY->NewStringFromTwoByte(Vector<const uc16>(buf, len));
98 for (int j = 0; j < len; j++) { 98 for (int j = 0; j < len; j++) {
99 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 99 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
100 } 100 }
101 break; 101 break;
102 } 102 }
103 case 1: { 103 case 1: {
104 char buf[2000]; 104 char buf[2000];
105 for (int j = 0; j < len; j++) { 105 for (int j = 0; j < len; j++) {
106 buf[j] = gen() % 128; 106 buf[j] = gen() % 128;
107 } 107 }
108 building_blocks[i] = 108 building_blocks[i] =
109 Factory::NewStringFromAscii(Vector<const char>(buf, len)); 109 FACTORY->NewStringFromAscii(Vector<const char>(buf, len));
110 for (int j = 0; j < len; j++) { 110 for (int j = 0; j < len; j++) {
111 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 111 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
112 } 112 }
113 break; 113 break;
114 } 114 }
115 case 2: { 115 case 2: {
116 uc16* buf = Zone::NewArray<uc16>(len); 116 uc16* buf = ZONE->NewArray<uc16>(len);
117 for (int j = 0; j < len; j++) { 117 for (int j = 0; j < len; j++) {
118 buf[j] = gen() % 65536; 118 buf[j] = gen() % 65536;
119 } 119 }
120 Resource* resource = new Resource(Vector<const uc16>(buf, len)); 120 Resource* resource = new Resource(Vector<const uc16>(buf, len));
121 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); 121 building_blocks[i] = FACTORY->NewExternalStringFromTwoByte(resource);
122 for (int j = 0; j < len; j++) { 122 for (int j = 0; j < len; j++) {
123 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 123 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
124 } 124 }
125 break; 125 break;
126 } 126 }
127 case 3: { 127 case 3: {
128 char* buf = NewArray<char>(len); 128 char* buf = NewArray<char>(len);
129 for (int j = 0; j < len; j++) { 129 for (int j = 0; j < len; j++) {
130 buf[j] = gen() % 128; 130 buf[j] = gen() % 128;
131 } 131 }
132 building_blocks[i] = 132 building_blocks[i] =
133 Factory::NewStringFromAscii(Vector<const char>(buf, len)); 133 FACTORY->NewStringFromAscii(Vector<const char>(buf, len));
134 for (int j = 0; j < len; j++) { 134 for (int j = 0; j < len; j++) {
135 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); 135 CHECK_EQ(buf[j], building_blocks[i]->Get(j));
136 } 136 }
137 DeleteArray<char>(buf); 137 DeleteArray<char>(buf);
138 break; 138 break;
139 } 139 }
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 144
145 static Handle<String> ConstructLeft( 145 static Handle<String> ConstructLeft(
146 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], 146 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS],
147 int depth) { 147 int depth) {
148 Handle<String> answer = Factory::NewStringFromAscii(CStrVector("")); 148 Handle<String> answer = FACTORY->NewStringFromAscii(CStrVector(""));
149 for (int i = 0; i < depth; i++) { 149 for (int i = 0; i < depth; i++) {
150 answer = Factory::NewConsString( 150 answer = FACTORY->NewConsString(
151 answer, 151 answer,
152 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS]); 152 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS]);
153 } 153 }
154 return answer; 154 return answer;
155 } 155 }
156 156
157 157
158 static Handle<String> ConstructRight( 158 static Handle<String> ConstructRight(
159 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], 159 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS],
160 int depth) { 160 int depth) {
161 Handle<String> answer = Factory::NewStringFromAscii(CStrVector("")); 161 Handle<String> answer = FACTORY->NewStringFromAscii(CStrVector(""));
162 for (int i = depth - 1; i >= 0; i--) { 162 for (int i = depth - 1; i >= 0; i--) {
163 answer = Factory::NewConsString( 163 answer = FACTORY->NewConsString(
164 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS], 164 building_blocks[i % NUMBER_OF_BUILDING_BLOCKS],
165 answer); 165 answer);
166 } 166 }
167 return answer; 167 return answer;
168 } 168 }
169 169
170 170
171 static Handle<String> ConstructBalancedHelper( 171 static Handle<String> ConstructBalancedHelper(
172 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS], 172 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS],
173 int from, 173 int from,
174 int to) { 174 int to) {
175 CHECK(to > from); 175 CHECK(to > from);
176 if (to - from == 1) { 176 if (to - from == 1) {
177 return building_blocks[from % NUMBER_OF_BUILDING_BLOCKS]; 177 return building_blocks[from % NUMBER_OF_BUILDING_BLOCKS];
178 } 178 }
179 if (to - from == 2) { 179 if (to - from == 2) {
180 return Factory::NewConsString( 180 return FACTORY->NewConsString(
181 building_blocks[from % NUMBER_OF_BUILDING_BLOCKS], 181 building_blocks[from % NUMBER_OF_BUILDING_BLOCKS],
182 building_blocks[(from+1) % NUMBER_OF_BUILDING_BLOCKS]); 182 building_blocks[(from+1) % NUMBER_OF_BUILDING_BLOCKS]);
183 } 183 }
184 Handle<String> part1 = 184 Handle<String> part1 =
185 ConstructBalancedHelper(building_blocks, from, from + ((to - from) / 2)); 185 ConstructBalancedHelper(building_blocks, from, from + ((to - from) / 2));
186 Handle<String> part2 = 186 Handle<String> part2 =
187 ConstructBalancedHelper(building_blocks, from + ((to - from) / 2), to); 187 ConstructBalancedHelper(building_blocks, from + ((to - from) / 2), to);
188 return Factory::NewConsString(part1, part2); 188 return FACTORY->NewConsString(part1, part2);
189 } 189 }
190 190
191 191
192 static Handle<String> ConstructBalanced( 192 static Handle<String> ConstructBalanced(
193 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { 193 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) {
194 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH); 194 return ConstructBalancedHelper(building_blocks, 0, DEEP_DEPTH);
195 } 195 }
196 196
197 197
198 static StringInputBuffer buffer; 198 static StringInputBuffer buffer;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 TEST(DeepAscii) { 279 TEST(DeepAscii) {
280 printf("TestDeepAscii\n"); 280 printf("TestDeepAscii\n");
281 InitializeVM(); 281 InitializeVM();
282 v8::HandleScope scope; 282 v8::HandleScope scope;
283 283
284 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); 284 char* foo = NewArray<char>(DEEP_ASCII_DEPTH);
285 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { 285 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) {
286 foo[i] = "foo "[i % 4]; 286 foo[i] = "foo "[i % 4];
287 } 287 }
288 Handle<String> string = 288 Handle<String> string =
289 Factory::NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); 289 FACTORY->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH));
290 Handle<String> foo_string = Factory::NewStringFromAscii(CStrVector("foo")); 290 Handle<String> foo_string = FACTORY->NewStringFromAscii(CStrVector("foo"));
291 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { 291 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) {
292 string = Factory::NewConsString(string, foo_string); 292 string = FACTORY->NewConsString(string, foo_string);
293 } 293 }
294 Handle<String> flat_string = Factory::NewConsString(string, foo_string); 294 Handle<String> flat_string = FACTORY->NewConsString(string, foo_string);
295 FlattenString(flat_string); 295 FlattenString(flat_string);
296 296
297 for (int i = 0; i < 500; i++) { 297 for (int i = 0; i < 500; i++) {
298 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); 298 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH);
299 } 299 }
300 DeleteArray<char>(foo); 300 DeleteArray<char>(foo);
301 } 301 }
302 302
303 303
304 TEST(Utf8Conversion) { 304 TEST(Utf8Conversion) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength); 358 CHECK_GT(kMaxLength, i::String::kMinNonFlatLength);
359 359
360 // Allocate two JavaScript arrays for holding short strings. 360 // Allocate two JavaScript arrays for holding short strings.
361 v8::Handle<v8::Array> ascii_external_strings = 361 v8::Handle<v8::Array> ascii_external_strings =
362 v8::Array::New(kMaxLength + 1); 362 v8::Array::New(kMaxLength + 1);
363 v8::Handle<v8::Array> non_ascii_external_strings = 363 v8::Handle<v8::Array> non_ascii_external_strings =
364 v8::Array::New(kMaxLength + 1); 364 v8::Array::New(kMaxLength + 1);
365 365
366 // Generate short ascii and non-ascii external strings. 366 // Generate short ascii and non-ascii external strings.
367 for (int i = 0; i <= kMaxLength; i++) { 367 for (int i = 0; i <= kMaxLength; i++) {
368 char* ascii = Zone::NewArray<char>(i + 1); 368 char* ascii = ZONE->NewArray<char>(i + 1);
369 for (int j = 0; j < i; j++) { 369 for (int j = 0; j < i; j++) {
370 ascii[j] = 'a'; 370 ascii[j] = 'a';
371 } 371 }
372 // Terminating '\0' is left out on purpose. It is not required for external 372 // Terminating '\0' is left out on purpose. It is not required for external
373 // string data. 373 // string data.
374 AsciiResource* ascii_resource = 374 AsciiResource* ascii_resource =
375 new AsciiResource(Vector<const char>(ascii, i)); 375 new AsciiResource(Vector<const char>(ascii, i));
376 v8::Local<v8::String> ascii_external_string = 376 v8::Local<v8::String> ascii_external_string =
377 v8::String::NewExternal(ascii_resource); 377 v8::String::NewExternal(ascii_resource);
378 378
379 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); 379 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string);
380 uc16* non_ascii = Zone::NewArray<uc16>(i + 1); 380 uc16* non_ascii = ZONE->NewArray<uc16>(i + 1);
381 for (int j = 0; j < i; j++) { 381 for (int j = 0; j < i; j++) {
382 non_ascii[j] = 0x1234; 382 non_ascii[j] = 0x1234;
383 } 383 }
384 // Terminating '\0' is left out on purpose. It is not required for external 384 // Terminating '\0' is left out on purpose. It is not required for external
385 // string data. 385 // string data.
386 Resource* resource = new Resource(Vector<const uc16>(non_ascii, i)); 386 Resource* resource = new Resource(Vector<const uc16>(non_ascii, i));
387 v8::Local<v8::String> non_ascii_external_string = 387 v8::Local<v8::String> non_ascii_external_string =
388 v8::String::NewExternal(resource); 388 v8::String::NewExternal(resource);
389 non_ascii_external_strings->Set(v8::Integer::New(i), 389 non_ascii_external_strings->Set(v8::Integer::New(i),
390 non_ascii_external_string); 390 non_ascii_external_string);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 "x[s];", 452 "x[s];",
453 "x[s] = 37;", 453 "x[s] = 37;",
454 "x[4];", 454 "x[4];",
455 "x[s];", 455 "x[s];",
456 NULL 456 NULL
457 }; 457 };
458 458
459 Handle<Smi> fortytwo(Smi::FromInt(42)); 459 Handle<Smi> fortytwo(Smi::FromInt(42));
460 Handle<Smi> thirtyseven(Smi::FromInt(37)); 460 Handle<Smi> thirtyseven(Smi::FromInt(37));
461 Handle<Object> results[] = { 461 Handle<Object> results[] = {
462 Factory::undefined_value(), 462 FACTORY->undefined_value(),
463 fortytwo, 463 fortytwo,
464 Factory::undefined_value(), 464 FACTORY->undefined_value(),
465 Factory::undefined_value(), 465 FACTORY->undefined_value(),
466 thirtyseven, 466 thirtyseven,
467 fortytwo, 467 fortytwo,
468 thirtyseven // Bug yielded 42 here. 468 thirtyseven // Bug yielded 42 here.
469 }; 469 };
470 470
471 const char* line; 471 const char* line;
472 for (int i = 0; (line = lines[i]); i++) { 472 for (int i = 0; (line = lines[i]); i++) {
473 printf("%s\n", line); 473 printf("%s\n", line);
474 v8::Local<v8::Value> result = 474 v8::Local<v8::Value> result =
475 v8::Script::Compile(v8::String::New(line))->Run(); 475 v8::Script::Compile(v8::String::New(line))->Run();
476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); 476 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined());
477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); 477 CHECK_EQ(results[i]->IsNumber(), result->IsNumber());
478 if (result->IsNumber()) { 478 if (result->IsNumber()) {
479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), 479 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(),
480 result->ToInt32()->Value()); 480 result->ToInt32()->Value());
481 } 481 }
482 } 482 }
483 } 483 }
OLDNEW
« no previous file with comments | « test/cctest/test-spaces.cc ('k') | test/cctest/test-thread-termination.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698