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

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

Issue 10886012: Release stack trace data after firing Error.stack accessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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
« no previous file with comments | « src/messages.js ('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.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index ec2fb3dd6e0e4ef85a4ceb2e9d0b7b7ab251a389..442e272c63d9c3eba81dcf148d32db77ea93da4b 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -2183,3 +2183,56 @@ TEST(IncrementalMarkingClearsPolymorhpicIC) {
Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC);
CHECK(ic_after->ic_state() == UNINITIALIZED);
}
+
+
+class SourceResource: public v8::String::ExternalAsciiStringResource {
+ public:
+ explicit SourceResource(const char* data, int* counter)
+ : data_(data), length_(strlen(data)), counter_(counter) { }
+
+ virtual void Dispose() {
+ i::DeleteArray(data_);
+ if (counter_ != NULL) ++*counter_;
+ }
+
+ const char* data() const { return data_; }
+
+ size_t length() const { return length_; }
+
+ private:
+ const char* data_;
+ size_t length_;
+ int* counter_;
+};
+
+
+TEST(ReleaseStackTraceData) {
+ // Test that the data retained by the Error.stack accessor is released
+ // after the first time the accessor is fired. We use external string
+ // to check whether the data is being released since the external string
+ // resource's callback is fired when the external string is GC'ed.
+ InitializeVM();
+ v8::HandleScope scope;
+ static const char* source = "var error = 1; "
+ "try { "
+ " throw new Error(); "
+ "} catch (e) { "
+ " error = e; "
+ "} ";
+ int counter = 0;
+ SourceResource* resource = new SourceResource(i::StrDup(source), &counter);
+ {
+ v8::HandleScope scope;
+ v8::Handle<v8::String> source_string = v8::String::NewExternal(resource);
+ v8::Script::Compile(source_string)->Run();
+ CHECK(counter == 0);
+ }
+ HEAP->CollectAllAvailableGarbage();
+ CHECK(counter == 0); // External source is being retained by the stack trace.
+
+ CompileRun("error.stack;");
+ HEAP->CollectAllAvailableGarbage();
+ CHECK(counter == 1); // External source has been released.
+
+ delete resource;
+}
« no previous file with comments | « src/messages.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698