| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 358 } |
| 359 | 359 |
| 360 | 360 |
| 361 FinalizablePersistentHandle* FinalizablePersistentHandle::Cast( | 361 FinalizablePersistentHandle* FinalizablePersistentHandle::Cast( |
| 362 Dart_WeakPersistentHandle handle) { | 362 Dart_WeakPersistentHandle handle) { |
| 363 #if defined(DEBUG) | 363 #if defined(DEBUG) |
| 364 ApiState* state = Isolate::Current()->api_state(); | 364 ApiState* state = Isolate::Current()->api_state(); |
| 365 ASSERT(state->IsValidWeakPersistentHandle(handle) || | 365 ASSERT(state->IsValidWeakPersistentHandle(handle) || |
| 366 state->IsValidPrologueWeakPersistentHandle(handle)); | 366 state->IsValidPrologueWeakPersistentHandle(handle)); |
| 367 #endif | 367 #endif |
| 368 uword addr = reinterpret_cast<uword>(handle); | 368 return reinterpret_cast<FinalizablePersistentHandle*>(handle); |
| 369 return reinterpret_cast<FinalizablePersistentHandle*>( | |
| 370 addr & ~kWeakPersistentTagMask); | |
| 371 } | 369 } |
| 372 | 370 |
| 373 | 371 |
| 374 void FinalizablePersistentHandle::Finalize(Isolate* isolate, | 372 void FinalizablePersistentHandle::Finalize( |
| 375 FinalizablePersistentHandle* handle, | 373 Isolate* isolate, FinalizablePersistentHandle* handle) { |
| 376 bool is_prologue_weak) { | |
| 377 if (!handle->raw()->IsHeapObject()) { | 374 if (!handle->raw()->IsHeapObject()) { |
| 378 return; | 375 return; |
| 379 } | 376 } |
| 380 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); | 377 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); |
| 381 ASSERT(callback != NULL); | 378 ASSERT(callback != NULL); |
| 382 void* peer = handle->peer(); | 379 void* peer = handle->peer(); |
| 383 Dart_WeakPersistentHandle object = is_prologue_weak ? | 380 Dart_WeakPersistentHandle object = handle->apiHandle(); |
| 384 handle->apiPrologueHandle() : | |
| 385 handle->apiHandle(); | |
| 386 (*callback)(isolate->init_callback_data(), object, peer); | 381 (*callback)(isolate->init_callback_data(), object, peer); |
| 387 ApiState* state = isolate->api_state(); | 382 ApiState* state = isolate->api_state(); |
| 388 ASSERT(state != NULL); | 383 ASSERT(state != NULL); |
| 389 if (is_prologue_weak) { | 384 if (handle->IsPrologueWeakPersistent()) { |
| 390 state->prologue_weak_persistent_handles().FreeHandle(handle); | 385 state->prologue_weak_persistent_handles().FreeHandle(handle); |
| 391 } else { | 386 } else { |
| 392 state->weak_persistent_handles().FreeHandle(handle); | 387 state->weak_persistent_handles().FreeHandle(handle); |
| 393 } | 388 } |
| 394 } | 389 } |
| 395 | 390 |
| 396 | 391 |
| 397 // --- Handles --- | 392 // --- Handles --- |
| 398 | 393 |
| 399 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 394 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 Object& ref = isolate->ObjectHandle(); | 650 Object& ref = isolate->ObjectHandle(); |
| 656 ref = Api::UnwrapHandle(object); | 651 ref = Api::UnwrapHandle(object); |
| 657 FinalizablePersistentHandle* finalizable_ref = is_prologue ? | 652 FinalizablePersistentHandle* finalizable_ref = is_prologue ? |
| 658 state->prologue_weak_persistent_handles().AllocateHandle() : | 653 state->prologue_weak_persistent_handles().AllocateHandle() : |
| 659 state->weak_persistent_handles().AllocateHandle(); | 654 state->weak_persistent_handles().AllocateHandle(); |
| 660 | 655 |
| 661 finalizable_ref->set_raw(ref); | 656 finalizable_ref->set_raw(ref); |
| 662 finalizable_ref->set_peer(peer); | 657 finalizable_ref->set_peer(peer); |
| 663 finalizable_ref->set_callback(callback); | 658 finalizable_ref->set_callback(callback); |
| 664 finalizable_ref->SetExternalSize(external_allocation_size, isolate); | 659 finalizable_ref->SetExternalSize(external_allocation_size, isolate); |
| 665 if (is_prologue) { | 660 finalizable_ref->SetPrologueWeakPersistent(is_prologue); |
| 666 return finalizable_ref->apiPrologueHandle(); | 661 return finalizable_ref->apiHandle(); |
| 667 } else { | |
| 668 return finalizable_ref->apiHandle(); | |
| 669 } | |
| 670 } | 662 } |
| 671 | 663 |
| 672 | 664 |
| 673 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 665 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 674 Dart_Handle object, | 666 Dart_Handle object, |
| 675 void* peer, | 667 void* peer, |
| 676 intptr_t external_allocation_size, | 668 intptr_t external_allocation_size, |
| 677 Dart_WeakPersistentHandleFinalizer callback) { | 669 Dart_WeakPersistentHandleFinalizer callback) { |
| 678 Isolate* isolate = Isolate::Current(); | 670 Isolate* isolate = Isolate::Current(); |
| 679 CHECK_ISOLATE(isolate); | 671 CHECK_ISOLATE(isolate); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 714 |
| 723 | 715 |
| 724 DART_EXPORT void Dart_DeleteWeakPersistentHandle( | 716 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
| 725 Dart_Isolate current_isolate, | 717 Dart_Isolate current_isolate, |
| 726 Dart_WeakPersistentHandle object) { | 718 Dart_WeakPersistentHandle object) { |
| 727 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); | 719 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); |
| 728 CHECK_ISOLATE(isolate); | 720 CHECK_ISOLATE(isolate); |
| 729 ASSERT(isolate == Isolate::Current()); | 721 ASSERT(isolate == Isolate::Current()); |
| 730 ApiState* state = isolate->api_state(); | 722 ApiState* state = isolate->api_state(); |
| 731 ASSERT(state != NULL); | 723 ASSERT(state != NULL); |
| 732 if (FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)) { | 724 FinalizablePersistentHandle* weak_ref = |
| 725 FinalizablePersistentHandle::Cast(object); |
| 726 weak_ref->EnsureFreeExternal(isolate); |
| 727 if (weak_ref->IsPrologueWeakPersistent()) { |
| 733 ASSERT(state->IsValidPrologueWeakPersistentHandle(object)); | 728 ASSERT(state->IsValidPrologueWeakPersistentHandle(object)); |
| 734 FinalizablePersistentHandle* weak_ref = | |
| 735 FinalizablePersistentHandle::Cast(object); | |
| 736 weak_ref->EnsureFreeExternal(isolate); | |
| 737 state->prologue_weak_persistent_handles().FreeHandle(weak_ref); | 729 state->prologue_weak_persistent_handles().FreeHandle(weak_ref); |
| 738 } else { | 730 } else { |
| 739 ASSERT(!state->IsValidPrologueWeakPersistentHandle(object)); | 731 ASSERT(!state->IsValidPrologueWeakPersistentHandle(object)); |
| 740 FinalizablePersistentHandle* weak_ref = | |
| 741 FinalizablePersistentHandle::Cast(object); | |
| 742 weak_ref->EnsureFreeExternal(isolate); | |
| 743 state->weak_persistent_handles().FreeHandle(weak_ref); | 732 state->weak_persistent_handles().FreeHandle(weak_ref); |
| 744 } | 733 } |
| 745 } | 734 } |
| 746 | 735 |
| 747 | 736 |
| 748 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( | 737 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( |
| 749 Dart_WeakPersistentHandle object) { | 738 Dart_WeakPersistentHandle object) { |
| 750 #if defined(DEBUG) | 739 FinalizablePersistentHandle* weak_ref = |
| 751 Isolate* isolate = Isolate::Current(); | 740 FinalizablePersistentHandle::Cast(object); |
| 752 CHECK_ISOLATE(isolate); | 741 return weak_ref->IsPrologueWeakPersistent(); |
| 753 ApiState* state = isolate->api_state(); | |
| 754 ASSERT(state != NULL); | |
| 755 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) == | |
| 756 FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)); | |
| 757 #endif | |
| 758 return FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object); | |
| 759 } | 742 } |
| 760 | 743 |
| 761 | 744 |
| 762 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( | 745 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet( |
| 763 Dart_WeakPersistentHandle* keys, | 746 Dart_WeakPersistentHandle* keys, |
| 764 intptr_t num_keys, | 747 intptr_t num_keys, |
| 765 Dart_WeakPersistentHandle* values, | 748 Dart_WeakPersistentHandle* values, |
| 766 intptr_t num_values) { | 749 intptr_t num_values) { |
| 767 Isolate* isolate = Isolate::Current(); | 750 Isolate* isolate = Isolate::Current(); |
| 768 CHECK_ISOLATE(isolate); | 751 CHECK_ISOLATE(isolate); |
| (...skipping 3888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4657 | 4640 |
| 4658 | 4641 |
| 4659 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4642 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4660 const char* name, | 4643 const char* name, |
| 4661 Dart_ServiceRequestCallback callback, | 4644 Dart_ServiceRequestCallback callback, |
| 4662 void* user_data) { | 4645 void* user_data) { |
| 4663 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4646 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4664 } | 4647 } |
| 4665 | 4648 |
| 4666 } // namespace dart | 4649 } // namespace dart |
| OLD | NEW |