Index: test/cctest/test-heap-profiler.cc |
=================================================================== |
--- test/cctest/test-heap-profiler.cc (revision 10391) |
+++ test/cctest/test-heap-profiler.cc (working copy) |
@@ -855,7 +855,67 @@ |
CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid3)); |
} |
+class TestResource: public v8::String::ExternalStringResource { |
+ public: |
+ static const size_t max_length = 100; |
mnaganov (inactive)
2012/01/11 18:50:23
kMaxLength
yurys
2012/01/11 19:50:13
Done.
|
+ explicit TestResource(const char* data) |
+ : data_(), length_(strlen(data)) { |
+ if (length_ >= max_length) length_ = max_length - 1; |
+ for (size_t i = 0; i < length_; i++) data_[i] = data[i]; |
+ data_[length_ + 1] = 0; |
+ } |
+ ~TestResource() {} |
+ const uint16_t* data() const { return data_; } |
+ size_t length() const { return length_; } |
+ private: |
+ uint16_t data_[max_length]; |
+ size_t length_; |
+}; |
+ |
+class VisitorImpl : public v8::HeapProfiler::ExternalResourceVisitor { |
+ public: |
+ VisitorImpl(TestResource* r1, TestResource* r2) |
+ : resource1_(r1), |
+ resource2_(r2) {} |
+ virtual ~VisitorImpl() {} |
+ virtual void VisitExternalString(v8::Handle<v8::String> string) { |
+ if (!string->IsExternal()) { |
+ CHECK(string->IsExternalAscii()); |
+ return; |
+ } |
+ v8::String::ExternalStringResource* resource = |
+ string->GetExternalStringResource(); |
+ CHECK(resource); |
+ if (resource1_ == resource) |
mnaganov (inactive)
2012/01/11 18:50:23
Perhaps, just use boolean flags? Modifying referen
yurys
2012/01/11 19:50:13
Done.
|
+ resource1_ = NULL; |
+ if (resource2_ == resource) |
+ resource2_ = NULL; |
+ } |
+ void CheckVisitedResources() { |
+ CHECK_EQ(NULL, resource1_); |
+ CHECK_EQ(NULL, resource2_); |
+ } |
+ |
+ private: |
+ v8::String::ExternalStringResource* resource1_; |
+ v8::String::ExternalStringResource* resource2_; |
+}; |
+ |
+TEST(VisitExternalStrings) { |
+ v8::HandleScope scope; |
+ LocalContext env; |
+ TestResource* resource = new TestResource("Test string1"); |
+ v8::Local<v8::String> string1 = v8::String::NewExternal(resource); |
+ TestResource* resource2 = new TestResource("Test string2"); |
+ v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); |
+ |
+ VisitorImpl visitor(resource, resource2); |
+ v8::HeapProfiler::VisitExternalResources(&visitor); |
+ visitor.CheckVisitedResources(); |
+} |
+ |
+ |
TEST(DocumentURL) { |
v8::HandleScope scope; |
LocalContext env; |