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

Unified Diff: runtime/vm/dart_api_impl.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: Address review comments 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 3a4056fe4cc0c779a8d8ba45b2d0896bdce4e5d0..a671845afcc25f032630a4f4dd3401b765ffd293 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -487,7 +487,7 @@ DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2,
}
-DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
+static PersistentHandle* AllocatePersistentHandle(Dart_Handle object) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
DARTSCOPE_NOCHECKS(isolate);
@@ -496,6 +496,24 @@ DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
new_ref->set_raw(old_ref);
+ return new_ref;
+}
+
+
+DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
+ PersistentHandle* new_ref = AllocatePersistentHandle(object);
+ return reinterpret_cast<Dart_Handle>(new_ref);
+}
+
+
+DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
+ Dart_Handle object,
+ void* peer,
+ Dart_PeerFinalizer callback) {
+ PersistentHandle* new_ref = AllocatePersistentHandle(object);
+ new_ref->set_kind(PersistentHandle::WeakReference);
+ new_ref->set_peer(peer);
+ new_ref->set_callback(callback);
return reinterpret_cast<Dart_Handle>(new_ref);
}
@@ -513,15 +531,16 @@ DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
}
-DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) {
- UNIMPLEMENTED();
- return NULL;
-}
-
-
-DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object) {
- UNIMPLEMENTED();
- return NULL;
+DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
+ Isolate* isolate = Isolate::Current();
+ CHECK_ISOLATE(isolate);
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ if (state->IsValidPersistentHandle(object)) {
+ PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
+ return ref->kind() == PersistentHandle::WeakReference;
+ }
+ return false;
}

Powered by Google App Engine
This is Rietveld 408576698