OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 const v8::HeapGraphNode* gc_roots = GetNode( | 1756 const v8::HeapGraphNode* gc_roots = GetNode( |
1757 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); | 1757 snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)"); |
1758 CHECK_NE(NULL, gc_roots); | 1758 CHECK_NE(NULL, gc_roots); |
1759 const v8::HeapGraphNode* global_handles = GetNode( | 1759 const v8::HeapGraphNode* global_handles = GetNode( |
1760 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); | 1760 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); |
1761 CHECK_NE(NULL, global_handles); | 1761 CHECK_NE(NULL, global_handles); |
1762 return HasWeakEdge(global_handles); | 1762 return HasWeakEdge(global_handles); |
1763 } | 1763 } |
1764 | 1764 |
1765 | 1765 |
1766 static void PersistentHandleCallback(v8::Isolate* isolate, | 1766 static void PersistentHandleCallback( |
1767 v8::Persistent<v8::Value>* handle, | 1767 const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) { |
1768 void*) { | 1768 data.GetParameter()->Reset(); |
1769 handle->Reset(); | 1769 delete data.GetParameter(); |
1770 } | 1770 } |
1771 | 1771 |
1772 | 1772 |
1773 TEST(WeakGlobalHandle) { | 1773 TEST(WeakGlobalHandle) { |
1774 LocalContext env; | 1774 LocalContext env; |
1775 v8::HandleScope scope(env->GetIsolate()); | 1775 v8::HandleScope scope(env->GetIsolate()); |
1776 | 1776 |
1777 CHECK(!HasWeakGlobalHandle()); | 1777 CHECK(!HasWeakGlobalHandle()); |
1778 | 1778 |
1779 v8::Persistent<v8::Object> handle(env->GetIsolate(), v8::Object::New()); | 1779 v8::Persistent<v8::Object>* handle = |
1780 handle.MakeWeak<v8::Value, void>(NULL, PersistentHandleCallback); | 1780 new v8::Persistent<v8::Object>(env->GetIsolate(), v8::Object::New()); |
| 1781 handle->SetWeak(handle, PersistentHandleCallback); |
1781 | 1782 |
1782 CHECK(HasWeakGlobalHandle()); | 1783 CHECK(HasWeakGlobalHandle()); |
1783 } | 1784 } |
1784 | 1785 |
1785 | 1786 |
1786 TEST(SfiAndJsFunctionWeakRefs) { | 1787 TEST(SfiAndJsFunctionWeakRefs) { |
1787 LocalContext env; | 1788 LocalContext env; |
1788 v8::HandleScope scope(env->GetIsolate()); | 1789 v8::HandleScope scope(env->GetIsolate()); |
1789 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1790 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
1790 | 1791 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2322 | 2323 |
2323 AllocationTraceNode* node = | 2324 AllocationTraceNode* node = |
2324 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2325 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2325 CHECK_NE(NULL, node); | 2326 CHECK_NE(NULL, node); |
2326 CHECK_LT(node->allocation_count(), 100); | 2327 CHECK_LT(node->allocation_count(), 100); |
2327 | 2328 |
2328 CcTest::heap()->DisableInlineAllocation(); | 2329 CcTest::heap()->DisableInlineAllocation(); |
2329 heap_profiler->StopTrackingHeapObjects(); | 2330 heap_profiler->StopTrackingHeapObjects(); |
2330 } | 2331 } |
2331 } | 2332 } |
OLD | NEW |