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

Unified Diff: runtime/vm/dart_api_impl.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.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 3a6f0aedd7af6421757bca0fe544bb6340e9e548..4d6140c65b69bf92479e6e8979a3a1a4303c3ad4 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -155,9 +155,11 @@ RawObject* Api::UnwrapHandle(Dart_Handle object) {
ASSERT(isolate != NULL);
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- ASSERT(state->IsValidPersistentHandle(object) ||
+ ASSERT(state->IsValidWeakPersistentHandle(object) ||
+ state->IsValidPersistentHandle(object) ||
state->IsValidLocalHandle(object));
- ASSERT(PersistentHandle::raw_offset() == 0 &&
+ ASSERT(WeakPersistentHandle::raw_offset() == 0 &&
+ PersistentHandle::raw_offset() == 0 &&
LocalHandle::raw_offset() == 0);
#endif
return *(reinterpret_cast<RawObject**>(object));
@@ -190,6 +192,13 @@ PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state,
}
+WeakPersistentHandle* Api::UnwrapAsWeakPersistentHandle(const ApiState& state,
+ Dart_Handle object) {
+ ASSERT(state.IsValidWeakPersistentHandle(object));
+ return reinterpret_cast<WeakPersistentHandle*>(object);
+}
+
+
Dart_Isolate Api::CastIsolate(Isolate* isolate) {
return reinterpret_cast<Dart_Isolate>(isolate);
}
@@ -457,7 +466,7 @@ DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2,
}
-static PersistentHandle* AllocatePersistentHandle(Dart_Handle object) {
+DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
DARTSCOPE_NOCHECKS(isolate);
@@ -466,12 +475,6 @@ static PersistentHandle* AllocatePersistentHandle(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);
}
@@ -480,8 +483,15 @@ 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);
+ Isolate* isolate = Isolate::Current();
+ CHECK_ISOLATE(isolate);
+ DARTSCOPE_NOCHECKS(isolate);
+ ApiState* state = isolate->api_state();
+ ASSERT(state != NULL);
+ const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
+ WeakPersistentHandle* new_ref =
+ state->weak_persistent_handles().AllocateHandle();
+ new_ref->set_raw(old_ref);
new_ref->set_peer(peer);
new_ref->set_callback(callback);
return reinterpret_cast<Dart_Handle>(new_ref);
@@ -493,10 +503,16 @@ DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
CHECK_ISOLATE(isolate);
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
- ASSERT(!ref->IsProtected());
- if (!ref->IsProtected()) {
- state->persistent_handles().FreeHandle(ref);
+ if (state->IsValidWeakPersistentHandle(object)) {
+ WeakPersistentHandle* weak_ref =
+ Api::UnwrapAsWeakPersistentHandle(*state, object);
+ state->weak_persistent_handles().FreeHandle(weak_ref);
+ } else {
+ PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
+ ASSERT(!state->IsProtectedHandle(ref));
+ if (!state->IsProtectedHandle(ref)) {
+ state->persistent_handles().FreeHandle(ref);
+ }
}
}
@@ -506,11 +522,7 @@ DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
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;
+ return state->IsValidWeakPersistentHandle(object);
}
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698