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; |
+} |