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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 10916185: New test case to ensure finalizers are not invoked on deleted handles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 511ef579d0613f49cb6eae1bccf6b271bb07d77f..9282ae0c91ab4e9dee54644a012f31d75eb21b81 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1418,23 +1418,44 @@ static void WeakPersistentHandlePeerFinalizer(Dart_Handle handle, void* peer) {
TEST_CASE(WeakPersistentHandleCallback) {
Dart_Handle weak_ref = Dart_Null();
EXPECT(Dart_IsNull(weak_ref));
- int* peer = new int();
+ int peer = 0;
{
Dart_EnterScope();
Dart_Handle obj = Dart_NewString("new string");
EXPECT_VALID(obj);
- weak_ref = Dart_NewWeakPersistentHandle(obj, peer,
+ weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
WeakPersistentHandlePeerFinalizer);
Dart_ExitScope();
}
EXPECT_VALID(weak_ref);
- EXPECT(*peer == 0);
+ EXPECT(peer == 0);
Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
- EXPECT(*peer == 0);
+ EXPECT(peer == 0);
GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
- EXPECT(*peer == 42);
- delete peer;
+ EXPECT(peer == 42);
+ Dart_DeletePersistentHandle(weak_ref);
+}
+
+
+TEST_CASE(WeakPersistentHandleNoCallback) {
+ Dart_Handle weak_ref = Dart_Null();
+ EXPECT(Dart_IsNull(weak_ref));
+ int peer = 0;
+ {
+ Dart_EnterScope();
+ Dart_Handle obj = Dart_NewString("new string");
+ EXPECT_VALID(obj);
+ weak_ref = Dart_NewWeakPersistentHandle(obj, &peer,
+ WeakPersistentHandlePeerFinalizer);
+ Dart_ExitScope();
+ }
Dart_DeletePersistentHandle(weak_ref);
hausner 2012/09/07 22:19:42 Maybe add a comment that the finalizer should not
cshapiro 2012/09/07 22:32:22 Thanks, that is a good idea. Done.
+ EXPECT_VALID(weak_ref);
+ EXPECT(peer == 0);
+ Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ EXPECT(peer == 0);
+ GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks);
+ EXPECT(peer == 0);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698