| 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 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 } | 1583 } |
| 1584 } | 1584 } |
| 1585 return Instance::null(); | 1585 return Instance::null(); |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 | 1588 |
| 1589 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1589 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 1590 Isolate* isolate = Isolate::Current(); | 1590 Isolate* isolate = Isolate::Current(); |
| 1591 DARTSCOPE(isolate); | 1591 DARTSCOPE(isolate); |
| 1592 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1592 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1593 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1593 return (obj.IsArray() || obj.IsGrowableObjectArray() || |
| 1594 return (obj.IsArray() || | |
| 1595 (GetListInstance(isolate, obj) != Instance::null())); | 1594 (GetListInstance(isolate, obj) != Instance::null())); |
| 1596 } | 1595 } |
| 1597 | 1596 |
| 1598 | 1597 |
| 1599 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1598 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 1600 Isolate* isolate = Isolate::Current(); | 1599 Isolate* isolate = Isolate::Current(); |
| 1601 DARTSCOPE(isolate); | 1600 DARTSCOPE(isolate); |
| 1602 return Api::NewHandle(isolate, Array::New(length)); | 1601 return Api::NewHandle(isolate, Array::New(length)); |
| 1603 } | 1602 } |
| 1604 | 1603 |
| 1605 | 1604 |
| 1605 #define GET_LIST_LENGTH(isolate, type, obj, len) \ |
| 1606 type& array = type::Handle(isolate); \ |
| 1607 array ^= obj.raw(); \ |
| 1608 *len = array.Length(); \ |
| 1609 return Api::Success(isolate); \ |
| 1610 |
| 1611 |
| 1606 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1612 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 1607 Isolate* isolate = Isolate::Current(); | 1613 Isolate* isolate = Isolate::Current(); |
| 1608 DARTSCOPE(isolate); | 1614 DARTSCOPE(isolate); |
| 1609 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1615 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1610 if (obj.IsByteArray()) { | 1616 if (obj.IsByteArray()) { |
| 1611 ByteArray& byte_array = ByteArray::Handle(isolate); | 1617 GET_LIST_LENGTH(isolate, ByteArray, obj, len); |
| 1612 byte_array ^= obj.raw(); | |
| 1613 *len = byte_array.Length(); | |
| 1614 return Api::Success(isolate); | |
| 1615 } | 1618 } |
| 1616 if (obj.IsArray()) { | 1619 if (obj.IsArray()) { |
| 1617 Array& array_obj = Array::Handle(isolate); | 1620 GET_LIST_LENGTH(isolate, Array, obj, len); |
| 1618 array_obj ^= obj.raw(); | |
| 1619 *len = array_obj.Length(); | |
| 1620 return Api::Success(isolate); | |
| 1621 } | 1621 } |
| 1622 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1622 if (obj.IsGrowableObjectArray()) { |
| 1623 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); |
| 1624 } |
| 1623 // Now check and handle a dart object that implements the List interface. | 1625 // Now check and handle a dart object that implements the List interface. |
| 1624 const Instance& instance = | 1626 const Instance& instance = |
| 1625 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1627 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1626 if (instance.IsNull()) { | 1628 if (instance.IsNull()) { |
| 1627 return Api::NewError("Object does not implement the List inteface"); | 1629 return Api::NewError("Object does not implement the List inteface"); |
| 1628 } | 1630 } |
| 1629 String& name = String::Handle(isolate, String::New("length")); | 1631 String& name = String::Handle(isolate, String::New("length")); |
| 1630 name = Field::GetterName(name); | 1632 name = Field::GetterName(name); |
| 1631 const Function& function = | 1633 const Function& function = |
| 1632 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1634 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1655 "maximum value that 'len' parameter can hold"); | 1657 "maximum value that 'len' parameter can hold"); |
| 1656 } | 1658 } |
| 1657 } else if (retval.IsError()) { | 1659 } else if (retval.IsError()) { |
| 1658 return Api::NewHandle(isolate, retval.raw()); | 1660 return Api::NewHandle(isolate, retval.raw()); |
| 1659 } else { | 1661 } else { |
| 1660 return Api::NewError("Length of List object is not an integer"); | 1662 return Api::NewError("Length of List object is not an integer"); |
| 1661 } | 1663 } |
| 1662 } | 1664 } |
| 1663 | 1665 |
| 1664 | 1666 |
| 1667 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ |
| 1668 type& array_obj = type::Handle(isolate); \ |
| 1669 array_obj ^= obj.raw(); \ |
| 1670 if ((index >= 0) && (index < array_obj.Length())) { \ |
| 1671 return Api::NewHandle(isolate, array_obj.At(index)); \ |
| 1672 } \ |
| 1673 return Api::NewError("Invalid index passed in to access list element"); \ |
| 1674 |
| 1675 |
| 1665 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1676 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 1666 Isolate* isolate = Isolate::Current(); | 1677 Isolate* isolate = Isolate::Current(); |
| 1667 DARTSCOPE(isolate); | 1678 DARTSCOPE(isolate); |
| 1668 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1679 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1669 if (obj.IsArray()) { | 1680 if (obj.IsArray()) { |
| 1670 Array& array_obj = Array::Handle(isolate); | 1681 GET_LIST_ELEMENT(isolate, Array, obj, index); |
| 1671 array_obj ^= obj.raw(); | |
| 1672 if ((index >= 0) && (index < array_obj.Length())) { | |
| 1673 return Api::NewHandle(isolate, array_obj.At(index)); | |
| 1674 } | |
| 1675 return Api::NewError("Invalid index passed in to access array element"); | |
| 1676 } | 1682 } |
| 1677 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1683 if (obj.IsGrowableObjectArray()) { |
| 1684 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); |
| 1685 } |
| 1678 // Now check and handle a dart object that implements the List interface. | 1686 // Now check and handle a dart object that implements the List interface. |
| 1679 const Instance& instance = | 1687 const Instance& instance = |
| 1680 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1688 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1681 if (!instance.IsNull()) { | 1689 if (!instance.IsNull()) { |
| 1682 String& name = String::Handle(isolate, String::New("[]")); | 1690 String& name = String::Handle(isolate, String::New("[]")); |
| 1683 const Function& function = | 1691 const Function& function = |
| 1684 Function::Handle(isolate, | 1692 Function::Handle(isolate, |
| 1685 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1693 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1686 if (!function.IsNull()) { | 1694 if (!function.IsNull()) { |
| 1687 GrowableArray<const Object*> args(1); | 1695 GrowableArray<const Object*> args(1); |
| 1688 Integer& indexobj = Integer::Handle(isolate); | 1696 Integer& indexobj = Integer::Handle(isolate); |
| 1689 indexobj = Integer::New(index); | 1697 indexobj = Integer::New(index); |
| 1690 args.Add(&indexobj); | 1698 args.Add(&indexobj); |
| 1691 const Array& kNoArgumentNames = Array::Handle(isolate); | 1699 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1692 return Api::NewHandle( | 1700 return Api::NewHandle( |
| 1693 isolate, | 1701 isolate, |
| 1694 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1702 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
| 1695 } | 1703 } |
| 1696 } | 1704 } |
| 1697 return Api::NewError("Object does not implement the 'List' interface"); | 1705 return Api::NewError("Object does not implement the 'List' interface"); |
| 1698 } | 1706 } |
| 1699 | 1707 |
| 1700 | 1708 |
| 1709 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
| 1710 type& array = type::Handle(isolate); \ |
| 1711 array ^= obj.raw(); \ |
| 1712 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |
| 1713 if ((index >= 0) && (index < array.Length())) { \ |
| 1714 array.SetAt(index, value_obj); \ |
| 1715 return Api::Success(isolate); \ |
| 1716 } \ |
| 1717 return Api::NewError("Invalid index passed in to set list element"); \ |
| 1718 |
| 1719 |
| 1701 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1720 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 1702 intptr_t index, | 1721 intptr_t index, |
| 1703 Dart_Handle value) { | 1722 Dart_Handle value) { |
| 1704 Isolate* isolate = Isolate::Current(); | 1723 Isolate* isolate = Isolate::Current(); |
| 1705 DARTSCOPE(isolate); | 1724 DARTSCOPE(isolate); |
| 1706 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1725 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1707 if (obj.IsArray()) { | 1726 if (obj.IsArray()) { |
| 1708 if (obj.IsImmutableArray()) { | 1727 if (obj.IsImmutableArray()) { |
| 1709 return Api::NewError("Cannot modify immutable array"); | 1728 return Api::NewError("Cannot modify immutable array"); |
| 1710 } | 1729 } |
| 1711 Array& array_obj = Array::Handle(isolate); | 1730 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1712 array_obj ^= obj.raw(); | |
| 1713 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | |
| 1714 if ((index >= 0) && (index < array_obj.Length())) { | |
| 1715 array_obj.SetAt(index, value_obj); | |
| 1716 return Api::Success(isolate); | |
| 1717 } | |
| 1718 return Api::NewError("Invalid index passed in to set array element"); | |
| 1719 } | 1731 } |
| 1720 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1732 if (obj.IsGrowableObjectArray()) { |
| 1733 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1734 } |
| 1721 // Now check and handle a dart object that implements the List interface. | 1735 // Now check and handle a dart object that implements the List interface. |
| 1722 const Instance& instance = | 1736 const Instance& instance = |
| 1723 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1737 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1724 if (!instance.IsNull()) { | 1738 if (!instance.IsNull()) { |
| 1725 String& name = String::Handle(isolate, String::New("[]=")); | 1739 String& name = String::Handle(isolate, String::New("[]=")); |
| 1726 const Function& function = | 1740 const Function& function = |
| 1727 Function::Handle(isolate, | 1741 Function::Handle(isolate, |
| 1728 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1742 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1729 if (!function.IsNull()) { | 1743 if (!function.IsNull()) { |
| 1730 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); | 1744 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); |
| 1731 const Object& value_obj = | 1745 const Object& value_obj = |
| 1732 Object::Handle(isolate, Api::UnwrapHandle(value)); | 1746 Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 1733 GrowableArray<const Object*> args(2); | 1747 GrowableArray<const Object*> args(2); |
| 1734 args.Add(&index_obj); | 1748 args.Add(&index_obj); |
| 1735 args.Add(&value_obj); | 1749 args.Add(&value_obj); |
| 1736 const Array& kNoArgumentNames = Array::Handle(isolate); | 1750 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1737 return Api::NewHandle( | 1751 return Api::NewHandle( |
| 1738 isolate, | 1752 isolate, |
| 1739 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1753 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
| 1740 } | 1754 } |
| 1741 } | 1755 } |
| 1742 return Api::NewError("Object does not implement the 'List' interface"); | 1756 return Api::NewError("Object does not implement the 'List' interface"); |
| 1743 } | 1757 } |
| 1744 | 1758 |
| 1745 | 1759 |
| 1760 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. |
| 1761 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
| 1762 length) \ |
| 1763 type& array = type::Handle(isolate); \ |
| 1764 array ^= obj.raw(); \ |
| 1765 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 1766 Object& element = Object::Handle(isolate); \ |
| 1767 Integer& integer = Integer::Handle(isolate); \ |
| 1768 for (int i = 0; i < length; i++) { \ |
| 1769 element = array.At(offset + i); \ |
| 1770 if (!element.IsInteger()) { \ |
| 1771 return Api::NewError("%s expects the argument 'list' to be " \ |
| 1772 "a List of int", CURRENT_FUNC); \ |
| 1773 } \ |
| 1774 integer ^= element.raw(); \ |
| 1775 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
| 1776 ASSERT(integer.AsInt64Value() <= 0xff); \ |
| 1777 } \ |
| 1778 return Api::Success(isolate); \ |
| 1779 } \ |
| 1780 return Api::NewError("Invalid length passed in to access array elements"); \ |
| 1781 |
| 1782 |
| 1746 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1783 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
| 1747 intptr_t offset, | 1784 intptr_t offset, |
| 1748 uint8_t* native_array, | 1785 uint8_t* native_array, |
| 1749 intptr_t length) { | 1786 intptr_t length) { |
| 1750 Isolate* isolate = Isolate::Current(); | 1787 Isolate* isolate = Isolate::Current(); |
| 1751 DARTSCOPE(isolate); | 1788 DARTSCOPE(isolate); |
| 1752 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1789 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1753 if (obj.IsByteArray()) { | 1790 if (obj.IsByteArray()) { |
| 1754 ByteArray& byte_array = ByteArray::Handle(isolate); | 1791 ByteArray& byte_array = ByteArray::Handle(isolate); |
| 1755 byte_array ^= obj.raw(); | 1792 byte_array ^= obj.raw(); |
| 1756 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 1793 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 1757 ByteArray::Copy(native_array, byte_array, offset, length); | 1794 ByteArray::Copy(native_array, byte_array, offset, length); |
| 1758 return Api::Success(isolate); | 1795 return Api::Success(isolate); |
| 1759 } | 1796 } |
| 1760 return Api::NewError("Invalid length passed in to access list elements"); | 1797 return Api::NewError("Invalid length passed in to access list elements"); |
| 1761 } | 1798 } |
| 1762 if (obj.IsArray()) { | 1799 if (obj.IsArray()) { |
| 1763 Array& array_obj = Array::Handle(isolate); | 1800 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1764 array_obj ^= obj.raw(); | 1801 Array, |
| 1765 if (Utils::RangeCheck(offset, length, array_obj.Length())) { | 1802 obj, |
| 1766 Object& element = Object::Handle(isolate); | 1803 native_array, |
| 1767 Integer& integer = Integer::Handle(isolate); | 1804 offset, |
| 1768 for (int i = 0; i < length; i++) { | 1805 length); } |
| 1769 element = array_obj.At(offset + i); | 1806 if (obj.IsGrowableObjectArray()) { |
| 1770 if (!element.IsInteger()) { | 1807 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1771 return Api::NewError("%s expects the argument 'list' to be " | 1808 GrowableObjectArray, |
| 1772 "a List of int", CURRENT_FUNC); | 1809 obj, |
| 1773 } | 1810 native_array, |
| 1774 integer ^= element.raw(); | 1811 offset, |
| 1775 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); | 1812 length); |
| 1776 ASSERT(integer.AsInt64Value() <= 0xff); | |
| 1777 // TODO(hpayer): value should always be smaller then 0xff. Add error | |
| 1778 // handling. | |
| 1779 } | |
| 1780 return Api::Success(isolate); | |
| 1781 } | |
| 1782 return Api::NewError("Invalid length passed in to access array elements"); | |
| 1783 } | 1813 } |
| 1784 // TODO(5526318): Make access to GrowableObjectArray more efficient. | |
| 1785 // Now check and handle a dart object that implements the List interface. | 1814 // Now check and handle a dart object that implements the List interface. |
| 1786 const Instance& instance = | 1815 const Instance& instance = |
| 1787 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1816 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1788 if (!instance.IsNull()) { | 1817 if (!instance.IsNull()) { |
| 1789 String& name = String::Handle(isolate, String::New("[]")); | 1818 String& name = String::Handle(isolate, String::New("[]")); |
| 1790 const Function& function = | 1819 const Function& function = |
| 1791 Function::Handle(isolate, | 1820 Function::Handle(isolate, |
| 1792 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1821 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1793 if (!function.IsNull()) { | 1822 if (!function.IsNull()) { |
| 1794 Object& result = Object::Handle(isolate); | 1823 Object& result = Object::Handle(isolate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1813 // handling. | 1842 // handling. |
| 1814 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1843 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
| 1815 } | 1844 } |
| 1816 return Api::Success(isolate); | 1845 return Api::Success(isolate); |
| 1817 } | 1846 } |
| 1818 } | 1847 } |
| 1819 return Api::NewError("Object does not implement the 'List' interface"); | 1848 return Api::NewError("Object does not implement the 'List' interface"); |
| 1820 } | 1849 } |
| 1821 | 1850 |
| 1822 | 1851 |
| 1852 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
| 1853 length) \ |
| 1854 type& array = type::Handle(isolate); \ |
| 1855 array ^= obj.raw(); \ |
| 1856 Integer& integer = Integer::Handle(isolate); \ |
| 1857 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 1858 for (int i = 0; i < length; i++) { \ |
| 1859 integer = Integer::New(native_array[i]); \ |
| 1860 array.SetAt(offset + i, integer); \ |
| 1861 } \ |
| 1862 return Api::Success(isolate); \ |
| 1863 } \ |
| 1864 return Api::NewError("Invalid length passed in to set array elements"); \ |
| 1865 |
| 1866 |
| 1823 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 1867 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
| 1824 intptr_t offset, | 1868 intptr_t offset, |
| 1825 uint8_t* native_array, | 1869 uint8_t* native_array, |
| 1826 intptr_t length) { | 1870 intptr_t length) { |
| 1827 Isolate* isolate = Isolate::Current(); | 1871 Isolate* isolate = Isolate::Current(); |
| 1828 DARTSCOPE(isolate); | 1872 DARTSCOPE(isolate); |
| 1829 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1873 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1830 if (obj.IsByteArray()) { | 1874 if (obj.IsByteArray()) { |
| 1831 ByteArray& byte_array = ByteArray::Handle(isolate); | 1875 ByteArray& byte_array = ByteArray::Handle(isolate); |
| 1832 byte_array ^= obj.raw(); | 1876 byte_array ^= obj.raw(); |
| 1833 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 1877 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 1834 ByteArray::Copy(byte_array, offset, native_array, length); | 1878 ByteArray::Copy(byte_array, offset, native_array, length); |
| 1835 return Api::Success(isolate); | 1879 return Api::Success(isolate); |
| 1836 } | 1880 } |
| 1837 return Api::NewError("Invalid length passed in to set list elements"); | 1881 return Api::NewError("Invalid length passed in to set list elements"); |
| 1838 } | 1882 } |
| 1839 if (obj.IsArray()) { | 1883 if (obj.IsArray()) { |
| 1840 if (obj.IsImmutableArray()) { | 1884 if (obj.IsImmutableArray()) { |
| 1841 return Api::NewError("Cannot modify immutable array"); | 1885 return Api::NewError("Cannot modify immutable array"); |
| 1842 } | 1886 } |
| 1843 Array& array_obj = Array::Handle(isolate); | 1887 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1844 array_obj ^= obj.raw(); | 1888 Array, |
| 1845 Integer& integer = Integer::Handle(isolate); | 1889 obj, |
| 1846 if (Utils::RangeCheck(offset, length, array_obj.Length())) { | 1890 native_array, |
| 1847 for (int i = 0; i < length; i++) { | 1891 offset, |
| 1848 integer = Integer::New(native_array[i]); | 1892 length); |
| 1849 array_obj.SetAt(offset + i, integer); | |
| 1850 } | |
| 1851 return Api::Success(isolate); | |
| 1852 } | |
| 1853 return Api::NewError("Invalid length passed in to set array elements"); | |
| 1854 } | 1893 } |
| 1855 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1894 if (obj.IsGrowableObjectArray()) { |
| 1895 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1896 GrowableObjectArray, |
| 1897 obj, |
| 1898 native_array, |
| 1899 offset, |
| 1900 length); |
| 1901 } |
| 1856 // Now check and handle a dart object that implements the List interface. | 1902 // Now check and handle a dart object that implements the List interface. |
| 1857 const Instance& instance = | 1903 const Instance& instance = |
| 1858 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1904 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1859 if (!instance.IsNull()) { | 1905 if (!instance.IsNull()) { |
| 1860 String& name = String::Handle(isolate, String::New("[]=")); | 1906 String& name = String::Handle(isolate, String::New("[]=")); |
| 1861 const Function& function = | 1907 const Function& function = |
| 1862 Function::Handle(isolate, | 1908 Function::Handle(isolate, |
| 1863 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1909 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1864 if (!function.IsNull()) { | 1910 if (!function.IsNull()) { |
| 1865 Integer& indexobj = Integer::Handle(isolate); | 1911 Integer& indexobj = Integer::Handle(isolate); |
| (...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3353 *buffer = NULL; | 3399 *buffer = NULL; |
| 3354 } | 3400 } |
| 3355 delete debug_region; | 3401 delete debug_region; |
| 3356 } else { | 3402 } else { |
| 3357 *buffer = NULL; | 3403 *buffer = NULL; |
| 3358 *buffer_size = 0; | 3404 *buffer_size = 0; |
| 3359 } | 3405 } |
| 3360 } | 3406 } |
| 3361 | 3407 |
| 3362 } // namespace dart | 3408 } // namespace dart |
| OLD | NEW |