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 "compilation-cache.h" | 7 #include "compilation-cache.h" |
8 #include "execution.h" | 8 #include "execution.h" |
9 #include "factory.h" | 9 #include "factory.h" |
10 #include "macro-assembler.h" | 10 #include "macro-assembler.h" |
(...skipping 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 size_t length() const { return length_; } | 2344 size_t length() const { return length_; } |
2345 | 2345 |
2346 bool IsDisposed() { return data_ == NULL; } | 2346 bool IsDisposed() { return data_ == NULL; } |
2347 | 2347 |
2348 private: | 2348 private: |
2349 const char* data_; | 2349 const char* data_; |
2350 size_t length_; | 2350 size_t length_; |
2351 }; | 2351 }; |
2352 | 2352 |
2353 | 2353 |
2354 TEST(ReleaseStackTraceData) { | 2354 void ReleaseStackTraceDataTest(const char* source) { |
2355 // Test that the data retained by the Error.stack accessor is released | 2355 // Test that the data retained by the Error.stack accessor is released |
2356 // after the first time the accessor is fired. We use external string | 2356 // after the first time the accessor is fired. We use external string |
2357 // to check whether the data is being released since the external string | 2357 // to check whether the data is being released since the external string |
2358 // resource's callback is fired when the external string is GC'ed. | 2358 // resource's callback is fired when the external string is GC'ed. |
2359 InitializeVM(); | 2359 InitializeVM(); |
2360 v8::HandleScope scope; | 2360 v8::HandleScope scope; |
2361 static const char* source = "var error = 1; " | |
2362 "try { " | |
2363 " throw new Error(); " | |
2364 "} catch (e) { " | |
2365 " error = e; " | |
2366 "} "; | |
2367 SourceResource* resource = new SourceResource(i::StrDup(source)); | 2361 SourceResource* resource = new SourceResource(i::StrDup(source)); |
2368 { | 2362 { |
2369 v8::HandleScope scope; | 2363 v8::HandleScope scope; |
2370 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); | 2364 v8::Handle<v8::String> source_string = v8::String::NewExternal(resource); |
2371 v8::Script::Compile(source_string)->Run(); | 2365 v8::Script::Compile(source_string)->Run(); |
2372 CHECK(!resource->IsDisposed()); | 2366 CHECK(!resource->IsDisposed()); |
2373 } | 2367 } |
2374 HEAP->CollectAllAvailableGarbage(); | 2368 HEAP->CollectAllAvailableGarbage(); |
2375 // External source is being retained by the stack trace. | 2369 // External source is being retained by the stack trace. |
2376 CHECK(!resource->IsDisposed()); | 2370 CHECK(!resource->IsDisposed()); |
2377 | 2371 |
2378 CompileRun("error.stack; error.stack;"); | 2372 CompileRun("error.stack;"); |
2379 HEAP->CollectAllAvailableGarbage(); | 2373 HEAP->CollectAllAvailableGarbage(); |
2380 // External source has been released. | 2374 // External source has been released. |
2381 CHECK(resource->IsDisposed()); | 2375 CHECK(resource->IsDisposed()); |
| 2376 delete resource; |
| 2377 } |
2382 | 2378 |
2383 delete resource; | 2379 |
| 2380 TEST(ReleaseStackTraceData) { |
| 2381 static const char* source1 = "var error = null; " |
| 2382 /* Normal Error */ "try { " |
| 2383 " throw new Error(); " |
| 2384 "} catch (e) { " |
| 2385 " error = e; " |
| 2386 "} "; |
| 2387 static const char* source2 = "var error = null; " |
| 2388 /* Stack overflow */ "try { " |
| 2389 " (function f() { f(); })(); " |
| 2390 "} catch (e) { " |
| 2391 " error = e; " |
| 2392 "} "; |
| 2393 ReleaseStackTraceDataTest(source1); |
| 2394 ReleaseStackTraceDataTest(source2); |
2384 } | 2395 } |
2385 | 2396 |
2386 | 2397 |
2387 TEST(Regression144230) { | 2398 TEST(Regression144230) { |
2388 InitializeVM(); | 2399 InitializeVM(); |
2389 v8::HandleScope scope; | 2400 v8::HandleScope scope; |
2390 | 2401 |
2391 // First make sure that the uninitialized CallIC stub is on a single page | 2402 // First make sure that the uninitialized CallIC stub is on a single page |
2392 // that will later be selected as an evacuation candidate. | 2403 // that will later be selected as an evacuation candidate. |
2393 { | 2404 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2434 Handle<Object> call_function(call); | 2445 Handle<Object> call_function(call); |
2435 | 2446 |
2436 // Now we are ready to mess up the heap. | 2447 // Now we are ready to mess up the heap. |
2437 HEAP->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); | 2448 HEAP->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); |
2438 | 2449 |
2439 // Either heap verification caught the problem already or we go kaboom once | 2450 // Either heap verification caught the problem already or we go kaboom once |
2440 // the CallIC is executed the next time. | 2451 // the CallIC is executed the next time. |
2441 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); | 2452 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); |
2442 CompileRun("call();"); | 2453 CompileRun("call();"); |
2443 } | 2454 } |
OLD | NEW |