OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 CHECK(ic_before->ic_state() == MEGAMORPHIC); | 2176 CHECK(ic_before->ic_state() == MEGAMORPHIC); |
2177 | 2177 |
2178 // Fire context dispose notification. | 2178 // Fire context dispose notification. |
2179 v8::V8::ContextDisposedNotification(); | 2179 v8::V8::ContextDisposedNotification(); |
2180 SimulateIncrementalMarking(); | 2180 SimulateIncrementalMarking(); |
2181 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2181 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2182 | 2182 |
2183 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2183 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2184 CHECK(ic_after->ic_state() == UNINITIALIZED); | 2184 CHECK(ic_after->ic_state() == UNINITIALIZED); |
2185 } | 2185 } |
| 2186 |
| 2187 |
| 2188 class SourceResource: public v8::String::ExternalAsciiStringResource { |
| 2189 public: |
| 2190 explicit SourceResource(const char* data, int* counter) |
| 2191 : data_(data), length_(strlen(data)), counter_(counter) { } |
| 2192 |
| 2193 virtual void Dispose() { |
| 2194 i::DeleteArray(data_); |
| 2195 if (counter_ != NULL) ++*counter_; |
| 2196 } |
| 2197 |
| 2198 const char* data() const { return data_; } |
| 2199 |
| 2200 size_t length() const { return length_; } |
| 2201 |
| 2202 private: |
| 2203 const char* data_; |
| 2204 size_t length_; |
| 2205 int* counter_; |
| 2206 }; |
| 2207 |
| 2208 |
| 2209 TEST(ReleaseStackTraceData) { |
| 2210 // Test that the data retained by the Error.stack accessor is released |
| 2211 // after the first time the accessor is fired. We use external string |
| 2212 // to check whether the data is being released since the external string |
| 2213 // resource's callback is fired when the external string is GC'ed. |
| 2214 InitializeVM(); |
| 2215 v8::HandleScope scope; |
| 2216 static const char* source = "var error = 1; " |
| 2217 "try { " |
| 2218 " throw new Error(); " |
| 2219 "} catch (e) { " |
| 2220 " error = e; " |
| 2221 "} "; |
| 2222 int counter = 0; |
| 2223 SourceResource* resource = new SourceResource(i::StrDup(source), &counter); |
| 2224 { |
| 2225 v8::HandleScope scope; |
| 2226 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); |
| 2227 v8::Script::Compile(source_string)->Run(); |
| 2228 CHECK(counter == 0); |
| 2229 } |
| 2230 HEAP->CollectAllAvailableGarbage(); |
| 2231 CHECK(counter == 0); // External source is being retained by the stack trace. |
| 2232 |
| 2233 CompileRun("error.stack;"); |
| 2234 HEAP->CollectAllAvailableGarbage(); |
| 2235 CHECK(counter == 1); // External source has been released. |
| 2236 |
| 2237 delete resource; |
| 2238 } |
OLD | NEW |