| 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); | 616 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); |
| 617 obj1_ref->set_raw(obj2_ref); | 617 obj1_ref->set_raw(obj2_ref); |
| 618 } | 618 } |
| 619 | 619 |
| 620 | 620 |
| 621 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 621 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| 622 Isolate* isolate, | 622 Isolate* isolate, |
| 623 Dart_Handle object, | 623 Dart_Handle object, |
| 624 bool is_prologue, | 624 bool is_prologue, |
| 625 void* peer, | 625 void* peer, |
| 626 intptr_t external_allocation_size, |
| 626 Dart_WeakPersistentHandleFinalizer callback) { | 627 Dart_WeakPersistentHandleFinalizer callback) { |
| 627 ApiState* state = isolate->api_state(); | 628 ApiState* state = isolate->api_state(); |
| 628 ASSERT(state != NULL); | 629 ASSERT(state != NULL); |
| 629 ReusableObjectHandleScope reused_obj_handle(isolate); | 630 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 630 Object& ref = reused_obj_handle.Handle(); | 631 Object& ref = reused_obj_handle.Handle(); |
| 631 ref = Api::UnwrapHandle(object); | 632 ref = Api::UnwrapHandle(object); |
| 632 FinalizablePersistentHandle* finalizable_ref = is_prologue ? | 633 FinalizablePersistentHandle* finalizable_ref = is_prologue ? |
| 633 state->prologue_weak_persistent_handles().AllocateHandle() : | 634 state->prologue_weak_persistent_handles().AllocateHandle() : |
| 634 state->weak_persistent_handles().AllocateHandle(); | 635 state->weak_persistent_handles().AllocateHandle(); |
| 635 | 636 |
| 636 finalizable_ref->set_raw(ref); | 637 finalizable_ref->set_raw(ref); |
| 637 finalizable_ref->set_peer(peer); | 638 finalizable_ref->set_peer(peer); |
| 638 finalizable_ref->set_callback(callback); | 639 finalizable_ref->set_callback(callback); |
| 640 finalizable_ref->SetExternalSize(external_allocation_size, isolate); |
| 639 if (is_prologue) { | 641 if (is_prologue) { |
| 640 return finalizable_ref->apiPrologueHandle(); | 642 return finalizable_ref->apiPrologueHandle(); |
| 641 } else { | 643 } else { |
| 642 return finalizable_ref->apiHandle(); | 644 return finalizable_ref->apiHandle(); |
| 643 } | 645 } |
| 644 } | 646 } |
| 645 | 647 |
| 646 | 648 |
| 647 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 649 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 648 Dart_Handle object, | 650 Dart_Handle object, |
| 649 void* peer, | 651 void* peer, |
| 652 intptr_t external_allocation_size, |
| 650 Dart_WeakPersistentHandleFinalizer callback) { | 653 Dart_WeakPersistentHandleFinalizer callback) { |
| 651 Isolate* isolate = Isolate::Current(); | 654 Isolate* isolate = Isolate::Current(); |
| 652 CHECK_ISOLATE(isolate); | 655 CHECK_ISOLATE(isolate); |
| 653 return AllocateFinalizableHandle(isolate, | 656 return AllocateFinalizableHandle(isolate, |
| 654 object, | 657 object, |
| 655 false, | 658 false, |
| 656 peer, | 659 peer, |
| 660 external_allocation_size, |
| 657 callback); | 661 callback); |
| 658 } | 662 } |
| 659 | 663 |
| 660 | 664 |
| 661 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( | 665 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
| 662 Dart_Handle object, | 666 Dart_Handle object, |
| 663 void* peer, | 667 void* peer, |
| 668 intptr_t external_allocation_size, |
| 664 Dart_WeakPersistentHandleFinalizer callback) { | 669 Dart_WeakPersistentHandleFinalizer callback) { |
| 665 Isolate* isolate = Isolate::Current(); | 670 Isolate* isolate = Isolate::Current(); |
| 666 CHECK_ISOLATE(isolate); | 671 CHECK_ISOLATE(isolate); |
| 667 return AllocateFinalizableHandle(isolate, | 672 return AllocateFinalizableHandle(isolate, |
| 668 object, | 673 object, |
| 669 true, | 674 true, |
| 670 peer, | 675 peer, |
| 676 external_allocation_size, |
| 671 callback); | 677 callback); |
| 672 } | 678 } |
| 673 | 679 |
| 674 | 680 |
| 675 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 681 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| 676 Isolate* isolate = Isolate::Current(); | 682 Isolate* isolate = Isolate::Current(); |
| 677 CHECK_ISOLATE(isolate); | 683 CHECK_ISOLATE(isolate); |
| 678 ApiState* state = isolate->api_state(); | 684 ApiState* state = isolate->api_state(); |
| 679 ASSERT(state != NULL); | 685 ASSERT(state != NULL); |
| 680 PersistentHandle* ref = PersistentHandle::Cast(object); | 686 PersistentHandle* ref = PersistentHandle::Cast(object); |
| 681 ASSERT(!state->IsProtectedHandle(ref)); | 687 ASSERT(!state->IsProtectedHandle(ref)); |
| 682 if (!state->IsProtectedHandle(ref)) { | 688 if (!state->IsProtectedHandle(ref)) { |
| 683 state->persistent_handles().FreeHandle(ref); | 689 state->persistent_handles().FreeHandle(ref); |
| 684 } | 690 } |
| 685 } | 691 } |
| 686 | 692 |
| 687 | 693 |
| 688 DART_EXPORT void Dart_DeleteWeakPersistentHandle( | 694 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
| 689 Dart_Isolate current_isolate, | 695 Dart_Isolate current_isolate, |
| 690 Dart_WeakPersistentHandle object) { | 696 Dart_WeakPersistentHandle object) { |
| 691 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); | 697 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); |
| 692 CHECK_ISOLATE(isolate); | 698 CHECK_ISOLATE(isolate); |
| 693 ASSERT(isolate == Isolate::Current()); | 699 ASSERT(isolate == Isolate::Current()); |
| 694 ApiState* state = isolate->api_state(); | 700 ApiState* state = isolate->api_state(); |
| 695 ASSERT(state != NULL); | 701 ASSERT(state != NULL); |
| 696 if (FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)) { | 702 if (FinalizablePersistentHandle::IsPrologueWeakPersistentHandle(object)) { |
| 697 ASSERT(state->IsValidPrologueWeakPersistentHandle(object)); | 703 ASSERT(state->IsValidPrologueWeakPersistentHandle(object)); |
| 698 FinalizablePersistentHandle* weak_ref = | 704 FinalizablePersistentHandle* weak_ref = |
| 699 FinalizablePersistentHandle::Cast(object); | 705 FinalizablePersistentHandle::Cast(object); |
| 706 weak_ref->EnsureFreeExternal(isolate); |
| 700 state->prologue_weak_persistent_handles().FreeHandle(weak_ref); | 707 state->prologue_weak_persistent_handles().FreeHandle(weak_ref); |
| 701 } else { | 708 } else { |
| 702 ASSERT(!state->IsValidPrologueWeakPersistentHandle(object)); | 709 ASSERT(!state->IsValidPrologueWeakPersistentHandle(object)); |
| 703 FinalizablePersistentHandle* weak_ref = | 710 FinalizablePersistentHandle* weak_ref = |
| 704 FinalizablePersistentHandle::Cast(object); | 711 FinalizablePersistentHandle::Cast(object); |
| 712 weak_ref->EnsureFreeExternal(isolate); |
| 705 state->weak_persistent_handles().FreeHandle(weak_ref); | 713 state->weak_persistent_handles().FreeHandle(weak_ref); |
| 706 } | 714 } |
| 707 } | 715 } |
| 708 | 716 |
| 709 | 717 |
| 710 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( | 718 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle( |
| 711 Dart_WeakPersistentHandle object) { | 719 Dart_WeakPersistentHandle object) { |
| 712 #if defined(DEBUG) | 720 #if defined(DEBUG) |
| 713 Isolate* isolate = Isolate::Current(); | 721 Isolate* isolate = Isolate::Current(); |
| 714 CHECK_ISOLATE(isolate); | 722 CHECK_ISOLATE(isolate); |
| (...skipping 3923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4638 | 4646 |
| 4639 | 4647 |
| 4640 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4648 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4641 const char* name, | 4649 const char* name, |
| 4642 Dart_ServiceRequestCallback callback, | 4650 Dart_ServiceRequestCallback callback, |
| 4643 void* user_data) { | 4651 void* user_data) { |
| 4644 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4652 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4645 } | 4653 } |
| 4646 | 4654 |
| 4647 } // namespace dart | 4655 } // namespace dart |
| OLD | NEW |