Chromium Code Reviews| 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 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1572 CURRENT_FUNC); | 1572 CURRENT_FUNC); |
| 1573 } | 1573 } |
| 1574 return Api::NewHandle(isolate, String::New(str)); | 1574 return Api::NewHandle(isolate, String::New(str)); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 | 1577 |
| 1578 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | 1578 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, |
| 1579 intptr_t length) { | 1579 intptr_t length) { |
| 1580 Isolate* isolate = Isolate::Current(); | 1580 Isolate* isolate = Isolate::Current(); |
| 1581 DARTSCOPE(isolate); | 1581 DARTSCOPE(isolate); |
| 1582 if (codepoints == NULL) { | |
| 1583 RETURN_NULL_ERROR(codepoints); | |
| 1584 } | |
| 1585 if (length < 0 || length > OneByteString::kMaxElements) { | |
| 1586 return Api::NewError( | |
| 1587 "%s expects argument 'length' to be in the range [0..%ld].", | |
| 1588 CURRENT_FUNC, OneByteString::kMaxElements); | |
| 1589 } | |
| 1582 return Api::NewHandle(isolate, String::New(codepoints, length)); | 1590 return Api::NewHandle(isolate, String::New(codepoints, length)); |
| 1583 } | 1591 } |
| 1584 | 1592 |
| 1585 | 1593 |
| 1586 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | 1594 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, |
| 1587 intptr_t length) { | 1595 intptr_t length) { |
| 1588 Isolate* isolate = Isolate::Current(); | 1596 Isolate* isolate = Isolate::Current(); |
| 1589 DARTSCOPE(isolate); | 1597 DARTSCOPE(isolate); |
| 1598 if (codepoints == NULL) { | |
| 1599 RETURN_NULL_ERROR(codepoints); | |
| 1600 } | |
| 1601 if (length < 0 || length > TwoByteString::kMaxElements) { | |
|
cshapiro
2012/07/19 05:49:01
I thought you were going to add a macro or somethi
turnidge
2012/07/31 23:21:45
Done.
| |
| 1602 return Api::NewError( | |
| 1603 "%s expects argument 'length' to be in the range [0..%ld].", | |
| 1604 CURRENT_FUNC, TwoByteString::kMaxElements); | |
| 1605 } | |
| 1590 return Api::NewHandle(isolate, String::New(codepoints, length)); | 1606 return Api::NewHandle(isolate, String::New(codepoints, length)); |
| 1591 } | 1607 } |
| 1592 | 1608 |
| 1593 | 1609 |
| 1594 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1610 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
| 1595 intptr_t length) { | 1611 intptr_t length) { |
| 1596 Isolate* isolate = Isolate::Current(); | 1612 Isolate* isolate = Isolate::Current(); |
| 1597 DARTSCOPE(isolate); | 1613 DARTSCOPE(isolate); |
| 1614 if (codepoints == NULL) { | |
| 1615 RETURN_NULL_ERROR(codepoints); | |
| 1616 } | |
| 1617 if (length < 0 || length > FourByteString::kMaxElements) { | |
| 1618 return Api::NewError( | |
| 1619 "%s expects argument 'length' to be in the range [0..%ld].", | |
| 1620 CURRENT_FUNC, FourByteString::kMaxElements); | |
| 1621 } | |
| 1598 return Api::NewHandle(isolate, String::New(codepoints, length)); | 1622 return Api::NewHandle(isolate, String::New(codepoints, length)); |
| 1599 } | 1623 } |
| 1600 | 1624 |
| 1601 | 1625 |
| 1602 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1626 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1603 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1627 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 1604 } | 1628 } |
| 1605 | 1629 |
| 1606 | 1630 |
| 1607 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1631 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1645 | 1669 |
| 1646 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, | 1670 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, |
| 1647 intptr_t length, | 1671 intptr_t length, |
| 1648 void* peer, | 1672 void* peer, |
| 1649 Dart_PeerFinalizer callback) { | 1673 Dart_PeerFinalizer callback) { |
| 1650 Isolate* isolate = Isolate::Current(); | 1674 Isolate* isolate = Isolate::Current(); |
| 1651 DARTSCOPE(isolate); | 1675 DARTSCOPE(isolate); |
| 1652 if (codepoints == NULL && length != 0) { | 1676 if (codepoints == NULL && length != 0) { |
| 1653 RETURN_NULL_ERROR(codepoints); | 1677 RETURN_NULL_ERROR(codepoints); |
| 1654 } | 1678 } |
| 1655 if (length < 0) { | 1679 if (length < 0 || length > ExternalTwoByteString::kMaxElements) { |
| 1656 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1680 return Api::NewError( |
| 1657 CURRENT_FUNC); | 1681 "%s expects argument 'length' to be in the range [0..%ld].", |
| 1682 CURRENT_FUNC, ExternalTwoByteString::kMaxElements); | |
| 1658 } | 1683 } |
| 1659 return Api::NewHandle( | 1684 return Api::NewHandle( |
| 1660 isolate, String::NewExternal(codepoints, length, peer, callback)); | 1685 isolate, String::NewExternal(codepoints, length, peer, callback)); |
| 1661 } | 1686 } |
| 1662 | 1687 |
| 1663 | 1688 |
| 1664 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, | 1689 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, |
| 1665 intptr_t length, | 1690 intptr_t length, |
| 1666 void* peer, | 1691 void* peer, |
| 1667 Dart_PeerFinalizer callback) { | 1692 Dart_PeerFinalizer callback) { |
| 1668 Isolate* isolate = Isolate::Current(); | 1693 Isolate* isolate = Isolate::Current(); |
| 1669 DARTSCOPE(isolate); | 1694 DARTSCOPE(isolate); |
| 1670 if (codepoints == NULL && length != 0) { | 1695 if (codepoints == NULL && length != 0) { |
| 1671 RETURN_NULL_ERROR(codepoints); | 1696 RETURN_NULL_ERROR(codepoints); |
| 1672 } | 1697 } |
| 1673 if (length < 0) { | 1698 if (length < 0 || length > ExternalFourByteString::kMaxElements) { |
| 1674 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1699 return Api::NewError( |
| 1675 CURRENT_FUNC); | 1700 "%s expects argument 'length' to be in the range [0..%ld].", |
| 1701 CURRENT_FUNC, ExternalFourByteString::kMaxElements); | |
| 1676 } | 1702 } |
| 1677 return Api::NewHandle( | 1703 return Api::NewHandle( |
| 1678 isolate, String::NewExternal(codepoints, length, peer, callback)); | 1704 isolate, String::NewExternal(codepoints, length, peer, callback)); |
| 1679 } | 1705 } |
| 1680 | 1706 |
| 1681 | 1707 |
| 1682 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | 1708 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, |
| 1683 uint8_t* codepoints, | 1709 uint8_t* codepoints, |
| 1684 intptr_t* length) { | 1710 intptr_t* length) { |
| 1685 Isolate* isolate = Isolate::Current(); | 1711 Isolate* isolate = Isolate::Current(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1816 Isolate* isolate = Isolate::Current(); | 1842 Isolate* isolate = Isolate::Current(); |
| 1817 DARTSCOPE(isolate); | 1843 DARTSCOPE(isolate); |
| 1818 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1844 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1819 return GetListInstance(isolate, obj) != Instance::null(); | 1845 return GetListInstance(isolate, obj) != Instance::null(); |
| 1820 } | 1846 } |
| 1821 | 1847 |
| 1822 | 1848 |
| 1823 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1849 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 1824 Isolate* isolate = Isolate::Current(); | 1850 Isolate* isolate = Isolate::Current(); |
| 1825 DARTSCOPE(isolate); | 1851 DARTSCOPE(isolate); |
| 1852 if (length < 0 || length > Array::kMaxElements) { | |
| 1853 return Api::NewError( | |
| 1854 "%s expects argument 'length' to be in the range [0..%ld].", | |
| 1855 CURRENT_FUNC, Array::kMaxElements); | |
| 1856 } | |
| 1826 return Api::NewHandle(isolate, Array::New(length)); | 1857 return Api::NewHandle(isolate, Array::New(length)); |
| 1827 } | 1858 } |
| 1828 | 1859 |
| 1829 | 1860 |
| 1830 #define GET_LIST_LENGTH(isolate, type, obj, len) \ | 1861 #define GET_LIST_LENGTH(isolate, type, obj, len) \ |
| 1831 type& array = type::Handle(isolate); \ | 1862 type& array = type::Handle(isolate); \ |
| 1832 array ^= obj.raw(); \ | 1863 array ^= obj.raw(); \ |
| 1833 *len = array.Length(); \ | 1864 *len = array.Length(); \ |
| 1834 return Api::Success(isolate); \ | 1865 return Api::Success(isolate); \ |
| 1835 | 1866 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2156 | 2187 |
| 2157 | 2188 |
| 2158 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { | 2189 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { |
| 2159 return RawObject::IsByteArrayClassId(Api::ClassId(object)); | 2190 return RawObject::IsByteArrayClassId(Api::ClassId(object)); |
| 2160 } | 2191 } |
| 2161 | 2192 |
| 2162 | 2193 |
| 2163 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 2194 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| 2164 Isolate* isolate = Isolate::Current(); | 2195 Isolate* isolate = Isolate::Current(); |
| 2165 DARTSCOPE(isolate); | 2196 DARTSCOPE(isolate); |
| 2197 if (length < 0 || length > Uint8Array::kMaxElements) { | |
| 2198 return Api::NewError( | |
| 2199 "%s expects argument 'length' to be in the range [0..%ld] but saw %ld", | |
| 2200 CURRENT_FUNC, Uint8Array::kMaxElements, length); | |
| 2201 } | |
| 2166 return Api::NewHandle(isolate, Uint8Array::New(length)); | 2202 return Api::NewHandle(isolate, Uint8Array::New(length)); |
| 2167 } | 2203 } |
| 2168 | 2204 |
| 2169 | 2205 |
| 2170 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, | 2206 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, |
| 2171 intptr_t length, | 2207 intptr_t length, |
| 2172 void* peer, | 2208 void* peer, |
| 2173 Dart_PeerFinalizer callback) { | 2209 Dart_PeerFinalizer callback) { |
| 2174 Isolate* isolate = Isolate::Current(); | 2210 Isolate* isolate = Isolate::Current(); |
| 2175 DARTSCOPE(isolate); | 2211 DARTSCOPE(isolate); |
| 2176 if (data == NULL && length != 0) { | 2212 if (data == NULL && length != 0) { |
| 2177 RETURN_NULL_ERROR(data); | 2213 RETURN_NULL_ERROR(data); |
| 2178 } | 2214 } |
| 2179 if (length < 0) { | 2215 if (length < 0 || length > ExternalUint8Array::kMaxElements) { |
| 2180 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 2216 return Api::NewError( |
| 2181 CURRENT_FUNC); | 2217 "%s expects argument 'length' to be in the range [0..%ld] but saw %ld", |
| 2218 CURRENT_FUNC, ExternalUint8Array::kMaxElements, length); | |
| 2182 } | 2219 } |
| 2183 return Api::NewHandle( | 2220 return Api::NewHandle( |
| 2184 isolate, ExternalUint8Array::New(data, length, peer, callback)); | 2221 isolate, ExternalUint8Array::New(data, length, peer, callback)); |
| 2185 } | 2222 } |
| 2186 | 2223 |
| 2187 | 2224 |
| 2188 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, | 2225 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, |
| 2189 void** peer) { | 2226 void** peer) { |
| 2190 Isolate* isolate = Isolate::Current(); | 2227 Isolate* isolate = Isolate::Current(); |
| 2191 DARTSCOPE(isolate); | 2228 DARTSCOPE(isolate); |
| (...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4120 *buffer_size = 0; | 4157 *buffer_size = 0; |
| 4121 } | 4158 } |
| 4122 } | 4159 } |
| 4123 | 4160 |
| 4124 | 4161 |
| 4125 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { | 4162 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { |
| 4126 Dart::set_flow_graph_writer(function); | 4163 Dart::set_flow_graph_writer(function); |
| 4127 } | 4164 } |
| 4128 | 4165 |
| 4129 } // namespace dart | 4166 } // namespace dart |
| OLD | NEW |