Chromium Code Reviews| 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..a2d1cfc9ffef8374181a5c23b71709b61e0b3d5e 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,23 @@ 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); |
| + new_ref->set_kind(PersistentHandle::StrongReference); |
| + return reinterpret_cast<Dart_Handle>(new_ref); |
| +} |
| + |
| + |
| +DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( |
| + Dart_Handle object, |
| + Dart_PeerFinalizer callback) { |
|
Ivan Posva
2011/12/19 22:41:36
We will need to add the peer pointer here.
cshapiro
2011/12/20 00:58:57
Sure. I was going to leave this for the next chan
|
| + PersistentHandle* new_ref = AllocatePersistentHandle(object); |
| + new_ref->set_kind(PersistentHandle::WeakReference); |
| + new_ref->set_callback(reinterpret_cast<void*>(callback)); |
| return reinterpret_cast<Dart_Handle>(new_ref); |
| } |
| @@ -513,15 +530,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; |
| } |