| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 735 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 736 i::Handle<i::String> isymbol = | 736 i::Handle<i::String> isymbol = |
| 737 factory->InternalizeString(istring); | 737 factory->InternalizeString(istring); |
| 738 CHECK(isymbol->IsInternalizedString()); | 738 CHECK(isymbol->IsInternalizedString()); |
| 739 } | 739 } |
| 740 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 740 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 741 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 741 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 742 } | 742 } |
| 743 | 743 |
| 744 | 744 |
| 745 class DummyResource : public v8::String::ExternalStringResource { |
| 746 public: |
| 747 virtual const uint16_t* data() const { return string_; } |
| 748 virtual size_t length() const { return 1 << 30; } |
| 749 |
| 750 private: |
| 751 uint16_t string_[10]; |
| 752 }; |
| 753 |
| 754 |
| 755 class DummyOneByteResource : public v8::String::ExternalOneByteStringResource { |
| 756 public: |
| 757 virtual const char* data() const { return string_; } |
| 758 virtual size_t length() const { return 1 << 30; } |
| 759 |
| 760 private: |
| 761 char string_[10]; |
| 762 }; |
| 763 |
| 764 |
| 765 THREADED_TEST(NewExternalForVeryLongString) { |
| 766 { |
| 767 LocalContext env; |
| 768 v8::HandleScope scope(env->GetIsolate()); |
| 769 v8::TryCatch try_catch; |
| 770 DummyOneByteResource r; |
| 771 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); |
| 772 CHECK(str.IsEmpty()); |
| 773 CHECK(try_catch.HasCaught()); |
| 774 String::Utf8Value exception_value(try_catch.Exception()); |
| 775 CHECK_EQ("RangeError: Invalid string length", *exception_value); |
| 776 } |
| 777 |
| 778 { |
| 779 LocalContext env; |
| 780 v8::HandleScope scope(env->GetIsolate()); |
| 781 v8::TryCatch try_catch; |
| 782 DummyResource r; |
| 783 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); |
| 784 CHECK(str.IsEmpty()); |
| 785 CHECK(try_catch.HasCaught()); |
| 786 String::Utf8Value exception_value(try_catch.Exception()); |
| 787 CHECK_EQ("RangeError: Invalid string length", *exception_value); |
| 788 } |
| 789 } |
| 790 |
| 791 |
| 745 THREADED_TEST(ScavengeExternalString) { | 792 THREADED_TEST(ScavengeExternalString) { |
| 746 i::FLAG_stress_compaction = false; | 793 i::FLAG_stress_compaction = false; |
| 747 i::FLAG_gc_global = false; | 794 i::FLAG_gc_global = false; |
| 748 int dispose_count = 0; | 795 int dispose_count = 0; |
| 749 bool in_new_space = false; | 796 bool in_new_space = false; |
| 750 { | 797 { |
| 751 v8::HandleScope scope(CcTest::isolate()); | 798 v8::HandleScope scope(CcTest::isolate()); |
| 752 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 799 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
| 753 Local<String> string = String::NewExternal( | 800 Local<String> string = String::NewExternal( |
| 754 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); | 801 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); |
| (...skipping 22592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23347 " var foobXXXXX"; // Too many bytes which look like incomplete chars! | 23394 " var foobXXXXX"; // Too many bytes which look like incomplete chars! |
| 23348 char chunk2[] = | 23395 char chunk2[] = |
| 23349 "r = 13;\n" | 23396 "r = 13;\n" |
| 23350 " return foob\xeb\x91\x80\x80\x80r;\n" | 23397 " return foob\xeb\x91\x80\x80\x80r;\n" |
| 23351 "}\n"; | 23398 "}\n"; |
| 23352 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; | 23399 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; |
| 23353 | 23400 |
| 23354 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; | 23401 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; |
| 23355 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); | 23402 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); |
| 23356 } | 23403 } |
| OLD | NEW |