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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 9148051: Provide API support for weak handles and post-mortem finalization. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: a better strategy for protected handle checks Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/thread.h" 10 #include "vm/thread.h"
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 EXPECT(!Dart_IsNull(weak_old_ref)); 824 EXPECT(!Dart_IsNull(weak_old_ref));
825 825
826 // garbage collect old space again 826 // garbage collect old space again
827 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 827 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
828 828
829 // weak ref to old space object should now be cleared 829 // weak ref to old space object should now be cleared
830 EXPECT_VALID(weak_new_ref); 830 EXPECT_VALID(weak_new_ref);
831 EXPECT(Dart_IsNull(weak_new_ref)); 831 EXPECT(Dart_IsNull(weak_new_ref));
832 EXPECT_VALID(weak_old_ref); 832 EXPECT_VALID(weak_old_ref);
833 EXPECT(Dart_IsNull(weak_old_ref)); 833 EXPECT(Dart_IsNull(weak_old_ref));
834
835 Dart_DeletePersistentHandle(weak_new_ref);
836 Dart_DeletePersistentHandle(weak_old_ref);
837 }
838
839
840 static void WeakPersistentHandlePeerFinalizer(void* peer) {
841 *static_cast<int*>(peer) = 42;
842 }
843
844
845 TEST_CASE(WeakPersistentHandleCallback) {
846 Dart_Handle weak_ref = Dart_Null();
847 EXPECT(Dart_IsNull(weak_ref));
848 int* peer = new int();
849 {
850 Dart_EnterScope();
851 Dart_Handle obj = Dart_NewString("new string");
852 EXPECT_VALID(obj);
853 weak_ref = Dart_NewWeakPersistentHandle(obj, peer,
854 WeakPersistentHandlePeerFinalizer);
855 Dart_ExitScope();
856 }
857 EXPECT_VALID(weak_ref);
858 EXPECT(*peer == 0);
859 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
860 EXPECT(*peer == 0);
861 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
862 EXPECT(*peer == 42);
863 delete peer;
864 Dart_DeletePersistentHandle(weak_ref);
834 } 865 }
835 866
836 #endif 867 #endif
837 868
838 869
839 // Unit test for creating multiple scopes and local handles within them. 870 // Unit test for creating multiple scopes and local handles within them.
840 // Ensure that the local handles get all cleaned out when exiting the 871 // Ensure that the local handles get all cleaned out when exiting the
841 // scope. 872 // scope.
842 UNIT_TEST_CASE(LocalHandles) { 873 UNIT_TEST_CASE(LocalHandles) {
843 TestCase::CreateTestIsolate(); 874 TestCase::CreateTestIsolate();
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2971 // We should have received the expected number of interrupts. 3002 // We should have received the expected number of interrupts.
2972 EXPECT_EQ(kInterruptCount, interrupt_count); 3003 EXPECT_EQ(kInterruptCount, interrupt_count);
2973 3004
2974 // Give the spawned thread enough time to properly exit. 3005 // Give the spawned thread enough time to properly exit.
2975 Isolate::SetInterruptCallback(saved); 3006 Isolate::SetInterruptCallback(saved);
2976 } 3007 }
2977 3008
2978 #endif // TARGET_ARCH_IA32. 3009 #endif // TARGET_ARCH_IA32.
2979 3010
2980 } // namespace dart 3011 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698