| 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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 PersistentHandle* obj1_ref = Api::UnwrapAsPersistentHandle(obj1); | 610 PersistentHandle* obj1_ref = Api::UnwrapAsPersistentHandle(obj1); |
| 611 obj1_ref->set_raw(obj2_ref); | 611 obj1_ref->set_raw(obj2_ref); |
| 612 } | 612 } |
| 613 | 613 |
| 614 | 614 |
| 615 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 615 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| 616 Isolate* isolate, | 616 Isolate* isolate, |
| 617 FinalizablePersistentHandles* handles, | 617 FinalizablePersistentHandles* handles, |
| 618 Dart_Handle object, | 618 Dart_Handle object, |
| 619 void* peer, | 619 void* peer, |
| 620 intptr_t external_allocation_size, |
| 620 Dart_WeakPersistentHandleFinalizer callback) { | 621 Dart_WeakPersistentHandleFinalizer callback) { |
| 621 ReusableObjectHandleScope reused_obj_handle(isolate); | 622 ReusableObjectHandleScope reused_obj_handle(isolate); |
| 622 Object& ref = reused_obj_handle.Handle(); | 623 Object& ref = reused_obj_handle.Handle(); |
| 623 ref = Api::UnwrapHandle(object); | 624 ref = Api::UnwrapHandle(object); |
| 624 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); | 625 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); |
| 625 finalizable_ref->set_raw(ref); | 626 finalizable_ref->set_raw(ref); |
| 626 finalizable_ref->set_peer(peer); | 627 finalizable_ref->set_peer(peer); |
| 627 finalizable_ref->set_callback(callback); | 628 finalizable_ref->set_callback(callback); |
| 629 finalizable_ref->SetExternalAllocationSize(external_allocation_size, |
| 630 isolate->heap()); |
| 628 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); | 631 return reinterpret_cast<Dart_WeakPersistentHandle>(finalizable_ref); |
| 629 } | 632 } |
| 630 | 633 |
| 631 | 634 |
| 632 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 635 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( |
| 633 Dart_Handle object, | 636 Dart_Handle object, |
| 634 void* peer, | 637 void* peer, |
| 638 intptr_t external_allocation_size, |
| 635 Dart_WeakPersistentHandleFinalizer callback) { | 639 Dart_WeakPersistentHandleFinalizer callback) { |
| 636 Isolate* isolate = Isolate::Current(); | 640 Isolate* isolate = Isolate::Current(); |
| 637 CHECK_ISOLATE(isolate); | 641 CHECK_ISOLATE(isolate); |
| 638 ApiState* state = isolate->api_state(); | 642 ApiState* state = isolate->api_state(); |
| 639 ASSERT(state != NULL); | 643 ASSERT(state != NULL); |
| 640 return AllocateFinalizableHandle(isolate, | 644 return AllocateFinalizableHandle(isolate, |
| 641 &state->weak_persistent_handles(), | 645 &state->weak_persistent_handles(), |
| 642 object, | 646 object, |
| 643 peer, | 647 peer, |
| 648 external_allocation_size, |
| 644 callback); | 649 callback); |
| 645 } | 650 } |
| 646 | 651 |
| 647 | 652 |
| 648 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( | 653 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle( |
| 649 Dart_Handle object, | 654 Dart_Handle object, |
| 650 void* peer, | 655 void* peer, |
| 656 intptr_t external_allocation_size, |
| 651 Dart_WeakPersistentHandleFinalizer callback) { | 657 Dart_WeakPersistentHandleFinalizer callback) { |
| 652 Isolate* isolate = Isolate::Current(); | 658 Isolate* isolate = Isolate::Current(); |
| 653 CHECK_ISOLATE(isolate); | 659 CHECK_ISOLATE(isolate); |
| 654 ApiState* state = isolate->api_state(); | 660 ApiState* state = isolate->api_state(); |
| 655 ASSERT(state != NULL); | 661 ASSERT(state != NULL); |
| 656 return AllocateFinalizableHandle(isolate, | 662 return AllocateFinalizableHandle(isolate, |
| 657 &state->prologue_weak_persistent_handles(), | 663 &state->prologue_weak_persistent_handles(), |
| 658 object, | 664 object, |
| 659 peer, | 665 peer, |
| 666 external_allocation_size, |
| 660 callback); | 667 callback); |
| 661 } | 668 } |
| 662 | 669 |
| 663 | 670 |
| 664 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 671 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| 665 Isolate* isolate = Isolate::Current(); | 672 Isolate* isolate = Isolate::Current(); |
| 666 CHECK_ISOLATE(isolate); | 673 CHECK_ISOLATE(isolate); |
| 667 ApiState* state = isolate->api_state(); | 674 ApiState* state = isolate->api_state(); |
| 668 ASSERT(state != NULL); | 675 ASSERT(state != NULL); |
| 669 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); | 676 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(object); |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 CHECK_CALLBACK_STATE(isolate); | 1785 CHECK_CALLBACK_STATE(isolate); |
| 1779 return Api::NewHandle(isolate, String::FromUTF32(utf32_array, length)); | 1786 return Api::NewHandle(isolate, String::FromUTF32(utf32_array, length)); |
| 1780 } | 1787 } |
| 1781 | 1788 |
| 1782 | 1789 |
| 1783 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 1790 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( |
| 1784 const uint8_t* latin1_array, | 1791 const uint8_t* latin1_array, |
| 1785 intptr_t length, | 1792 intptr_t length, |
| 1786 void* peer, | 1793 void* peer, |
| 1787 Dart_PeerFinalizer cback) { | 1794 Dart_PeerFinalizer cback) { |
| 1795 // TODO(17284): Allocate large external data in old space. |
| 1788 Isolate* isolate = Isolate::Current(); | 1796 Isolate* isolate = Isolate::Current(); |
| 1789 DARTSCOPE(isolate); | 1797 DARTSCOPE(isolate); |
| 1790 if (latin1_array == NULL && length != 0) { | 1798 if (latin1_array == NULL && length != 0) { |
| 1791 RETURN_NULL_ERROR(latin1_array); | 1799 RETURN_NULL_ERROR(latin1_array); |
| 1792 } | 1800 } |
| 1793 CHECK_LENGTH(length, String::kMaxElements); | 1801 CHECK_LENGTH(length, String::kMaxElements); |
| 1794 CHECK_CALLBACK_STATE(isolate); | 1802 CHECK_CALLBACK_STATE(isolate); |
| 1795 return Api::NewHandle(isolate, | 1803 return Api::NewHandle(isolate, |
| 1796 String::NewExternal(latin1_array, length, peer, cback)); | 1804 String::NewExternal(latin1_array, length, peer, cback)); |
| 1797 } | 1805 } |
| 1798 | 1806 |
| 1799 | 1807 |
| 1800 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 1808 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
| 1801 intptr_t length, | 1809 intptr_t length, |
| 1802 void* peer, | 1810 void* peer, |
| 1803 Dart_PeerFinalizer cback) { | 1811 Dart_PeerFinalizer cback) { |
| 1812 // TODO(17284): Allocate large external data in old space. |
| 1804 Isolate* isolate = Isolate::Current(); | 1813 Isolate* isolate = Isolate::Current(); |
| 1805 DARTSCOPE(isolate); | 1814 DARTSCOPE(isolate); |
| 1806 if (utf16_array == NULL && length != 0) { | 1815 if (utf16_array == NULL && length != 0) { |
| 1807 RETURN_NULL_ERROR(utf16_array); | 1816 RETURN_NULL_ERROR(utf16_array); |
| 1808 } | 1817 } |
| 1809 CHECK_LENGTH(length, String::kMaxElements); | 1818 CHECK_LENGTH(length, String::kMaxElements); |
| 1810 CHECK_CALLBACK_STATE(isolate); | 1819 CHECK_CALLBACK_STATE(isolate); |
| 1811 return Api::NewHandle(isolate, | 1820 return Api::NewHandle(isolate, |
| 1812 String::NewExternal(utf16_array, length, peer, cback)); | 1821 String::NewExternal(utf16_array, length, peer, cback)); |
| 1813 } | 1822 } |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2735 } | 2744 } |
| 2736 UNREACHABLE(); | 2745 UNREACHABLE(); |
| 2737 return Api::Null(); | 2746 return Api::Null(); |
| 2738 } | 2747 } |
| 2739 | 2748 |
| 2740 | 2749 |
| 2741 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 2750 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( |
| 2742 Dart_TypedData_Type type, | 2751 Dart_TypedData_Type type, |
| 2743 void* data, | 2752 void* data, |
| 2744 intptr_t length) { | 2753 intptr_t length) { |
| 2754 // TODO(17284): Allocate large external data in old space. |
| 2745 Isolate* isolate = Isolate::Current(); | 2755 Isolate* isolate = Isolate::Current(); |
| 2746 DARTSCOPE(isolate); | 2756 DARTSCOPE(isolate); |
| 2747 if (data == NULL && length != 0) { | 2757 if (data == NULL && length != 0) { |
| 2748 RETURN_NULL_ERROR(data); | 2758 RETURN_NULL_ERROR(data); |
| 2749 } | 2759 } |
| 2750 CHECK_CALLBACK_STATE(isolate); | 2760 CHECK_CALLBACK_STATE(isolate); |
| 2751 switch (type) { | 2761 switch (type) { |
| 2752 case Dart_TypedData_kByteData: | 2762 case Dart_TypedData_kByteData: |
| 2753 return NewExternalByteData(isolate, data, length); | 2763 return NewExternalByteData(isolate, data, length); |
| 2754 case Dart_TypedData_kInt8: | 2764 case Dart_TypedData_kInt8: |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4607 | 4617 |
| 4608 | 4618 |
| 4609 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4619 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4610 const char* name, | 4620 const char* name, |
| 4611 Dart_ServiceRequestCallback callback, | 4621 Dart_ServiceRequestCallback callback, |
| 4612 void* user_data) { | 4622 void* user_data) { |
| 4613 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4623 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4614 } | 4624 } |
| 4615 | 4625 |
| 4616 } // namespace dart | 4626 } // namespace dart |
| OLD | NEW |