OLD | NEW |
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // Terminating '\0' is left out on purpose. It is not required for external | 369 // Terminating '\0' is left out on purpose. It is not required for external |
370 // string data. | 370 // string data. |
371 AsciiResource* ascii_resource = | 371 AsciiResource* ascii_resource = |
372 new AsciiResource(Vector<const char>(ascii, i)); | 372 new AsciiResource(Vector<const char>(ascii, i)); |
373 v8::Local<v8::String> ascii_external_string = | 373 v8::Local<v8::String> ascii_external_string = |
374 v8::String::NewExternal(ascii_resource); | 374 v8::String::NewExternal(ascii_resource); |
375 | 375 |
376 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); | 376 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); |
377 uc16* non_ascii = Zone::NewArray<uc16>(i + 1); | 377 uc16* non_ascii = Zone::NewArray<uc16>(i + 1); |
378 for (int j = 0; j < i; j++) { | 378 for (int j = 0; j < i; j++) { |
379 non_ascii[j] = 1234; | 379 non_ascii[j] = 0x1234; |
380 } | 380 } |
381 // Terminating '\0' is left out on purpose. It is not required for external | 381 // Terminating '\0' is left out on purpose. It is not required for external |
382 // string data. | 382 // string data. |
383 Resource* resource = new Resource(Vector<const uc16>(non_ascii, i)); | 383 Resource* resource = new Resource(Vector<const uc16>(non_ascii, i)); |
384 v8::Local<v8::String> non_ascii_external_string = | 384 v8::Local<v8::String> non_ascii_external_string = |
385 v8::String::NewExternal(resource); | 385 v8::String::NewExternal(resource); |
386 non_ascii_external_strings->Set(v8::Integer::New(i), | 386 non_ascii_external_strings->Set(v8::Integer::New(i), |
387 non_ascii_external_string); | 387 non_ascii_external_string); |
388 } | 388 } |
389 | 389 |
390 // Add the arrays with the short external strings in the global object. | 390 // Add the arrays with the short external strings in the global object. |
391 v8::Handle<v8::Object> global = env->Global(); | 391 v8::Handle<v8::Object> global = env->Global(); |
392 global->Set(v8_str("ascii"), ascii_external_strings); | 392 global->Set(v8_str("external_ascii"), ascii_external_strings); |
393 global->Set(v8_str("non_ascii"), non_ascii_external_strings); | 393 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings); |
| 394 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength)); |
394 | 395 |
395 // Add short external ascii and non-ascii strings checking the result. | 396 // Add short external ascii and non-ascii strings checking the result. |
396 static const char* source = | 397 static const char* source = |
397 "function test() {" | 398 "function test() {" |
398 " for (var i = 0; i <= 20; i++) {" | 399 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';" |
| 400 " var non_ascii_chars = '\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u
1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234\u1234';" //NOL
INT |
| 401 " if (ascii_chars.length != max_length) return 1;" |
| 402 " if (non_ascii_chars.length != max_length) return 2;" |
| 403 " var ascii = Array(max_length + 1);" |
| 404 " var non_ascii = Array(max_length + 1);" |
| 405 " for (var i = 0; i <= max_length; i++) {" |
| 406 " ascii[i] = ascii_chars.substring(0, i);" |
| 407 " non_ascii[i] = non_ascii_chars.substring(0, i);" |
| 408 " };" |
| 409 " for (var i = 0; i <= max_length; i++) {" |
| 410 " if (ascii[i] != external_ascii[i]) return 3;" |
| 411 " if (non_ascii[i] != external_non_ascii[i]) return 4;" |
399 " for (var j = 0; j < i; j++) {" | 412 " for (var j = 0; j < i; j++) {" |
400 " if (non_ascii[i] != (non_ascii[j] + non_ascii[i - j])) return false;" | 413 " if (external_ascii[i] !=" |
401 " if (ascii[i] != (ascii[j] + ascii[i - j])) return false;" | 414 " (external_ascii[j] + external_ascii[i - j])) return 5;" |
| 415 " if (external_non_ascii[i] !=" |
| 416 " (external_non_ascii[j] + external_non_ascii[i - j])) return 6;" |
| 417 " if (non_ascii[i] != (non_ascii[j] + non_ascii[i - j])) return 7;" |
| 418 " if (ascii[i] != (ascii[j] + ascii[i - j])) return 8;" |
| 419 " if (ascii[i] != (external_ascii[j] + ascii[i - j])) return 9;" |
| 420 " if (ascii[i] != (ascii[j] + external_ascii[i - j])) return 10;" |
| 421 " if (non_ascii[i] !=" |
| 422 " (external_non_ascii[j] + non_ascii[i - j])) return 11;" |
| 423 " if (non_ascii[i] !=" |
| 424 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" |
402 " }" | 425 " }" |
403 " }" | 426 " }" |
404 " return true;" | 427 " return 0;" |
405 "};" | 428 "};" |
406 "test()"; | 429 "test()"; |
407 CHECK(v8::Script::Compile(v8::String::New(source))->Run()->BooleanValue()); | 430 CHECK_EQ(0, |
| 431 v8::Script::Compile(v8::String::New(source))->Run()->Int32Value()); |
408 } | 432 } |
OLD | NEW |