| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 TypeArguments::Handle(isolate), | 73 TypeArguments::Handle(isolate), |
| 74 &malformed_type_error)) { | 74 &malformed_type_error)) { |
| 75 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 75 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
| 76 return instance.raw(); | 76 return instance.raw(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 return Instance::null(); | 79 return Instance::null(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 Heap::Space SpaceForExternal(Isolate* isolate, intptr_t size) { |
| 84 Heap* heap = isolate->heap(); |
| 85 // If 'size' would be a significant fraction of new space, then use old. |
| 86 static const int kExtNewRatio = 16; |
| 87 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { |
| 88 return Heap::kOld; |
| 89 } else { |
| 90 return Heap::kNew; |
| 91 } |
| 92 } |
| 93 |
| 94 |
| 83 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { | 95 Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) { |
| 84 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); | 96 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
| 85 ASSERT(local_handles != NULL); | 97 ASSERT(local_handles != NULL); |
| 86 LocalHandle* ref = local_handles->AllocateHandle(); | 98 LocalHandle* ref = local_handles->AllocateHandle(); |
| 87 ref->set_raw(raw); | 99 ref->set_raw(raw); |
| 88 return reinterpret_cast<Dart_Handle>(ref); | 100 return reinterpret_cast<Dart_Handle>(ref); |
| 89 } | 101 } |
| 90 | 102 |
| 91 | 103 |
| 92 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 104 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
| (...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 void* peer, | 1804 void* peer, |
| 1793 Dart_PeerFinalizer cback) { | 1805 Dart_PeerFinalizer cback) { |
| 1794 Isolate* isolate = Isolate::Current(); | 1806 Isolate* isolate = Isolate::Current(); |
| 1795 DARTSCOPE(isolate); | 1807 DARTSCOPE(isolate); |
| 1796 if (latin1_array == NULL && length != 0) { | 1808 if (latin1_array == NULL && length != 0) { |
| 1797 RETURN_NULL_ERROR(latin1_array); | 1809 RETURN_NULL_ERROR(latin1_array); |
| 1798 } | 1810 } |
| 1799 CHECK_LENGTH(length, String::kMaxElements); | 1811 CHECK_LENGTH(length, String::kMaxElements); |
| 1800 CHECK_CALLBACK_STATE(isolate); | 1812 CHECK_CALLBACK_STATE(isolate); |
| 1801 return Api::NewHandle(isolate, | 1813 return Api::NewHandle(isolate, |
| 1802 String::NewExternal(latin1_array, length, peer, cback)); | 1814 String::NewExternal(latin1_array, |
| 1815 length, |
| 1816 peer, |
| 1817 cback, |
| 1818 SpaceForExternal(isolate, length))); |
| 1803 } | 1819 } |
| 1804 | 1820 |
| 1805 | 1821 |
| 1806 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 1822 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
| 1807 intptr_t length, | 1823 intptr_t length, |
| 1808 void* peer, | 1824 void* peer, |
| 1809 Dart_PeerFinalizer cback) { | 1825 Dart_PeerFinalizer cback) { |
| 1810 Isolate* isolate = Isolate::Current(); | 1826 Isolate* isolate = Isolate::Current(); |
| 1811 DARTSCOPE(isolate); | 1827 DARTSCOPE(isolate); |
| 1812 if (utf16_array == NULL && length != 0) { | 1828 if (utf16_array == NULL && length != 0) { |
| 1813 RETURN_NULL_ERROR(utf16_array); | 1829 RETURN_NULL_ERROR(utf16_array); |
| 1814 } | 1830 } |
| 1815 CHECK_LENGTH(length, String::kMaxElements); | 1831 CHECK_LENGTH(length, String::kMaxElements); |
| 1816 CHECK_CALLBACK_STATE(isolate); | 1832 CHECK_CALLBACK_STATE(isolate); |
| 1833 intptr_t bytes = length * sizeof(*utf16_array); |
| 1817 return Api::NewHandle(isolate, | 1834 return Api::NewHandle(isolate, |
| 1818 String::NewExternal(utf16_array, length, peer, cback)); | 1835 String::NewExternal(utf16_array, |
| 1836 length, |
| 1837 peer, |
| 1838 cback, |
| 1839 SpaceForExternal(isolate, bytes))); |
| 1819 } | 1840 } |
| 1820 | 1841 |
| 1821 | 1842 |
| 1822 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 1843 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| 1823 const char** cstr) { | 1844 const char** cstr) { |
| 1824 Isolate* isolate = Isolate::Current(); | 1845 Isolate* isolate = Isolate::Current(); |
| 1825 DARTSCOPE(isolate); | 1846 DARTSCOPE(isolate); |
| 1826 if (cstr == NULL) { | 1847 if (cstr == NULL) { |
| 1827 RETURN_NULL_ERROR(cstr); | 1848 RETURN_NULL_ERROR(cstr); |
| 1828 } | 1849 } |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2654 intptr_t cid, | 2675 intptr_t cid, |
| 2655 intptr_t length) { | 2676 intptr_t length) { |
| 2656 CHECK_LENGTH(length, TypedData::MaxElements(cid)); | 2677 CHECK_LENGTH(length, TypedData::MaxElements(cid)); |
| 2657 return Api::NewHandle(isolate, TypedData::New(cid, length)); | 2678 return Api::NewHandle(isolate, TypedData::New(cid, length)); |
| 2658 } | 2679 } |
| 2659 | 2680 |
| 2660 | 2681 |
| 2661 static Dart_Handle NewExternalTypedData( | 2682 static Dart_Handle NewExternalTypedData( |
| 2662 Isolate* isolate, intptr_t cid, void* data, intptr_t length) { | 2683 Isolate* isolate, intptr_t cid, void* data, intptr_t length) { |
| 2663 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); | 2684 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); |
| 2685 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); |
| 2664 const ExternalTypedData& result = ExternalTypedData::Handle( | 2686 const ExternalTypedData& result = ExternalTypedData::Handle( |
| 2665 isolate, | 2687 isolate, |
| 2666 ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), length)); | 2688 ExternalTypedData::New(cid, |
| 2689 reinterpret_cast<uint8_t*>(data), |
| 2690 length, |
| 2691 SpaceForExternal(isolate, bytes))); |
| 2667 return Api::NewHandle(isolate, result.raw()); | 2692 return Api::NewHandle(isolate, result.raw()); |
| 2668 } | 2693 } |
| 2669 | 2694 |
| 2670 | 2695 |
| 2671 static Dart_Handle NewExternalByteData( | 2696 static Dart_Handle NewExternalByteData( |
| 2672 Isolate* isolate, void* data, intptr_t length) { | 2697 Isolate* isolate, void* data, intptr_t length) { |
| 2673 Dart_Handle ext_data = NewExternalTypedData( | 2698 Dart_Handle ext_data = NewExternalTypedData( |
| 2674 isolate, kExternalTypedDataUint8ArrayCid, data, length); | 2699 isolate, kExternalTypedDataUint8ArrayCid, data, length); |
| 2675 if (::Dart_IsError(ext_data)) { | 2700 if (::Dart_IsError(ext_data)) { |
| 2676 return ext_data; | 2701 return ext_data; |
| (...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4613 | 4638 |
| 4614 | 4639 |
| 4615 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4640 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4616 const char* name, | 4641 const char* name, |
| 4617 Dart_ServiceRequestCallback callback, | 4642 Dart_ServiceRequestCallback callback, |
| 4618 void* user_data) { | 4643 void* user_data) { |
| 4619 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4644 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4620 } | 4645 } |
| 4621 | 4646 |
| 4622 } // namespace dart | 4647 } // namespace dart |
| OLD | NEW |