Chromium Code Reviews| 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 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 DARTSCOPE(Isolate::Current()); | 1352 DARTSCOPE(Isolate::Current()); |
| 1353 const Array& obj = Array::Handle(Array::New(length)); | 1353 const Array& obj = Array::Handle(Array::New(length)); |
| 1354 return Api::NewLocalHandle(obj); | 1354 return Api::NewLocalHandle(obj); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 | 1357 |
| 1358 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1358 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 1359 Isolate* isolate = Isolate::Current(); | 1359 Isolate* isolate = Isolate::Current(); |
| 1360 DARTSCOPE(isolate); | 1360 DARTSCOPE(isolate); |
| 1361 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1361 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1362 if (obj.IsByteArray()) { | |
|
cshapiro
2012/01/27 23:00:04
Two questions. Why is this ahead of array and why
Anders Johnsen
2012/01/27 23:42:39
Adding the native operations for getting/setting d
| |
| 1363 ByteArray& byte_array = ByteArray::Handle(); | |
| 1364 byte_array ^= obj.raw(); | |
| 1365 *len = byte_array.Length(); | |
| 1366 return Api::Success(); | |
| 1367 } | |
| 1362 if (obj.IsArray()) { | 1368 if (obj.IsArray()) { |
| 1363 Array& array_obj = Array::Handle(); | 1369 Array& array_obj = Array::Handle(); |
| 1364 array_obj ^= obj.raw(); | 1370 array_obj ^= obj.raw(); |
| 1365 *len = array_obj.Length(); | 1371 *len = array_obj.Length(); |
| 1366 return Api::Success(); | 1372 return Api::Success(); |
| 1367 } | 1373 } |
| 1368 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1374 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
| 1369 // Now check and handle a dart object that implements the List interface. | 1375 // Now check and handle a dart object that implements the List interface. |
| 1370 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); | 1376 const Instance& instance = Instance::Handle(GetListInstance(isolate, obj)); |
| 1371 if (!instance.IsNull()) { | 1377 if (!instance.IsNull()) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1557 } | 1563 } |
| 1558 | 1564 |
| 1559 | 1565 |
| 1560 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1566 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
| 1561 intptr_t offset, | 1567 intptr_t offset, |
| 1562 uint8_t* native_array, | 1568 uint8_t* native_array, |
| 1563 intptr_t length) { | 1569 intptr_t length) { |
| 1564 Isolate* isolate = Isolate::Current(); | 1570 Isolate* isolate = Isolate::Current(); |
| 1565 DARTSCOPE(isolate); | 1571 DARTSCOPE(isolate); |
| 1566 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1572 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1573 if (obj.IsByteArray()) { | |
| 1574 ByteArray& byte_array = ByteArray::Handle(); | |
| 1575 byte_array ^= obj.raw(); | |
| 1576 if ((offset + length) <= byte_array.Length()) { | |
| 1577 ByteArray::Copy(native_array, byte_array, offset, length); | |
| 1578 return Api::Success(); | |
| 1579 } | |
| 1580 return Api::NewError("Invalid length passed in to access array elements"); | |
|
cshapiro
2012/01/27 23:00:04
list elements, right? I think the list interface
Anders Johnsen
2012/01/27 23:42:39
Done.
| |
| 1581 } | |
| 1567 if (obj.IsArray()) { | 1582 if (obj.IsArray()) { |
| 1568 Array& array_obj = Array::Handle(); | 1583 Array& array_obj = Array::Handle(); |
| 1569 array_obj ^= obj.raw(); | 1584 array_obj ^= obj.raw(); |
| 1570 if ((offset + length) <= array_obj.Length()) { | 1585 if ((offset + length) <= array_obj.Length()) { |
| 1571 Object& element = Object::Handle(); | 1586 Object& element = Object::Handle(); |
| 1572 Integer& integer = Integer::Handle(); | 1587 Integer& integer = Integer::Handle(); |
| 1573 for (int i = 0; i < length; i++) { | 1588 for (int i = 0; i < length; i++) { |
| 1574 element = array_obj.At(offset + i); | 1589 element = array_obj.At(offset + i); |
| 1575 if (!element.IsInteger()) { | 1590 if (!element.IsInteger()) { |
| 1576 return Api::NewError("%s expects the argument 'list' to be " | 1591 return Api::NewError("%s expects the argument 'list' to be " |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1620 } | 1635 } |
| 1621 | 1636 |
| 1622 | 1637 |
| 1623 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 1638 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
| 1624 intptr_t offset, | 1639 intptr_t offset, |
| 1625 uint8_t* native_array, | 1640 uint8_t* native_array, |
| 1626 intptr_t length) { | 1641 intptr_t length) { |
| 1627 Isolate* isolate = Isolate::Current(); | 1642 Isolate* isolate = Isolate::Current(); |
| 1628 DARTSCOPE(isolate); | 1643 DARTSCOPE(isolate); |
| 1629 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); | 1644 const Object& obj = Object::Handle(Api::UnwrapHandle(list)); |
| 1645 if (obj.IsByteArray()) { | |
| 1646 ByteArray& byte_array = ByteArray::Handle(); | |
| 1647 byte_array ^= obj.raw(); | |
| 1648 if ((offset + length) <= byte_array.Length()) { | |
| 1649 ByteArray::Copy(byte_array, offset, native_array, length); | |
| 1650 return Api::Success(); | |
| 1651 } | |
| 1652 return Api::NewError("Invalid length passed in to access array elements"); | |
| 1653 } | |
| 1630 if (obj.IsArray()) { | 1654 if (obj.IsArray()) { |
| 1631 if (obj.IsImmutableArray()) { | 1655 if (obj.IsImmutableArray()) { |
| 1632 return Api::NewError("Cannot modify immutable array"); | 1656 return Api::NewError("Cannot modify immutable array"); |
| 1633 } | 1657 } |
| 1634 Array& array_obj = Array::Handle(); | 1658 Array& array_obj = Array::Handle(); |
| 1635 array_obj ^= obj.raw(); | 1659 array_obj ^= obj.raw(); |
| 1636 Integer& integer = Integer::Handle(); | 1660 Integer& integer = Integer::Handle(); |
| 1637 if ((offset + length) <= array_obj.Length()) { | 1661 if ((offset + length) <= array_obj.Length()) { |
| 1638 for (int i = 0; i < length; i++) { | 1662 for (int i = 0; i < length; i++) { |
| 1639 integer = Integer::New(native_array[i]); | 1663 integer = Integer::New(native_array[i]); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2492 } | 2516 } |
| 2493 delete debug_region; | 2517 delete debug_region; |
| 2494 } else { | 2518 } else { |
| 2495 *buffer = NULL; | 2519 *buffer = NULL; |
| 2496 *buffer_size = 0; | 2520 *buffer_size = 0; |
| 2497 } | 2521 } |
| 2498 } | 2522 } |
| 2499 | 2523 |
| 2500 | 2524 |
| 2501 } // namespace dart | 2525 } // namespace dart |
| OLD | NEW |