| 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 2668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 \ | 2679 \ |
| 2680 } \ | 2680 } \ |
| 2681 const Integer& integer = Integer::Cast(element); \ | 2681 const Integer& integer = Integer::Cast(element); \ |
| 2682 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 2682 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
| 2683 ASSERT(integer.AsInt64Value() <= 0xff); \ | 2683 ASSERT(integer.AsInt64Value() <= 0xff); \ |
| 2684 } \ | 2684 } \ |
| 2685 return Api::Success(); \ | 2685 return Api::Success(); \ |
| 2686 } \ | 2686 } \ |
| 2687 return Api::NewError("Invalid length passed in to access array elements"); \ | 2687 return Api::NewError("Invalid length passed in to access array elements"); \ |
| 2688 | 2688 |
| 2689 | 2689 template<typename T> |
| 2690 static Dart_Handle CopyBytes(const TypedData& array, | 2690 static Dart_Handle CopyBytes(const T& array, |
| 2691 intptr_t offset, | 2691 intptr_t offset, |
| 2692 uint8_t* native_array, | 2692 uint8_t* native_array, |
| 2693 intptr_t length) { | 2693 intptr_t length) { |
| 2694 ASSERT(array.IsTypedData()); | |
| 2695 ASSERT(array.ElementSizeInBytes() == 1); | 2694 ASSERT(array.ElementSizeInBytes() == 1); |
| 2696 NoGCScope no_gc; | 2695 NoGCScope no_gc; |
| 2697 memmove(native_array, | 2696 memmove(native_array, |
| 2698 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 2697 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
| 2699 length); | 2698 length); |
| 2700 return Api::Success(); | 2699 return Api::Success(); |
| 2701 } | 2700 } |
| 2702 | 2701 |
| 2703 | 2702 |
| 2704 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2703 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
| 2705 intptr_t offset, | 2704 intptr_t offset, |
| 2706 uint8_t* native_array, | 2705 uint8_t* native_array, |
| 2707 intptr_t length) { | 2706 intptr_t length) { |
| 2708 Isolate* isolate = Isolate::Current(); | 2707 Isolate* isolate = Isolate::Current(); |
| 2709 DARTSCOPE(isolate); | 2708 DARTSCOPE(isolate); |
| 2710 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2709 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 2711 if (obj.IsTypedData()) { | 2710 if (obj.IsTypedData()) { |
| 2712 const TypedData& array = TypedData::Cast(obj); | 2711 const TypedData& array = TypedData::Cast(obj); |
| 2713 if (array.ElementSizeInBytes() == 1) { | 2712 if (array.ElementSizeInBytes() == 1) { |
| 2714 if (!Utils::RangeCheck(offset, length, array.Length())) { | 2713 if (!Utils::RangeCheck(offset, length, array.Length())) { |
| 2715 return Api::NewError( | 2714 return Api::NewError( |
| 2716 "Invalid length passed in to access list elements"); | 2715 "Invalid length passed in to access list elements"); |
| 2717 } | 2716 } |
| 2718 return CopyBytes(array, offset, native_array, length); | 2717 return CopyBytes(array, offset, native_array, length); |
| 2719 } | 2718 } |
| 2720 } | 2719 } |
| 2720 if (obj.IsExternalTypedData()) { |
| 2721 const ExternalTypedData& external_array = ExternalTypedData::Cast(obj); |
| 2722 if (external_array.ElementSizeInBytes() == 1) { |
| 2723 if (!Utils::RangeCheck(offset, length, external_array.Length())) { |
| 2724 return Api::NewError( |
| 2725 "Invalid length passed in to access list elements"); |
| 2726 } |
| 2727 return CopyBytes(external_array, offset, native_array, length); |
| 2728 } |
| 2729 } |
| 2721 if (RawObject::IsTypedDataViewClassId(obj.GetClassId())) { | 2730 if (RawObject::IsTypedDataViewClassId(obj.GetClassId())) { |
| 2722 const Instance& view = Instance::Cast(obj); | 2731 const Instance& view = Instance::Cast(obj); |
| 2723 if (TypedDataView::ElementSizeInBytes(view) == 1) { | 2732 if (TypedDataView::ElementSizeInBytes(view) == 1) { |
| 2724 intptr_t view_length = Smi::Value(TypedDataView::Length(view)); | 2733 intptr_t view_length = Smi::Value(TypedDataView::Length(view)); |
| 2725 if (!Utils::RangeCheck(offset, length, view_length)) { | 2734 if (!Utils::RangeCheck(offset, length, view_length)) { |
| 2726 return Api::NewError( | 2735 return Api::NewError( |
| 2727 "Invalid length passed in to access list elements"); | 2736 "Invalid length passed in to access list elements"); |
| 2728 } | 2737 } |
| 2729 const Instance& data = Instance::Handle(TypedDataView::Data(view)); | 2738 const Instance& data = Instance::Handle(TypedDataView::Data(view)); |
| 2730 if (data.IsTypedData()) { | 2739 if (data.IsTypedData()) { |
| (...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5072 | 5081 |
| 5073 | 5082 |
| 5074 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5083 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 5075 const char* name, | 5084 const char* name, |
| 5076 Dart_ServiceRequestCallback callback, | 5085 Dart_ServiceRequestCallback callback, |
| 5077 void* user_data) { | 5086 void* user_data) { |
| 5078 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5087 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 5079 } | 5088 } |
| 5080 | 5089 |
| 5081 } // namespace dart | 5090 } // namespace dart |
| OLD | NEW |