OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 DARTSCOPE(Isolate::Current()); | 1384 DARTSCOPE(Isolate::Current()); |
1385 const Array& obj = Array::Handle(Array::New(length)); | 1385 const Array& obj = Array::Handle(Array::New(length)); |
1386 return Api::NewLocalHandle(obj); | 1386 return Api::NewLocalHandle(obj); |
1387 } | 1387 } |
1388 | 1388 |
1389 | 1389 |
1390 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1390 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
1391 Isolate* isolate = Isolate::Current(); | 1391 Isolate* isolate = Isolate::Current(); |
1392 DARTSCOPE(isolate); | 1392 DARTSCOPE(isolate); |
1393 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1393 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1394 if (obj.IsByteArray()) { |
| 1395 ByteArray& byte_array = ByteArray::Handle(); |
| 1396 byte_array ^= obj.raw(); |
| 1397 *len = byte_array.Length(); |
| 1398 return Api::Success(); |
| 1399 } |
1394 if (obj.IsArray()) { | 1400 if (obj.IsArray()) { |
1395 Array& array_obj = Array::Handle(); | 1401 Array& array_obj = Array::Handle(); |
1396 array_obj ^= obj.raw(); | 1402 array_obj ^= obj.raw(); |
1397 *len = array_obj.Length(); | 1403 *len = array_obj.Length(); |
1398 return Api::Success(); | 1404 return Api::Success(); |
1399 } | 1405 } |
1400 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1406 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1401 // Now check and handle a dart object that implements the List interface. | 1407 // Now check and handle a dart object that implements the List interface. |
1402 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1408 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
1403 if (!instance.IsNull()) { | 1409 if (!instance.IsNull()) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 } | 1595 } |
1590 | 1596 |
1591 | 1597 |
1592 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1598 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
1593 intptr_t offset, | 1599 intptr_t offset, |
1594 uint8_t* native_array, | 1600 uint8_t* native_array, |
1595 intptr_t length) { | 1601 intptr_t length) { |
1596 Isolate* isolate = Isolate::Current(); | 1602 Isolate* isolate = Isolate::Current(); |
1597 DARTSCOPE(isolate); | 1603 DARTSCOPE(isolate); |
1598 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1604 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1605 if (obj.IsByteArray()) { |
| 1606 ByteArray& byte_array = ByteArray::Handle(); |
| 1607 byte_array ^= obj.raw(); |
| 1608 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 1609 ByteArray::Copy(native_array, byte_array, offset, length); |
| 1610 return Api::Success(); |
| 1611 } |
| 1612 return Api::NewError("Invalid length passed in to access list elements"); |
| 1613 } |
1599 if (obj.IsArray()) { | 1614 if (obj.IsArray()) { |
1600 Array& array_obj = Array::Handle(); | 1615 Array& array_obj = Array::Handle(); |
1601 array_obj ^= obj.raw(); | 1616 array_obj ^= obj.raw(); |
1602 if ((offset + length) <= array_obj.Length()) { | 1617 if ((offset + length) <= array_obj.Length()) { |
1603 Object& element = Object::Handle(); | 1618 Object& element = Object::Handle(); |
1604 Integer& integer = Integer::Handle(); | 1619 Integer& integer = Integer::Handle(); |
1605 for (int i = 0; i < length; i++) { | 1620 for (int i = 0; i < length; i++) { |
1606 element = array_obj.At(offset + i); | 1621 element = array_obj.At(offset + i); |
1607 if (!element.IsInteger()) { | 1622 if (!element.IsInteger()) { |
1608 return Api::NewError("%s expects the argument 'list' to be " | 1623 return Api::NewError("%s expects the argument 'list' to be " |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 } | 1667 } |
1653 | 1668 |
1654 | 1669 |
1655 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 1670 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
1656 intptr_t offset, | 1671 intptr_t offset, |
1657 uint8_t* native_array, | 1672 uint8_t* native_array, |
1658 intptr_t length) { | 1673 intptr_t length) { |
1659 Isolate* isolate = Isolate::Current(); | 1674 Isolate* isolate = Isolate::Current(); |
1660 DARTSCOPE(isolate); | 1675 DARTSCOPE(isolate); |
1661 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1676 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1677 if (obj.IsByteArray()) { |
| 1678 ByteArray& byte_array = ByteArray::Handle(); |
| 1679 byte_array ^= obj.raw(); |
| 1680 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 1681 ByteArray::Copy(byte_array, offset, native_array, length); |
| 1682 return Api::Success(); |
| 1683 } |
| 1684 return Api::NewError("Invalid length passed in to set list elements"); |
| 1685 } |
1662 if (obj.IsArray()) { | 1686 if (obj.IsArray()) { |
1663 if (obj.IsImmutableArray()) { | 1687 if (obj.IsImmutableArray()) { |
1664 return Api::NewError("Cannot modify immutable array"); | 1688 return Api::NewError("Cannot modify immutable array"); |
1665 } | 1689 } |
1666 Array& array_obj = Array::Handle(); | 1690 Array& array_obj = Array::Handle(); |
1667 array_obj ^= obj.raw(); | 1691 array_obj ^= obj.raw(); |
1668 Integer& integer = Integer::Handle(); | 1692 Integer& integer = Integer::Handle(); |
1669 if ((offset + length) <= array_obj.Length()) { | 1693 if ((offset + length) <= array_obj.Length()) { |
1670 for (int i = 0; i < length; i++) { | 1694 for (int i = 0; i < length; i++) { |
1671 integer = Integer::New(native_array[i]); | 1695 integer = Integer::New(native_array[i]); |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 } | 2548 } |
2525 delete debug_region; | 2549 delete debug_region; |
2526 } else { | 2550 } else { |
2527 *buffer = NULL; | 2551 *buffer = NULL; |
2528 *buffer_size = 0; | 2552 *buffer_size = 0; |
2529 } | 2553 } |
2530 } | 2554 } |
2531 | 2555 |
2532 | 2556 |
2533 } // namespace dart | 2557 } // namespace dart |
OLD | NEW |