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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 THREADED_TEST(UsingExternalString) { | 606 THREADED_TEST(UsingExternalString) { |
607 { | 607 { |
608 v8::HandleScope scope; | 608 v8::HandleScope scope; |
609 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 609 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
610 Local<String> string = | 610 Local<String> string = |
611 String::NewExternal(new TestResource(two_byte_string)); | 611 String::NewExternal(new TestResource(two_byte_string)); |
612 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 612 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
613 // Trigger GCs so that the newly allocated string moves to old gen. | 613 // Trigger GCs so that the newly allocated string moves to old gen. |
614 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now | 614 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now |
615 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now | 615 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now |
616 i::Handle<i::String> isymbol = FACTORY->SymbolFromString(istring); | 616 i::Handle<i::String> isymbol = |
617 CHECK(isymbol->IsSymbol()); | 617 FACTORY->InternalizedStringFromString(istring); |
| 618 CHECK(isymbol->IsInternalizedString()); |
618 } | 619 } |
619 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 620 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
620 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 621 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
621 } | 622 } |
622 | 623 |
623 | 624 |
624 THREADED_TEST(UsingExternalAsciiString) { | 625 THREADED_TEST(UsingExternalAsciiString) { |
625 { | 626 { |
626 v8::HandleScope scope; | 627 v8::HandleScope scope; |
627 const char* one_byte_string = "test string"; | 628 const char* one_byte_string = "test string"; |
628 Local<String> string = String::NewExternal( | 629 Local<String> string = String::NewExternal( |
629 new TestAsciiResource(i::StrDup(one_byte_string))); | 630 new TestAsciiResource(i::StrDup(one_byte_string))); |
630 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 631 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
631 // Trigger GCs so that the newly allocated string moves to old gen. | 632 // Trigger GCs so that the newly allocated string moves to old gen. |
632 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now | 633 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now |
633 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now | 634 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now |
634 i::Handle<i::String> isymbol = FACTORY->SymbolFromString(istring); | 635 i::Handle<i::String> isymbol = |
635 CHECK(isymbol->IsSymbol()); | 636 FACTORY->InternalizedStringFromString(istring); |
| 637 CHECK(isymbol->IsInternalizedString()); |
636 } | 638 } |
637 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 639 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
638 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 640 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
639 } | 641 } |
640 | 642 |
641 | 643 |
642 THREADED_TEST(ScavengeExternalString) { | 644 THREADED_TEST(ScavengeExternalString) { |
643 i::FLAG_stress_compaction = false; | 645 i::FLAG_stress_compaction = false; |
644 i::FLAG_gc_global = false; | 646 i::FLAG_gc_global = false; |
645 int dispose_count = 0; | 647 int dispose_count = 0; |
(...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3766 // Check that equality works at all before relying on CHECK_EQ | 3768 // Check that equality works at all before relying on CHECK_EQ |
3767 CHECK(v8_str("a")->Equals(v8_str("a"))); | 3769 CHECK(v8_str("a")->Equals(v8_str("a"))); |
3768 CHECK(!v8_str("a")->Equals(v8_str("b"))); | 3770 CHECK(!v8_str("a")->Equals(v8_str("b"))); |
3769 | 3771 |
3770 CHECK_EQ(v8_str("a"), v8_str("a")); | 3772 CHECK_EQ(v8_str("a"), v8_str("a")); |
3771 CHECK_NE(v8_str("a"), v8_str("b")); | 3773 CHECK_NE(v8_str("a"), v8_str("b")); |
3772 CHECK_EQ(v8_num(1), v8_num(1)); | 3774 CHECK_EQ(v8_num(1), v8_num(1)); |
3773 CHECK_EQ(v8_num(1.00), v8_num(1)); | 3775 CHECK_EQ(v8_num(1.00), v8_num(1)); |
3774 CHECK_NE(v8_num(1), v8_num(2)); | 3776 CHECK_NE(v8_num(1), v8_num(2)); |
3775 | 3777 |
3776 // Assume String is not symbol. | 3778 // Assume String is not internalized. |
3777 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); | 3779 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); |
3778 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); | 3780 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); |
3779 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); | 3781 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); |
3780 CHECK(v8_num(1)->StrictEquals(v8_num(1))); | 3782 CHECK(v8_num(1)->StrictEquals(v8_num(1))); |
3781 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); | 3783 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); |
3782 CHECK(v8_num(0)->StrictEquals(v8_num(-0))); | 3784 CHECK(v8_num(0)->StrictEquals(v8_num(-0))); |
3783 Local<Value> not_a_number = v8_num(i::OS::nan_value()); | 3785 Local<Value> not_a_number = v8_num(i::OS::nan_value()); |
3784 CHECK(!not_a_number->StrictEquals(not_a_number)); | 3786 CHECK(!not_a_number->StrictEquals(not_a_number)); |
3785 CHECK(v8::False()->StrictEquals(v8::False())); | 3787 CHECK(v8::False()->StrictEquals(v8::False())); |
3786 CHECK(!v8::False()->StrictEquals(v8::Undefined())); | 3788 CHECK(!v8::False()->StrictEquals(v8::Undefined())); |
(...skipping 9010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12797 private: | 12799 private: |
12798 i::Vector<const i::uc16> data_; | 12800 i::Vector<const i::uc16> data_; |
12799 }; | 12801 }; |
12800 | 12802 |
12801 | 12803 |
12802 static void MorphAString(i::String* string, | 12804 static void MorphAString(i::String* string, |
12803 AsciiVectorResource* ascii_resource, | 12805 AsciiVectorResource* ascii_resource, |
12804 UC16VectorResource* uc16_resource) { | 12806 UC16VectorResource* uc16_resource) { |
12805 CHECK(i::StringShape(string).IsExternal()); | 12807 CHECK(i::StringShape(string).IsExternal()); |
12806 if (string->IsOneByteRepresentation()) { | 12808 if (string->IsOneByteRepresentation()) { |
12807 // Check old map is not symbol or long. | 12809 // Check old map is not internalized or long. |
12808 CHECK(string->map() == HEAP->external_ascii_string_map()); | 12810 CHECK(string->map() == HEAP->external_ascii_string_map()); |
12809 // Morph external string to be TwoByte string. | 12811 // Morph external string to be TwoByte string. |
12810 string->set_map(HEAP->external_string_map()); | 12812 string->set_map(HEAP->external_string_map()); |
12811 i::ExternalTwoByteString* morphed = | 12813 i::ExternalTwoByteString* morphed = |
12812 i::ExternalTwoByteString::cast(string); | 12814 i::ExternalTwoByteString::cast(string); |
12813 morphed->set_resource(uc16_resource); | 12815 morphed->set_resource(uc16_resource); |
12814 } else { | 12816 } else { |
12815 // Check old map is not symbol or long. | 12817 // Check old map is not internalized or long. |
12816 CHECK(string->map() == HEAP->external_string_map()); | 12818 CHECK(string->map() == HEAP->external_string_map()); |
12817 // Morph external string to be ASCII string. | 12819 // Morph external string to be ASCII string. |
12818 string->set_map(HEAP->external_ascii_string_map()); | 12820 string->set_map(HEAP->external_ascii_string_map()); |
12819 i::ExternalAsciiString* morphed = | 12821 i::ExternalAsciiString* morphed = |
12820 i::ExternalAsciiString::cast(string); | 12822 i::ExternalAsciiString::cast(string); |
12821 morphed->set_resource(ascii_resource); | 12823 morphed->set_resource(ascii_resource); |
12822 } | 12824 } |
12823 } | 12825 } |
12824 | 12826 |
12825 | 12827 |
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15258 resource[2] = new TestResource(two_byte_string); | 15260 resource[2] = new TestResource(two_byte_string); |
15259 v8::Local<v8::String> string2 = v8::String::NewSymbol(string); | 15261 v8::Local<v8::String> string2 = v8::String::NewSymbol(string); |
15260 CHECK(string2->MakeExternal(resource[2])); | 15262 CHECK(string2->MakeExternal(resource[2])); |
15261 | 15263 |
15262 // Symbolized External. | 15264 // Symbolized External. |
15263 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); | 15265 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); |
15264 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]); | 15266 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]); |
15265 HEAP->CollectAllAvailableGarbage(); // Tenure string. | 15267 HEAP->CollectAllAvailableGarbage(); // Tenure string. |
15266 // Turn into a symbol. | 15268 // Turn into a symbol. |
15267 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); | 15269 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); |
15268 CHECK(!HEAP->LookupSymbol(*string3_i)->IsFailure()); | 15270 CHECK(!HEAP->InternalizeString(*string3_i)->IsFailure()); |
15269 CHECK(string3_i->IsSymbol()); | 15271 CHECK(string3_i->IsInternalizedString()); |
15270 | 15272 |
15271 // We need to add usages for string* to avoid warnings in GCC 4.7 | 15273 // We need to add usages for string* to avoid warnings in GCC 4.7 |
15272 CHECK(string0->IsExternal()); | 15274 CHECK(string0->IsExternal()); |
15273 CHECK(string1->IsExternal()); | 15275 CHECK(string1->IsExternal()); |
15274 CHECK(string2->IsExternal()); | 15276 CHECK(string2->IsExternal()); |
15275 CHECK(string3->IsExternal()); | 15277 CHECK(string3->IsExternal()); |
15276 | 15278 |
15277 VisitorImpl visitor(resource); | 15279 VisitorImpl visitor(resource); |
15278 v8::V8::VisitExternalResources(&visitor); | 15280 v8::V8::VisitExternalResources(&visitor); |
15279 visitor.CheckVisitedResources(); | 15281 visitor.CheckVisitedResources(); |
(...skipping 2459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17739 ISOLATE->TearDown(); | 17741 ISOLATE->TearDown(); |
17740 CHECK_EQ(data2, isolate->GetData()); | 17742 CHECK_EQ(data2, isolate->GetData()); |
17741 CHECK_EQ(data2, ISOLATE->GetData()); | 17743 CHECK_EQ(data2, ISOLATE->GetData()); |
17742 } | 17744 } |
17743 | 17745 |
17744 | 17746 |
17745 TEST(StringEmpty) { | 17747 TEST(StringEmpty) { |
17746 v8::HandleScope scope; | 17748 v8::HandleScope scope; |
17747 LocalContext context; | 17749 LocalContext context; |
17748 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 17750 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
17749 i::Handle<i::Object> empty_string = FACTORY->empty_symbol(); | 17751 i::Handle<i::Object> empty_string = FACTORY->empty_string(); |
17750 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); | 17752 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); |
17751 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); | 17753 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); |
17752 | 17754 |
17753 // Test after-death behavior. | 17755 // Test after-death behavior. |
17754 CHECK(i::Internals::IsInitialized(isolate)); | 17756 CHECK(i::Internals::IsInitialized(isolate)); |
17755 CHECK_EQ(0, fatal_error_callback_counter); | 17757 CHECK_EQ(0, fatal_error_callback_counter); |
17756 v8::V8::SetFatalErrorHandler(CountingErrorCallback); | 17758 v8::V8::SetFatalErrorHandler(CountingErrorCallback); |
17757 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); | 17759 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); |
17758 i::Isolate::Current()->TearDown(); | 17760 i::Isolate::Current()->TearDown(); |
17759 CHECK(!i::Internals::IsInitialized(isolate)); | 17761 CHECK(!i::Internals::IsInitialized(isolate)); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18212 i::Semaphore* sem_; | 18214 i::Semaphore* sem_; |
18213 volatile int sem_value_; | 18215 volatile int sem_value_; |
18214 }; | 18216 }; |
18215 | 18217 |
18216 | 18218 |
18217 THREADED_TEST(SemaphoreInterruption) { | 18219 THREADED_TEST(SemaphoreInterruption) { |
18218 ThreadInterruptTest().RunTest(); | 18220 ThreadInterruptTest().RunTest(); |
18219 } | 18221 } |
18220 | 18222 |
18221 #endif // WIN32 | 18223 #endif // WIN32 |
OLD | NEW |