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

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

Issue 11340010: Correctly visit all external strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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
« src/heap.cc ('K') | « src/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14798 matching lines...) Expand 10 before | Expand all | Expand 10 after
14809 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); 14809 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
14810 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); 14810 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
14811 v8::V8::GetHeapStatistics(&heap_statistics); 14811 v8::V8::GetHeapStatistics(&heap_statistics);
14812 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); 14812 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
14813 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); 14813 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
14814 } 14814 }
14815 14815
14816 14816
14817 class VisitorImpl : public v8::ExternalResourceVisitor { 14817 class VisitorImpl : public v8::ExternalResourceVisitor {
14818 public: 14818 public:
14819 VisitorImpl(TestResource* r1, TestResource* r2) 14819 VisitorImpl(TestResource** resource) {
14820 : resource1_(r1), 14820 for (int i = 0; i < 4; i++) {
14821 resource2_(r2), 14821 resource_[i] = resource[i];
14822 found_resource1_(false), 14822 found_resource_[i] = false;
14823 found_resource2_(false) {} 14823 }
14824 }
14824 virtual ~VisitorImpl() {} 14825 virtual ~VisitorImpl() {}
14825 virtual void VisitExternalString(v8::Handle<v8::String> string) { 14826 virtual void VisitExternalString(v8::Handle<v8::String> string) {
14826 if (!string->IsExternal()) { 14827 if (!string->IsExternal()) {
14827 CHECK(string->IsExternalAscii()); 14828 CHECK(string->IsExternalAscii());
14828 return; 14829 return;
14829 } 14830 }
14830 v8::String::ExternalStringResource* resource = 14831 v8::String::ExternalStringResource* resource =
14831 string->GetExternalStringResource(); 14832 string->GetExternalStringResource();
14832 CHECK(resource); 14833 CHECK(resource);
14833 if (resource1_ == resource) { 14834 for (int i = 0; i < 4; i++) {
14834 CHECK(!found_resource1_); 14835 if (resource_[i] == resource) {
14835 found_resource1_ = true; 14836 CHECK(!found_resource_[i]);
14836 } 14837 found_resource_[i] = true;
14837 if (resource2_ == resource) { 14838 }
14838 CHECK(!found_resource2_);
14839 found_resource2_ = true;
14840 } 14839 }
14841 } 14840 }
14842 void CheckVisitedResources() { 14841 void CheckVisitedResources() {
14843 CHECK(found_resource1_); 14842 for (int i = 0; i < 4; i++) {
14844 CHECK(found_resource2_); 14843 CHECK(found_resource_[i]);
14844 }
14845 } 14845 }
14846 14846
14847 private: 14847 private:
14848 v8::String::ExternalStringResource* resource1_; 14848 v8::String::ExternalStringResource* resource_[4];
14849 v8::String::ExternalStringResource* resource2_; 14849 bool found_resource_[4];
14850 bool found_resource1_;
14851 bool found_resource2_;
14852 }; 14850 };
14853 14851
14854 TEST(VisitExternalStrings) { 14852 TEST(VisitExternalStrings) {
14855 v8::HandleScope scope; 14853 v8::HandleScope scope;
14856 LocalContext env; 14854 LocalContext env;
14857 const char* string = "Some string"; 14855 const char* string = "Some string";
14858 uint16_t* two_byte_string = AsciiToTwoByteString(string); 14856 uint16_t* two_byte_string = AsciiToTwoByteString(string);
14859 TestResource* resource1 = new TestResource(two_byte_string); 14857 TestResource* resource[4];
14860 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1); 14858 resource[0] = new TestResource(two_byte_string);
14861 TestResource* resource2 = new TestResource(two_byte_string); 14859 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]);
14862 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); 14860 resource[1] = new TestResource(two_byte_string);
14861 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]);
14863 14862
14864 // We need to add usages for string1 and string2 to avoid warnings in GCC 4.7 14863 // Externalized symbol.
14864 resource[2] = new TestResource(two_byte_string);
14865 v8::Local<v8::String> string2 = v8::String::NewSymbol(string);
14866 CHECK(string2->MakeExternal(resource[2]));
14867
14868 // Symbolized External.
14869 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
14870 v8::Local<v8::String> string3 = v8::String::NewExternal(resource[3]);
14871 HEAP->CollectAllAvailableGarbage(); // Tenure string.
14872 // Turn into a symbol.
14873 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3);
14874 CHECK(!HEAP->LookupSymbol(*string3_i)->IsFailure());
14875 CHECK(string3_i->IsSymbol());
14876
14877 // We need to add usages for string* to avoid warnings in GCC 4.7
14878 CHECK(string0->IsExternal());
14865 CHECK(string1->IsExternal()); 14879 CHECK(string1->IsExternal());
14866 CHECK(string2->IsExternal()); 14880 CHECK(string2->IsExternal());
14881 CHECK(string3->IsExternal());
14867 14882
14868 VisitorImpl visitor(resource1, resource2); 14883 VisitorImpl visitor(resource);
14869 v8::V8::VisitExternalResources(&visitor); 14884 v8::V8::VisitExternalResources(&visitor);
14870 visitor.CheckVisitedResources(); 14885 visitor.CheckVisitedResources();
14871 } 14886 }
14872 14887
14873 14888
14874 static double DoubleFromBits(uint64_t value) { 14889 static double DoubleFromBits(uint64_t value) {
14875 double target; 14890 double target;
14876 memcpy(&target, &value, sizeof(target)); 14891 memcpy(&target, &value, sizeof(target));
14877 return target; 14892 return target;
14878 } 14893 }
(...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after
17762 17777
17763 i::Semaphore* sem_; 17778 i::Semaphore* sem_;
17764 volatile int sem_value_; 17779 volatile int sem_value_;
17765 }; 17780 };
17766 17781
17767 17782
17768 THREADED_TEST(SemaphoreInterruption) { 17783 THREADED_TEST(SemaphoreInterruption) {
17769 ThreadInterruptTest().RunTest(); 17784 ThreadInterruptTest().RunTest();
17770 } 17785 }
17771 #endif // WIN32 17786 #endif // WIN32
OLDNEW
« src/heap.cc ('K') | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698