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

Unified 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: address review comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_api_state.h » ('j') | 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 c740d5d164e00d716990521f60cc659115f18f02..6736e8cfc55fc1d7f1983e63ae199a4530634e6c 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -831,6 +831,37 @@ TEST_CASE(WeakPersistentHandle) {
EXPECT(Dart_IsNull(weak_new_ref));
EXPECT_VALID(weak_old_ref);
EXPECT(Dart_IsNull(weak_old_ref));
+
+ Dart_DeletePersistentHandle(weak_new_ref);
+ Dart_DeletePersistentHandle(weak_old_ref);
+}
+
+
+static void WeakPersistentHandlePeerFinalizer(void* peer) {
+ *static_cast<int*>(peer) = 42;
+}
+
+
+TEST_CASE(WeakPersistentHandleCallback) {
+ Dart_Handle weak_ref = Dart_Null();
+ EXPECT(Dart_IsNull(weak_ref));
+ int* peer = new int();
+ {
+ Dart_EnterScope();
+ Dart_Handle obj = Dart_NewString("new string");
+ EXPECT_VALID(obj);
+ weak_ref = Dart_NewWeakPersistentHandle(obj, peer,
+ WeakPersistentHandlePeerFinalizer);
+ Dart_ExitScope();
+ }
+ EXPECT_VALID(weak_ref);
+ EXPECT(*peer == 0);
+ Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
+ EXPECT(*peer == 0);
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
+ EXPECT(*peer == 42);
+ delete peer;
+ Dart_DeletePersistentHandle(weak_ref);
}
#endif
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698