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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 static size_t two_byte_length = | 417 static size_t two_byte_length = |
418 sizeof(two_byte_data) / sizeof(two_byte_data[0]); | 418 sizeof(two_byte_data) / sizeof(two_byte_data[0]); |
419 static const char* one_byte_data = "two-byte data"; | 419 static const char* one_byte_data = "two-byte data"; |
420 | 420 |
421 // Allocate an external string resource and external string. | 421 // Allocate an external string resource and external string. |
422 TwoByteResource* resource = new TwoByteResource(two_byte_data, | 422 TwoByteResource* resource = new TwoByteResource(two_byte_data, |
423 two_byte_length); | 423 two_byte_length); |
424 Handle<String> string = Factory::NewExternalStringFromTwoByte(resource); | 424 Handle<String> string = Factory::NewExternalStringFromTwoByte(resource); |
425 Vector<const char> one_byte_vec = CStrVector(one_byte_data); | 425 Vector<const char> one_byte_vec = CStrVector(one_byte_data); |
426 Handle<String> compare = Factory::NewStringFromAscii(one_byte_vec); | 426 Handle<String> compare = Factory::NewStringFromAscii(one_byte_vec); |
427 | 427 |
428 // Verify the correct behaviour before "collecting" the external resource. | 428 // Verify the correct behaviour before "collecting" the external resource. |
429 CHECK(string->IsEqualTo(one_byte_vec)); | 429 CHECK(string->IsEqualTo(one_byte_vec)); |
430 CHECK(string->Equals(*compare)); | 430 CHECK(string->Equals(*compare)); |
431 | 431 |
432 // "Collect" the external resource manually by setting the external resource | 432 // "Collect" the external resource manually by setting the external resource |
433 // pointer to NULL. Then redo the comparisons, they should not match AND | 433 // pointer to NULL. Then redo the comparisons, they should not match AND |
434 // not crash. | 434 // not crash. |
435 Handle<ExternalTwoByteString> external(ExternalTwoByteString::cast(*string)); | 435 Handle<ExternalTwoByteString> external(ExternalTwoByteString::cast(*string)); |
436 external->set_resource(NULL); | 436 external->set_resource(NULL); |
437 CHECK_EQ(false, string->IsEqualTo(one_byte_vec)); | 437 CHECK_EQ(false, string->IsEqualTo(one_byte_vec)); |
438 #if !defined(DEBUG) | 438 #if !defined(DEBUG) |
439 // These tests only work in non-debug as there are ASSERTs in the code that | 439 // These tests only work in non-debug as there are ASSERTs in the code that |
440 // do prevent the ability to even get into the broken code when running the | 440 // do prevent the ability to even get into the broken code when running the |
441 // debug version of V8. | 441 // debug version of V8. |
442 CHECK_EQ(false, string->Equals(*compare)); | 442 CHECK_EQ(false, string->Equals(*compare)); |
443 CHECK_EQ(false, compare->Equals(*string)); | 443 CHECK_EQ(false, compare->Equals(*string)); |
444 CHECK_EQ(false, string->Equals(Heap::empty_string())); | 444 CHECK_EQ(false, string->Equals(Heap::empty_string())); |
445 #endif // !defined(DEBUG) | 445 #endif // !defined(DEBUG) |
446 } | 446 } |
OLD | NEW |