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

Unified Diff: runtime/vm/dart_api_state.h

Issue 2640573003: Resolution for issue #5092: Unit test handle checks consider dangling handles to be valid. (Closed)
Patch Set: Removed Dart API entry for IsValid. Created 3 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
Index: runtime/vm/dart_api_state.h
diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h
index 1bff38cb7e745fb840fce9248ad5ed08ecfe3a4c..3ca4f728b0da255ed68ab03ba171bb7cbb50a1b6 100644
--- a/runtime/vm/dart_api_state.h
+++ b/runtime/vm/dart_api_state.h
@@ -512,6 +512,17 @@ class PersistentHandles : Handles<kPersistentHandleSizeInWords,
return IsValidScopedHandle(reinterpret_cast<uword>(object));
}
+ bool IsFreeHandle(Dart_PersistentHandle object) const {
+ PersistentHandle* handle = free_list_;
+ while (handle != NULL) {
+ if (handle == reinterpret_cast<PersistentHandle*>(object)) {
+ return true;
+ }
+ handle = handle->Next();
+ }
+ return false;
+ }
+
// Returns a count of active handles (used for testing purposes).
int CountHandles() const { return CountScopedHandles(); }
@@ -594,6 +605,18 @@ class FinalizablePersistentHandles
return IsValidScopedHandle(reinterpret_cast<uword>(object));
}
+ bool IsFreeHandle(Dart_WeakPersistentHandle object) const {
+ MutexLocker ml(mutex_);
+ FinalizablePersistentHandle* handle = free_list_;
+ while (handle != NULL) {
+ if (handle == reinterpret_cast<FinalizablePersistentHandle*>(object)) {
+ return true;
+ }
+ handle = handle->Next();
+ }
+ return false;
+ }
+
// Returns a count of active handles (used for testing purposes).
int CountHandles() const { return CountScopedHandles(); }
@@ -742,10 +765,27 @@ class ApiState {
return persistent_handles_.IsValidHandle(object);
}
+ bool IsFreePersistentHandle(Dart_PersistentHandle object) const {
+ return persistent_handles_.IsFreeHandle(object);
+ }
+
+ bool IsActivePersistentHandle(Dart_PersistentHandle object) const {
+ return IsValidPersistentHandle(object) && !IsFreePersistentHandle(object);
+ }
+
bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object) const {
return weak_persistent_handles_.IsValidHandle(object);
}
+ bool IsFreeWeakPersistentHandle(Dart_WeakPersistentHandle object) const {
+ return weak_persistent_handles_.IsFreeHandle(object);
+ }
+
+ bool IsActiveWeakPersistentHandle(Dart_WeakPersistentHandle object) const {
+ return IsValidWeakPersistentHandle(object) &&
+ !IsFreeWeakPersistentHandle(object);
+ }
+
bool IsProtectedHandle(PersistentHandle* object) const {
if (object == NULL) return false;
return object == null_ || object == true_ || object == false_;

Powered by Google App Engine
This is Rietveld 408576698