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

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

Issue 8984006: Implement weak persistent handles in the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix whitespace. Created 9 years 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 757
758 // Make sure that the value transferred. 758 // Make sure that the value transferred.
759 EXPECT(Dart_IsBoolean(obj2)); 759 EXPECT(Dart_IsBoolean(obj2));
760 bool value = false; 760 bool value = false;
761 Dart_Handle result = Dart_BooleanValue(obj2, &value); 761 Dart_Handle result = Dart_BooleanValue(obj2, &value);
762 EXPECT_VALID(result); 762 EXPECT_VALID(result);
763 EXPECT(value); 763 EXPECT(value);
764 } 764 }
765 765
766 766
767 TEST_CASE(WeakPersistentHandle) {
768 Dart_Handle weak_new_ref = Dart_Null();
769 EXPECT(Dart_IsNull(weak_new_ref));
770
771 Dart_Handle weak_old_ref = Dart_Null();
772 EXPECT(Dart_IsNull(weak_old_ref));
773
774 {
775 Dart_EnterScope();
776
777 // create an object in new space
778 Dart_Handle new_ref = Dart_NewString("new string");
779 EXPECT_VALID(new_ref);
780
781 // create an object in old space
782 Dart_Handle old_ref;
783 {
784 DARTSCOPE(Isolate::Current());
785 const String& str =
786 String::Handle(String::New("old string", Heap::kOld));
787 old_ref = Api::NewLocalHandle(str);
788 EXPECT_VALID(old_ref);
789 }
790
791 // create a weak ref to the new space object
792 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref);
793 EXPECT_VALID(weak_new_ref);
794 EXPECT(!Dart_IsNull(weak_new_ref));
795
796 // create a weak ref to the old space object
797 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref);
798 EXPECT_VALID(weak_old_ref);
799 EXPECT(!Dart_IsNull(weak_old_ref));
800
801 // garbage collect new space
802 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
803
804 // nothing should be invalidated or cleared
Ivan Posva 2011/12/19 22:41:36 Also the weak and non-weak handles should still be
cshapiro 2011/12/20 00:58:57 Sounds good. Done.
805 EXPECT_VALID(new_ref);
806 EXPECT(!Dart_IsNull(new_ref));
807 EXPECT_VALID(old_ref);
808 EXPECT(!Dart_IsNull(old_ref));
809 EXPECT_VALID(weak_new_ref);
810 EXPECT(!Dart_IsNull(weak_new_ref));
811 EXPECT_VALID(weak_old_ref);
812 EXPECT(!Dart_IsNull(weak_old_ref));
813
814 // garbage collect old space
815 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
816
817 // nothing should be invalidated or cleared
Ivan Posva 2011/12/19 22:41:36 ditto.
cshapiro 2011/12/20 00:58:57 Done.
818 EXPECT_VALID(new_ref);
819 EXPECT(!Dart_IsNull(new_ref));
820 EXPECT_VALID(old_ref);
821 EXPECT(!Dart_IsNull(old_ref));
822 EXPECT_VALID(weak_new_ref);
823 EXPECT(!Dart_IsNull(weak_new_ref));
824 EXPECT_VALID(weak_old_ref);
825 EXPECT(!Dart_IsNull(weak_old_ref));
826
827 // delete local (strong) references
828 Dart_ExitScope();
829 }
830
831 // garbage collect new space again
832 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
833
834 // weak ref to new space object should now be cleared
835 EXPECT_VALID(weak_new_ref);
836 EXPECT(Dart_IsNull(weak_new_ref));
837 EXPECT_VALID(weak_old_ref);
838 EXPECT(!Dart_IsNull(weak_old_ref));
839
840 // garbage collect old space again
841 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
842
843 // weak ref to old space object should now be cleared
844 EXPECT_VALID(weak_new_ref);
845 EXPECT(Dart_IsNull(weak_new_ref));
846 EXPECT_VALID(weak_old_ref);
847 EXPECT(Dart_IsNull(weak_old_ref));
848 }
849
850
767 // Unit test for creating multiple scopes and local handles within them. 851 // Unit test for creating multiple scopes and local handles within them.
768 // Ensure that the local handles get all cleaned out when exiting the 852 // Ensure that the local handles get all cleaned out when exiting the
769 // scope. 853 // scope.
770 UNIT_TEST_CASE(LocalHandles) { 854 UNIT_TEST_CASE(LocalHandles) {
771 TestCase::CreateTestIsolate(); 855 TestCase::CreateTestIsolate();
772 Isolate* isolate = Isolate::Current(); 856 Isolate* isolate = Isolate::Current();
773 EXPECT(isolate != NULL); 857 EXPECT(isolate != NULL);
774 ApiState* state = isolate->api_state(); 858 ApiState* state = isolate->api_state();
775 EXPECT(state != NULL); 859 EXPECT(state != NULL);
776 ApiLocalScope* scope = state->top_scope(); 860 ApiLocalScope* scope = state->top_scope();
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2966 EXPECT_EQ(3, interrupt_count); 3050 EXPECT_EQ(3, interrupt_count);
2967 3051
2968 // Give the spawned thread enough time to properly exit. 3052 // Give the spawned thread enough time to properly exit.
2969 OS::Sleep(20); 3053 OS::Sleep(20);
2970 Isolate::SetInterruptCallback(saved); 3054 Isolate::SetInterruptCallback(saved);
2971 } 3055 }
2972 3056
2973 #endif // TARGET_ARCH_IA32. 3057 #endif // TARGET_ARCH_IA32.
2974 3058
2975 } // namespace dart 3059 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698