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

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

Issue 11315004: Count external string resources that were assigned to symbol strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: with minor test fix 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
« no previous file with comments | « src/api.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* r1, TestResource* r2, TestResource* r3)
14820 : resource1_(r1), 14820 : resource1_(r1),
14821 resource2_(r2), 14821 resource2_(r2),
14822 resource3_(r3),
14822 found_resource1_(false), 14823 found_resource1_(false),
14823 found_resource2_(false) {} 14824 found_resource2_(false),
14825 found_resource3_(false) {}
14824 virtual ~VisitorImpl() {} 14826 virtual ~VisitorImpl() {}
14825 virtual void VisitExternalString(v8::Handle<v8::String> string) { 14827 virtual void VisitExternalString(v8::Handle<v8::String> string) {
14826 if (!string->IsExternal()) { 14828 if (!string->IsExternal()) {
14827 CHECK(string->IsExternalAscii()); 14829 CHECK(string->IsExternalAscii());
14828 return; 14830 return;
14829 } 14831 }
14830 v8::String::ExternalStringResource* resource = 14832 v8::String::ExternalStringResource* resource =
14831 string->GetExternalStringResource(); 14833 string->GetExternalStringResource();
14832 CHECK(resource); 14834 CHECK(resource);
14833 if (resource1_ == resource) { 14835 if (resource1_ == resource) {
14834 CHECK(!found_resource1_); 14836 CHECK(!found_resource1_);
14835 found_resource1_ = true; 14837 found_resource1_ = true;
14836 } 14838 }
14837 if (resource2_ == resource) { 14839 if (resource2_ == resource) {
14838 CHECK(!found_resource2_); 14840 CHECK(!found_resource2_);
14839 found_resource2_ = true; 14841 found_resource2_ = true;
14840 } 14842 }
14843 if (resource3_ == resource) {
14844 CHECK(!found_resource3_);
14845 found_resource3_ = true;
14846 }
14841 } 14847 }
14842 void CheckVisitedResources() { 14848 void CheckVisitedResources() {
14843 CHECK(found_resource1_); 14849 CHECK(found_resource1_);
14844 CHECK(found_resource2_); 14850 CHECK(found_resource2_);
14851 CHECK(found_resource3_);
14845 } 14852 }
14846 14853
14847 private: 14854 private:
14848 v8::String::ExternalStringResource* resource1_; 14855 v8::String::ExternalStringResource* resource1_;
14849 v8::String::ExternalStringResource* resource2_; 14856 v8::String::ExternalStringResource* resource2_;
14857 v8::String::ExternalStringResource* resource3_;
14850 bool found_resource1_; 14858 bool found_resource1_;
14851 bool found_resource2_; 14859 bool found_resource2_;
14860 bool found_resource3_;
14852 }; 14861 };
14853 14862
14854 TEST(VisitExternalStrings) { 14863 TEST(VisitExternalStrings) {
14855 v8::HandleScope scope; 14864 v8::HandleScope scope;
14856 LocalContext env; 14865 LocalContext env;
14857 const char* string = "Some string"; 14866 const char* string = "Some string";
14858 uint16_t* two_byte_string = AsciiToTwoByteString(string); 14867 uint16_t* two_byte_string = AsciiToTwoByteString(string);
14859 TestResource* resource1 = new TestResource(two_byte_string); 14868 TestResource* resource1 = new TestResource(two_byte_string);
14860 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1); 14869 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1);
14861 TestResource* resource2 = new TestResource(two_byte_string); 14870 TestResource* resource2 = new TestResource(two_byte_string);
14862 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); 14871 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2);
14872 TestResource* resource3 = new TestResource(two_byte_string);
14873 v8::Local<v8::String> symbol = v8::String::NewSymbol(string);
14874 symbol->MakeExternal(resource3);
14863 14875
14864 // We need to add usages for string1 and string2 to avoid warnings in GCC 4.7 14876 // We need to add usages for string1, string2 and symbol string
14877 // to avoid warnings in GCC 4.7
14865 CHECK(string1->IsExternal()); 14878 CHECK(string1->IsExternal());
14866 CHECK(string2->IsExternal()); 14879 CHECK(string2->IsExternal());
14880 CHECK(symbol->IsExternal());
14867 14881
14868 VisitorImpl visitor(resource1, resource2); 14882 VisitorImpl visitor(resource1, resource2, resource3);
14869 v8::V8::VisitExternalResources(&visitor); 14883 v8::V8::VisitExternalResources(&visitor);
14870 visitor.CheckVisitedResources(); 14884 visitor.CheckVisitedResources();
14871 } 14885 }
14872 14886
14873 14887
14874 static double DoubleFromBits(uint64_t value) { 14888 static double DoubleFromBits(uint64_t value) {
14875 double target; 14889 double target;
14876 memcpy(&target, &value, sizeof(target)); 14890 memcpy(&target, &value, sizeof(target));
14877 return target; 14891 return target;
14878 } 14892 }
(...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after
17762 17776
17763 i::Semaphore* sem_; 17777 i::Semaphore* sem_;
17764 volatile int sem_value_; 17778 volatile int sem_value_;
17765 }; 17779 };
17766 17780
17767 17781
17768 THREADED_TEST(SemaphoreInterruption) { 17782 THREADED_TEST(SemaphoreInterruption) {
17769 ThreadInterruptTest().RunTest(); 17783 ThreadInterruptTest().RunTest();
17770 } 17784 }
17771 #endif // WIN32 17785 #endif // WIN32
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698