OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 | 2003 |
2004 | 2004 |
2005 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2005 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
2006 intptr_t offset, | 2006 intptr_t offset, |
2007 uint8_t* native_array, | 2007 uint8_t* native_array, |
2008 intptr_t length) { | 2008 intptr_t length) { |
2009 Isolate* isolate = Isolate::Current(); | 2009 Isolate* isolate = Isolate::Current(); |
2010 DARTSCOPE(isolate); | 2010 DARTSCOPE(isolate); |
2011 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2011 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
2012 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || | 2012 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || |
| 2013 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray() || |
2013 obj.IsInt8Array() || obj.IsExternalInt8Array()) { | 2014 obj.IsInt8Array() || obj.IsExternalInt8Array()) { |
2014 const ByteArray& byte_array = ByteArray::Cast(obj); | 2015 const ByteArray& byte_array = ByteArray::Cast(obj); |
2015 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2016 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
2016 ByteArray::Copy(native_array, byte_array, offset, length); | 2017 ByteArray::Copy(native_array, byte_array, offset, length); |
2017 return Api::Success(isolate); | 2018 return Api::Success(isolate); |
2018 } | 2019 } |
2019 return Api::NewError("Invalid length passed in to access list elements"); | 2020 return Api::NewError("Invalid length passed in to access list elements"); |
2020 } else if (obj.IsArray()) { | 2021 } else if (obj.IsArray()) { |
2021 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2022 GET_LIST_ELEMENT_AS_BYTES(isolate, |
2022 Array, | 2023 Array, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 return Api::NewError("Invalid length passed in to set array elements"); \ | 2089 return Api::NewError("Invalid length passed in to set array elements"); \ |
2089 | 2090 |
2090 | 2091 |
2091 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 2092 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
2092 intptr_t offset, | 2093 intptr_t offset, |
2093 uint8_t* native_array, | 2094 uint8_t* native_array, |
2094 intptr_t length) { | 2095 intptr_t length) { |
2095 Isolate* isolate = Isolate::Current(); | 2096 Isolate* isolate = Isolate::Current(); |
2096 DARTSCOPE(isolate); | 2097 DARTSCOPE(isolate); |
2097 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2098 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
2098 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { | 2099 if (obj.IsUint8Array() || obj.IsExternalUint8Array() || |
| 2100 obj.IsUint8ClampedArray() || obj.IsExternalUint8ClampedArray()) { |
2099 const ByteArray& byte_array = ByteArray::Cast(obj); | 2101 const ByteArray& byte_array = ByteArray::Cast(obj); |
2100 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2102 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
2101 ByteArray::Copy(byte_array, offset, native_array, length); | 2103 ByteArray::Copy(byte_array, offset, native_array, length); |
2102 return Api::Success(isolate); | 2104 return Api::Success(isolate); |
2103 } | 2105 } |
2104 return Api::NewError("Invalid length passed in to set list elements"); | 2106 return Api::NewError("Invalid length passed in to set list elements"); |
2105 } else if (obj.IsArray()) { | 2107 } else if (obj.IsArray()) { |
2106 if (obj.IsImmutableArray()) { | 2108 if (obj.IsImmutableArray()) { |
2107 return Api::NewError("Cannot modify immutable array"); | 2109 return Api::NewError("Cannot modify immutable array"); |
2108 } | 2110 } |
(...skipping 2344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4453 } | 4455 } |
4454 { | 4456 { |
4455 NoGCScope no_gc; | 4457 NoGCScope no_gc; |
4456 RawObject* raw_obj = obj.raw(); | 4458 RawObject* raw_obj = obj.raw(); |
4457 isolate->heap()->SetPeer(raw_obj, peer); | 4459 isolate->heap()->SetPeer(raw_obj, peer); |
4458 } | 4460 } |
4459 return Api::Success(isolate); | 4461 return Api::Success(isolate); |
4460 } | 4462 } |
4461 | 4463 |
4462 } // namespace dart | 4464 } // namespace dart |
OLD | NEW |