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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 9655011: Implement prologue weak persistent handles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor pre-review changes Created 8 years, 9 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
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 48c53517a23a73bac9010a74c7b304ce10b0f314..959dfe906cccbf7902ddcf86c655e1b641a45fa9 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1561,6 +1561,64 @@ TEST_CASE(ObjectGroups) {
}
+TEST_CASE(PrologueWeakPersistentHandles) {
+ Dart_Handle old_pwph = Dart_Null();
+ EXPECT(Dart_IsNull(old_pwph));
+ Dart_Handle new_pwph = Dart_Null();
+ EXPECT(Dart_IsNull(new_pwph));
+ Dart_EnterScope();
+ {
+ DARTSCOPE(Isolate::Current());
+ String& str = String::Handle();
+ str ^= String::New("new space prologue weak", Heap::kNew);
+ new_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str),
+ NULL,
+ NULL);
+ EXPECT_VALID(new_pwph);
+ EXPECT(!Dart_IsNull(new_pwph));
+ str ^= String::New("old space prologue weak", Heap::kOld);
+ old_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str),
+ NULL,
+ NULL);
+ EXPECT_VALID(old_pwph);
+ EXPECT(!Dart_IsNull(old_pwph));
+ str ^= String::null();
+ }
+ Dart_ExitScope();
+ EXPECT_VALID(new_pwph);
+ EXPECT(!Dart_IsNull(new_pwph));
+ EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph));
+ EXPECT_VALID(old_pwph);
+ EXPECT(!Dart_IsNull(old_pwph));
+ EXPECT(Dart_IsPrologueWeakPersistentHandle(old_pwph));
+ // Garbage collect new space without invoking API callbacks.
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
+ Heap::kIgnoreApiCallbacks);
+ // Both prologue weak handles should be preserved.
+ EXPECT(!Dart_IsNull(new_pwph));
+ EXPECT(!Dart_IsNull(old_pwph));
+ // Garbage collect old space without invoking API callbacks.
+ Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
+ Heap::kIgnoreApiCallbacks);
+ // Both prologue weak handles should be preserved.
+ EXPECT(!Dart_IsNull(new_pwph));
+ EXPECT(!Dart_IsNull(old_pwph));
+ // Garbage collect new space invoking API callbacks.
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
+ Heap::kInvokeApiCallbacks);
+ // The prologue weak handle with a new space referent should now be
+ // cleared. The old space referent should be preserved.
+ EXPECT(Dart_IsNull(new_pwph));
+ EXPECT(!Dart_IsNull(old_pwph));
+ Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
+ Heap::kInvokeApiCallbacks);
+ // The prologue weak handle with an old space referent should now be
+ // cleared. The new space referent should remain cleared.
+ EXPECT(Dart_IsNull(new_pwph));
+ EXPECT(Dart_IsNull(old_pwph));
+}
+
+
TEST_CASE(ImplicitReferences) {
Dart_Handle strong = Dart_Null();
EXPECT(Dart_IsNull(strong));

Powered by Google App Engine
This is Rietveld 408576698