| Index: runtime/vm/dart_api_impl.cc
|
| ===================================================================
|
| --- runtime/vm/dart_api_impl.cc (revision 22905)
|
| +++ runtime/vm/dart_api_impl.cc (working copy)
|
| @@ -36,6 +36,9 @@
|
| DECLARE_FLAG(bool, print_class_table);
|
|
|
| ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey;
|
| +Dart_Handle Api::true_handle_ = NULL;
|
| +Dart_Handle Api::false_handle_ = NULL;
|
| +Dart_Handle Api::null_handle_ = NULL;
|
|
|
|
|
| const char* CanonicalFunction(const char* func) {
|
| @@ -94,10 +97,7 @@
|
| ASSERT(isolate != NULL);
|
| ApiState* state = isolate->api_state();
|
| ASSERT(state != NULL);
|
| - ASSERT(state->IsValidLocalHandle(object) ||
|
| - state->IsValidPersistentHandle(object) ||
|
| - state->IsValidWeakPersistentHandle(object) ||
|
| - state->IsValidPrologueWeakPersistentHandle(object));
|
| + ASSERT(state->IsValidLocalHandle(object));
|
| ASSERT(FinalizablePersistentHandle::raw_offset() == 0 &&
|
| PersistentHandle::raw_offset() == 0 &&
|
| LocalHandle::raw_offset() == 0);
|
| @@ -126,7 +126,7 @@
|
|
|
|
|
| PersistentHandle* Api::UnwrapAsPersistentHandle(const ApiState& state,
|
| - Dart_Handle object) {
|
| + Dart_PersistentHandle object) {
|
| ASSERT(state.IsValidPersistentHandle(object));
|
| return reinterpret_cast<PersistentHandle*>(object);
|
| }
|
| @@ -134,7 +134,7 @@
|
|
|
| FinalizablePersistentHandle* Api::UnwrapAsWeakPersistentHandle(
|
| const ApiState& state,
|
| - Dart_Handle object) {
|
| + Dart_WeakPersistentHandle object) {
|
| ASSERT(state.IsValidWeakPersistentHandle(object));
|
| return reinterpret_cast<FinalizablePersistentHandle*>(object);
|
| }
|
| @@ -142,7 +142,7 @@
|
|
|
| FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle(
|
| const ApiState& state,
|
| - Dart_Handle object) {
|
| + Dart_WeakPersistentHandle object) {
|
| ASSERT(state.IsValidPrologueWeakPersistentHandle(object));
|
| return reinterpret_cast<FinalizablePersistentHandle*>(object);
|
| }
|
| @@ -211,29 +211,17 @@
|
|
|
|
|
| Dart_Handle Api::Null(Isolate* isolate) {
|
| - ASSERT(isolate != NULL);
|
| - ApiState* state = isolate->api_state();
|
| - ASSERT(state != NULL);
|
| - PersistentHandle* null_handle = state->Null();
|
| - return reinterpret_cast<Dart_Handle>(null_handle);
|
| + return Api::NewHandle(isolate, Object::null());
|
| }
|
|
|
|
|
| Dart_Handle Api::True(Isolate* isolate) {
|
| - ASSERT(isolate != NULL);
|
| - ApiState* state = isolate->api_state();
|
| - ASSERT(state != NULL);
|
| - PersistentHandle* true_handle = state->True();
|
| - return reinterpret_cast<Dart_Handle>(true_handle);
|
| + return Api::NewHandle(isolate, Bool::True().raw());
|
| }
|
|
|
|
|
| Dart_Handle Api::False(Isolate* isolate) {
|
| - ASSERT(isolate != NULL);
|
| - ApiState* state = isolate->api_state();
|
| - ASSERT(state != NULL);
|
| - PersistentHandle* false_handle = state->False();
|
| - return reinterpret_cast<Dart_Handle>(false_handle);
|
| + return Api::NewHandle(isolate, Bool::False().raw());
|
| }
|
|
|
|
|
| @@ -254,6 +242,23 @@
|
| }
|
|
|
|
|
| +void Api::InitHandles() {
|
| + Isolate* isolate = Isolate::Current();
|
| + ASSERT(isolate != NULL);
|
| + ASSERT(isolate == Dart::vm_isolate());
|
| + ApiState* state = isolate->api_state();
|
| + ASSERT(state != NULL);
|
| + ASSERT(true_handle_ == NULL);
|
| + true_handle_ = Api::NewHandle(isolate, Bool::True().raw());
|
| +
|
| + ASSERT(false_handle_ == NULL);
|
| + false_handle_ = Api::NewHandle(isolate, Bool::False().raw());
|
| +
|
| + ASSERT(null_handle_ == NULL);
|
| + null_handle_ = Api::NewHandle(isolate, Object::null());
|
| +}
|
| +
|
| +
|
| bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) {
|
| NoGCScope no_gc_scope;
|
| RawObject* raw_obj = Api::UnwrapHandle(object);
|
| @@ -524,18 +529,38 @@
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) {
|
| +DART_EXPORT Dart_Handle Dart_NewHandleFromPersistent(Dart_PersistentHandle object) {
|
| Isolate* isolate = Isolate::Current();
|
| DARTSCOPE(isolate);
|
| ApiState* state = isolate->api_state();
|
| ASSERT(state != NULL);
|
| + ASSERT(state->IsValidPersistentHandle(object));
|
| + return Api::NewHandle(isolate, reinterpret_cast<PersistentHandle*>(object)->raw());
|
| +}
|
| +
|
| +
|
| +DART_EXPORT Dart_Handle Dart_NewHandleFromWeakPersistent(Dart_WeakPersistentHandle object) {
|
| + Isolate* isolate = Isolate::Current();
|
| + DARTSCOPE(isolate);
|
| + ApiState* state = isolate->api_state();
|
| + ASSERT(state != NULL);
|
| + ASSERT(state->IsValidWeakPersistentHandle(object));
|
| + return Api::NewHandle(isolate, reinterpret_cast<FinalizablePersistentHandle*>(object)->raw());
|
| +}
|
| +
|
| +
|
| +DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) {
|
| + Isolate* isolate = Isolate::Current();
|
| + DARTSCOPE(isolate);
|
| + ApiState* state = isolate->api_state();
|
| + ASSERT(state != NULL);
|
| const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object));
|
| PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
|
| new_ref->set_raw(old_ref);
|
| - return reinterpret_cast<Dart_Handle>(new_ref);
|
| + return reinterpret_cast<Dart_PersistentHandle>(new_ref);
|
| }
|
|
|
| -static Dart_Handle AllocateFinalizableHandle(
|
| +static Dart_WeakPersistentHandle AllocateFinalizableHandle(
|
| Isolate* isolate,
|
| FinalizablePersistentHandles* handles,
|
| Dart_Handle object,
|
| @@ -546,11 +571,11 @@
|
| finalizable_ref->set_raw(ref);
|
| finalizable_ref->set_peer(peer);
|
| finalizable_ref->set_callback(callback);
|
| - return reinterpret_cast<Dart_Handle>(finalizable_ref);
|
| + return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref);
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
|
| +DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
|
| Dart_Handle object,
|
| void* peer,
|
| Dart_WeakPersistentHandleFinalizer callback) {
|
| @@ -566,7 +591,7 @@
|
| }
|
|
|
|
|
| -DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle(
|
| +DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle(
|
| Dart_Handle object,
|
| void* peer,
|
| Dart_WeakPersistentHandleFinalizer callback) {
|
| @@ -582,32 +607,38 @@
|
| }
|
|
|
|
|
| -DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
|
| +DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) {
|
| Isolate* isolate = Isolate::Current();
|
| CHECK_ISOLATE(isolate);
|
| ApiState* state = isolate->api_state();
|
| ASSERT(state != NULL);
|
| + PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
|
| + ASSERT(!state->IsProtectedHandle(ref));
|
| + if (!state->IsProtectedHandle(ref)) {
|
| + state->persistent_handles().FreeHandle(ref);
|
| + }
|
| +}
|
| +
|
| +
|
| +DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle object) {
|
| + Isolate* isolate = Isolate::Current();
|
| + CHECK_ISOLATE(isolate);
|
| + ApiState* state = isolate->api_state();
|
| + ASSERT(state != NULL);
|
| if (state->IsValidPrologueWeakPersistentHandle(object)) {
|
| FinalizablePersistentHandle* prologue_weak_ref =
|
| Api::UnwrapAsPrologueWeakPersistentHandle(*state, object);
|
| state->prologue_weak_persistent_handles().FreeHandle(prologue_weak_ref);
|
| return;
|
| }
|
| - if (state->IsValidWeakPersistentHandle(object)) {
|
| - FinalizablePersistentHandle* weak_ref =
|
| - Api::UnwrapAsWeakPersistentHandle(*state, object);
|
| - state->weak_persistent_handles().FreeHandle(weak_ref);
|
| - return;
|
| - }
|
| - PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object);
|
| - ASSERT(!state->IsProtectedHandle(ref));
|
| - if (!state->IsProtectedHandle(ref)) {
|
| - state->persistent_handles().FreeHandle(ref);
|
| - }
|
| + FinalizablePersistentHandle* weak_ref =
|
| + Api::UnwrapAsWeakPersistentHandle(*state, object);
|
| + state->weak_persistent_handles().FreeHandle(weak_ref);
|
| + return;
|
| }
|
|
|
|
|
| -DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object) {
|
| +DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_WeakPersistentHandle object) {
|
| Isolate* isolate = Isolate::Current();
|
| CHECK_ISOLATE(isolate);
|
| ApiState* state = isolate->api_state();
|
| @@ -616,7 +647,7 @@
|
| }
|
|
|
|
|
| -DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object) {
|
| +DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_WeakPersistentHandle object) {
|
| Isolate* isolate = Isolate::Current();
|
| CHECK_ISOLATE(isolate);
|
| ApiState* state = isolate->api_state();
|
|
|