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

Unified Diff: test/cctest/test-heap-profiler.cc

Issue 9139018: Provide a way for iterating through all external strings referenced from the JS heap (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« src/heap-profiler.cc ('K') | « src/heap-profiler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« src/heap-profiler.cc ('K') | « src/heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698