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

Side by Side 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, 3 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 unified diff | Download patch | Annotate | Revision Log
« src/messages.js ('K') | « src/messages.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
2210 TEST(ReleaseStackTraceData) {
2211 // Test that the data retained by the Error.stack accessor is released
2212 // after the first time the accessor is fired. We use external string
2213 // to check whether the data is being released since the external string
2214 // resource's callback is fired when the external string is GC'ed.
2215 InitializeVM();
2216 v8::HandleScope scope;
2217 static const char* source = "var error = 1; "
2218 "try { "
2219 " throw new Error(); "
2220 "} catch (e) { "
2221 " error = e; "
2222 "} ";
2223 int counter = 0;
2224 SourceResource* resource = new SourceResource(i::StrDup(source), &counter);
2225 {
2226 v8::HandleScope scope;
2227 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource);
2228 v8::Script::Compile(source_string)->Run();
2229 CHECK(counter == 0);
2230 }
2231 HEAP->CollectAllAvailableGarbage();
2232 CHECK(counter == 0); // External source is being retained by the stack trace.
2233
2234 CompileRun("error.stack;");
2235 HEAP->CollectAllAvailableGarbage();
2236 CHECK(counter == 1); // External source has been released.
2237
2238 delete resource;
Vyacheslav Egorov (Google) 2012/08/28 16:43:43 thanks for writing a test!
2239 }
OLDNEW
« src/messages.js ('K') | « src/messages.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698