| 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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 } \ | 1818 } \ |
| 1819 return Api::NewError("Invalid index passed in to access list element"); \ | 1819 return Api::NewError("Invalid index passed in to access list element"); \ |
| 1820 | 1820 |
| 1821 | 1821 |
| 1822 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1822 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 1823 Isolate* isolate = Isolate::Current(); | 1823 Isolate* isolate = Isolate::Current(); |
| 1824 DARTSCOPE(isolate); | 1824 DARTSCOPE(isolate); |
| 1825 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1825 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1826 if (obj.IsArray()) { | 1826 if (obj.IsArray()) { |
| 1827 GET_LIST_ELEMENT(isolate, Array, obj, index); | 1827 GET_LIST_ELEMENT(isolate, Array, obj, index); |
| 1828 } else if (obj.IsGrowableObjectArray()) { |
| 1829 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); |
| 1830 } else if (obj.IsError()) { |
| 1831 return list; |
| 1832 } else { |
| 1833 // Check and handle a dart object that implements the List interface. |
| 1834 const Instance& instance = |
| 1835 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1836 if (!instance.IsNull()) { |
| 1837 String& name = String::Handle(isolate, String::New("[]")); |
| 1838 const Function& function = |
| 1839 Function::Handle(isolate, |
| 1840 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1841 if (!function.IsNull()) { |
| 1842 GrowableArray<const Object*> args(1); |
| 1843 Integer& indexobj = Integer::Handle(isolate); |
| 1844 indexobj = Integer::New(index); |
| 1845 args.Add(&indexobj); |
| 1846 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1847 return Api::NewHandle(isolate, DartEntry::InvokeDynamic( |
| 1848 instance, function, args, kNoArgumentNames)); |
| 1849 } |
| 1850 } |
| 1851 return Api::NewError("Object does not implement the 'List' interface"); |
| 1828 } | 1852 } |
| 1829 if (obj.IsGrowableObjectArray()) { | |
| 1830 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); | |
| 1831 } | |
| 1832 // Now check and handle a dart object that implements the List interface. | |
| 1833 const Instance& instance = | |
| 1834 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
| 1835 if (!instance.IsNull()) { | |
| 1836 String& name = String::Handle(isolate, String::New("[]")); | |
| 1837 const Function& function = | |
| 1838 Function::Handle(isolate, | |
| 1839 Resolver::ResolveDynamic(instance, name, 2, 0)); | |
| 1840 if (!function.IsNull()) { | |
| 1841 GrowableArray<const Object*> args(1); | |
| 1842 Integer& indexobj = Integer::Handle(isolate); | |
| 1843 indexobj = Integer::New(index); | |
| 1844 args.Add(&indexobj); | |
| 1845 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 1846 return Api::NewHandle( | |
| 1847 isolate, | |
| 1848 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | |
| 1849 } | |
| 1850 } | |
| 1851 return Api::NewError("Object does not implement the 'List' interface"); | |
| 1852 } | 1853 } |
| 1853 | 1854 |
| 1854 | 1855 |
| 1855 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ | 1856 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
| 1856 const type& array = type::Cast(obj); \ | 1857 const type& array = type::Cast(obj); \ |
| 1857 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ | 1858 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |
| 1859 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ |
| 1860 RETURN_TYPE_ERROR(isolate, value, Instance); \ |
| 1861 } \ |
| 1858 if ((index >= 0) && (index < array.Length())) { \ | 1862 if ((index >= 0) && (index < array.Length())) { \ |
| 1859 array.SetAt(index, value_obj); \ | 1863 array.SetAt(index, value_obj); \ |
| 1860 return Api::Success(isolate); \ | 1864 return Api::Success(isolate); \ |
| 1861 } \ | 1865 } \ |
| 1862 return Api::NewError("Invalid index passed in to set list element"); \ | 1866 return Api::NewError("Invalid index passed in to set list element"); \ |
| 1863 | 1867 |
| 1864 | 1868 |
| 1865 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1869 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 1866 intptr_t index, | 1870 intptr_t index, |
| 1867 Dart_Handle value) { | 1871 Dart_Handle value) { |
| 1868 Isolate* isolate = Isolate::Current(); | 1872 Isolate* isolate = Isolate::Current(); |
| 1869 DARTSCOPE(isolate); | 1873 DARTSCOPE(isolate); |
| 1870 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1874 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1871 if (obj.IsArray()) { | 1875 if (obj.IsArray()) { |
| 1872 if (obj.IsImmutableArray()) { | 1876 if (obj.IsImmutableArray()) { |
| 1873 return Api::NewError("Cannot modify immutable array"); | 1877 return Api::NewError("Cannot modify immutable array"); |
| 1874 } | 1878 } |
| 1875 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 1879 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1880 } else if (obj.IsGrowableObjectArray()) { |
| 1881 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1882 } else if (obj.IsError()) { |
| 1883 return list; |
| 1884 } else { |
| 1885 // Check and handle a dart object that implements the List interface. |
| 1886 const Instance& instance = |
| 1887 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1888 if (!instance.IsNull()) { |
| 1889 String& name = String::Handle(isolate, String::New("[]=")); |
| 1890 const Function& function = |
| 1891 Function::Handle(isolate, |
| 1892 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1893 if (!function.IsNull()) { |
| 1894 const Integer& index_obj = |
| 1895 Integer::Handle(isolate, Integer::New(index)); |
| 1896 const Object& value_obj = |
| 1897 Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 1898 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 1899 RETURN_TYPE_ERROR(isolate, value, Instance); |
| 1900 } |
| 1901 GrowableArray<const Object*> args(2); |
| 1902 args.Add(&index_obj); |
| 1903 args.Add(&value_obj); |
| 1904 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1905 return Api::NewHandle(isolate, DartEntry::InvokeDynamic( |
| 1906 instance, function, args, kNoArgumentNames)); |
| 1907 } |
| 1908 } |
| 1909 return Api::NewError("Object does not implement the 'List' interface"); |
| 1876 } | 1910 } |
| 1877 if (obj.IsGrowableObjectArray()) { | |
| 1878 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | |
| 1879 } | |
| 1880 // Now check and handle a dart object that implements the List interface. | |
| 1881 const Instance& instance = | |
| 1882 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
| 1883 if (!instance.IsNull()) { | |
| 1884 String& name = String::Handle(isolate, String::New("[]=")); | |
| 1885 const Function& function = | |
| 1886 Function::Handle(isolate, | |
| 1887 Resolver::ResolveDynamic(instance, name, 3, 0)); | |
| 1888 if (!function.IsNull()) { | |
| 1889 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); | |
| 1890 const Object& value_obj = | |
| 1891 Object::Handle(isolate, Api::UnwrapHandle(value)); | |
| 1892 GrowableArray<const Object*> args(2); | |
| 1893 args.Add(&index_obj); | |
| 1894 args.Add(&value_obj); | |
| 1895 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 1896 return Api::NewHandle( | |
| 1897 isolate, | |
| 1898 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | |
| 1899 } | |
| 1900 } | |
| 1901 return Api::NewError("Object does not implement the 'List' interface"); | |
| 1902 } | 1911 } |
| 1903 | 1912 |
| 1904 | 1913 |
| 1905 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. | 1914 // TODO(hpayer): value should always be smaller then 0xff. Add error handling. |
| 1906 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 1915 #define GET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
| 1907 length) \ | 1916 length) \ |
| 1908 const type& array = type::Cast(obj); \ | 1917 const type& array = type::Cast(obj); \ |
| 1909 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 1918 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 1910 Object& element = Object::Handle(isolate); \ | 1919 Object& element = Object::Handle(isolate); \ |
| 1911 for (int i = 0; i < length; i++) { \ | 1920 for (int i = 0; i < length; i++) { \ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1930 Isolate* isolate = Isolate::Current(); | 1939 Isolate* isolate = Isolate::Current(); |
| 1931 DARTSCOPE(isolate); | 1940 DARTSCOPE(isolate); |
| 1932 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1941 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1933 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { | 1942 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { |
| 1934 const ByteArray& byte_array = ByteArray::Cast(obj); | 1943 const ByteArray& byte_array = ByteArray::Cast(obj); |
| 1935 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 1944 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 1936 ByteArray::Copy(native_array, byte_array, offset, length); | 1945 ByteArray::Copy(native_array, byte_array, offset, length); |
| 1937 return Api::Success(isolate); | 1946 return Api::Success(isolate); |
| 1938 } | 1947 } |
| 1939 return Api::NewError("Invalid length passed in to access list elements"); | 1948 return Api::NewError("Invalid length passed in to access list elements"); |
| 1940 } | 1949 } else if (obj.IsArray()) { |
| 1941 if (obj.IsArray()) { | |
| 1942 GET_LIST_ELEMENT_AS_BYTES(isolate, | 1950 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1943 Array, | 1951 Array, |
| 1944 obj, | 1952 obj, |
| 1945 native_array, | 1953 native_array, |
| 1946 offset, | 1954 offset, |
| 1947 length); } | 1955 length); |
| 1948 if (obj.IsGrowableObjectArray()) { | 1956 } else if (obj.IsGrowableObjectArray()) { |
| 1949 GET_LIST_ELEMENT_AS_BYTES(isolate, | 1957 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 1950 GrowableObjectArray, | 1958 GrowableObjectArray, |
| 1951 obj, | 1959 obj, |
| 1952 native_array, | 1960 native_array, |
| 1953 offset, | 1961 offset, |
| 1954 length); | 1962 length); |
| 1963 } else if (obj.IsError()) { |
| 1964 return list; |
| 1965 } else { |
| 1966 // Check and handle a dart object that implements the List interface. |
| 1967 const Instance& instance = |
| 1968 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1969 if (!instance.IsNull()) { |
| 1970 String& name = String::Handle(isolate, String::New("[]")); |
| 1971 const Function& function = |
| 1972 Function::Handle(isolate, |
| 1973 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 1974 if (!function.IsNull()) { |
| 1975 Object& result = Object::Handle(isolate); |
| 1976 Integer& intobj = Integer::Handle(isolate); |
| 1977 for (int i = 0; i < length; i++) { |
| 1978 intobj = Integer::New(offset + i); |
| 1979 GrowableArray<const Object*> args(1); |
| 1980 args.Add(&intobj); |
| 1981 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1982 result = DartEntry::InvokeDynamic( |
| 1983 instance, function, args, kNoArgumentNames); |
| 1984 if (result.IsError()) { |
| 1985 return Api::NewHandle(isolate, result.raw()); |
| 1986 } |
| 1987 if (!result.IsInteger()) { |
| 1988 return Api::NewError("%s expects the argument 'list' to be " |
| 1989 "a List of int", CURRENT_FUNC); |
| 1990 } |
| 1991 const Integer& integer_result = Integer::Cast(result); |
| 1992 ASSERT(integer_result.AsInt64Value() <= 0xff); |
| 1993 // TODO(hpayer): value should always be smaller then 0xff. Add error |
| 1994 // handling. |
| 1995 native_array[i] = |
| 1996 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); |
| 1997 } |
| 1998 return Api::Success(isolate); |
| 1999 } |
| 2000 } |
| 2001 return Api::NewError("Object does not implement the 'List' interface"); |
| 1955 } | 2002 } |
| 1956 // Now check and handle a dart object that implements the List interface. | |
| 1957 const Instance& instance = | |
| 1958 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
| 1959 if (!instance.IsNull()) { | |
| 1960 String& name = String::Handle(isolate, String::New("[]")); | |
| 1961 const Function& function = | |
| 1962 Function::Handle(isolate, | |
| 1963 Resolver::ResolveDynamic(instance, name, 2, 0)); | |
| 1964 if (!function.IsNull()) { | |
| 1965 Object& result = Object::Handle(isolate); | |
| 1966 Integer& intobj = Integer::Handle(isolate); | |
| 1967 for (int i = 0; i < length; i++) { | |
| 1968 intobj = Integer::New(offset + i); | |
| 1969 GrowableArray<const Object*> args(1); | |
| 1970 args.Add(&intobj); | |
| 1971 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 1972 result = DartEntry::InvokeDynamic( | |
| 1973 instance, function, args, kNoArgumentNames); | |
| 1974 if (result.IsError()) { | |
| 1975 return Api::NewHandle(isolate, result.raw()); | |
| 1976 } | |
| 1977 if (!result.IsInteger()) { | |
| 1978 return Api::NewError("%s expects the argument 'list' to be " | |
| 1979 "a List of int", CURRENT_FUNC); | |
| 1980 } | |
| 1981 const Integer& integer_result = Integer::Cast(result); | |
| 1982 ASSERT(integer_result.AsInt64Value() <= 0xff); | |
| 1983 // TODO(hpayer): value should always be smaller then 0xff. Add error | |
| 1984 // handling. | |
| 1985 native_array[i] = | |
| 1986 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); | |
| 1987 } | |
| 1988 return Api::Success(isolate); | |
| 1989 } | |
| 1990 } | |
| 1991 return Api::NewError("Object does not implement the 'List' interface"); | |
| 1992 } | 2003 } |
| 1993 | 2004 |
| 1994 | 2005 |
| 1995 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ | 2006 #define SET_LIST_ELEMENT_AS_BYTES(isolate, type, obj, native_array, offset, \ |
| 1996 length) \ | 2007 length) \ |
| 1997 const type& array = type::Cast(obj); \ | 2008 const type& array = type::Cast(obj); \ |
| 1998 Integer& integer = Integer::Handle(isolate); \ | 2009 Integer& integer = Integer::Handle(isolate); \ |
| 1999 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2010 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 2000 for (int i = 0; i < length; i++) { \ | 2011 for (int i = 0; i < length; i++) { \ |
| 2001 integer = Integer::New(native_array[i]); \ | 2012 integer = Integer::New(native_array[i]); \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2013 Isolate* isolate = Isolate::Current(); | 2024 Isolate* isolate = Isolate::Current(); |
| 2014 DARTSCOPE(isolate); | 2025 DARTSCOPE(isolate); |
| 2015 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2026 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 2016 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { | 2027 if (obj.IsUint8Array() || obj.IsExternalUint8Array()) { |
| 2017 const ByteArray& byte_array = ByteArray::Cast(obj); | 2028 const ByteArray& byte_array = ByteArray::Cast(obj); |
| 2018 if (Utils::RangeCheck(offset, length, byte_array.Length())) { | 2029 if (Utils::RangeCheck(offset, length, byte_array.Length())) { |
| 2019 ByteArray::Copy(byte_array, offset, native_array, length); | 2030 ByteArray::Copy(byte_array, offset, native_array, length); |
| 2020 return Api::Success(isolate); | 2031 return Api::Success(isolate); |
| 2021 } | 2032 } |
| 2022 return Api::NewError("Invalid length passed in to set list elements"); | 2033 return Api::NewError("Invalid length passed in to set list elements"); |
| 2023 } | 2034 } else if (obj.IsArray()) { |
| 2024 if (obj.IsArray()) { | |
| 2025 if (obj.IsImmutableArray()) { | 2035 if (obj.IsImmutableArray()) { |
| 2026 return Api::NewError("Cannot modify immutable array"); | 2036 return Api::NewError("Cannot modify immutable array"); |
| 2027 } | 2037 } |
| 2028 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2038 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2029 Array, | 2039 Array, |
| 2030 obj, | 2040 obj, |
| 2031 native_array, | 2041 native_array, |
| 2032 offset, | 2042 offset, |
| 2033 length); | 2043 length); |
| 2034 } | 2044 } else if (obj.IsGrowableObjectArray()) { |
| 2035 if (obj.IsGrowableObjectArray()) { | |
| 2036 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2045 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2037 GrowableObjectArray, | 2046 GrowableObjectArray, |
| 2038 obj, | 2047 obj, |
| 2039 native_array, | 2048 native_array, |
| 2040 offset, | 2049 offset, |
| 2041 length); | 2050 length); |
| 2051 } else if (obj.IsError()) { |
| 2052 return list; |
| 2053 } else { |
| 2054 // Check and handle a dart object that implements the List interface. |
| 2055 const Instance& instance = |
| 2056 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2057 if (!instance.IsNull()) { |
| 2058 String& name = String::Handle(isolate, String::New("[]=")); |
| 2059 const Function& function = |
| 2060 Function::Handle(isolate, |
| 2061 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 2062 if (!function.IsNull()) { |
| 2063 Integer& indexobj = Integer::Handle(isolate); |
| 2064 Integer& valueobj = Integer::Handle(isolate); |
| 2065 for (int i = 0; i < length; i++) { |
| 2066 indexobj = Integer::New(offset + i); |
| 2067 valueobj = Integer::New(native_array[i]); |
| 2068 GrowableArray<const Object*> args(2); |
| 2069 args.Add(&indexobj); |
| 2070 args.Add(&valueobj); |
| 2071 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 2072 const Object& result = Object::Handle( |
| 2073 isolate, |
| 2074 DartEntry::InvokeDynamic( |
| 2075 instance, function, args, kNoArgumentNames)); |
| 2076 if (result.IsError()) { |
| 2077 return Api::NewHandle(isolate, result.raw()); |
| 2078 } |
| 2079 } |
| 2080 return Api::Success(isolate); |
| 2081 } |
| 2082 } |
| 2083 return Api::NewError("Object does not implement the 'List' interface"); |
| 2042 } | 2084 } |
| 2043 // Now check and handle a dart object that implements the List interface. | |
| 2044 const Instance& instance = | |
| 2045 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
| 2046 if (!instance.IsNull()) { | |
| 2047 String& name = String::Handle(isolate, String::New("[]=")); | |
| 2048 const Function& function = | |
| 2049 Function::Handle(isolate, | |
| 2050 Resolver::ResolveDynamic(instance, name, 3, 0)); | |
| 2051 if (!function.IsNull()) { | |
| 2052 Integer& indexobj = Integer::Handle(isolate); | |
| 2053 Integer& valueobj = Integer::Handle(isolate); | |
| 2054 for (int i = 0; i < length; i++) { | |
| 2055 indexobj = Integer::New(offset + i); | |
| 2056 valueobj = Integer::New(native_array[i]); | |
| 2057 GrowableArray<const Object*> args(2); | |
| 2058 args.Add(&indexobj); | |
| 2059 args.Add(&valueobj); | |
| 2060 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2061 const Object& result = Object::Handle( | |
| 2062 isolate, | |
| 2063 DartEntry::InvokeDynamic( | |
| 2064 instance, function, args, kNoArgumentNames)); | |
| 2065 if (result.IsError()) { | |
| 2066 return Api::NewHandle(isolate, result.raw()); | |
| 2067 } | |
| 2068 } | |
| 2069 return Api::Success(isolate); | |
| 2070 } | |
| 2071 } | |
| 2072 return Api::NewError("Object does not implement the 'List' interface"); | |
| 2073 } | 2085 } |
| 2074 | 2086 |
| 2075 | 2087 |
| 2076 // --- Byte Arrays --- | 2088 // --- Byte Arrays --- |
| 2077 | 2089 |
| 2078 | 2090 |
| 2079 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { | 2091 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { |
| 2080 return RawObject::IsByteArrayClassId(Api::ClassId(object)); | 2092 return RawObject::IsByteArrayClassId(Api::ClassId(object)); |
| 2081 } | 2093 } |
| 2082 | 2094 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 Isolate* isolate = Isolate::Current(); | 2318 Isolate* isolate = Isolate::Current(); |
| 2307 DARTSCOPE(isolate); | 2319 DARTSCOPE(isolate); |
| 2308 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 2320 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 2309 return obj.IsClosure(); | 2321 return obj.IsClosure(); |
| 2310 } | 2322 } |
| 2311 | 2323 |
| 2312 | 2324 |
| 2313 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { | 2325 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { |
| 2314 Isolate* isolate = Isolate::Current(); | 2326 Isolate* isolate = Isolate::Current(); |
| 2315 DARTSCOPE(isolate); | 2327 DARTSCOPE(isolate); |
| 2316 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); | 2328 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure); |
| 2317 if (obj.IsNull()) { | 2329 if (closure_obj.IsNull()) { |
| 2318 return Api::NewError("Null object passed to Dart_ClosureFunction"); | 2330 RETURN_TYPE_ERROR(isolate, closure, Closure); |
| 2319 } | |
| 2320 if (!obj.IsClosure()) { | |
| 2321 return Api::NewError("Invalid closure passed to Dart_ClosureFunction"); | |
| 2322 } | 2331 } |
| 2323 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2332 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 2324 | 2333 |
| 2325 const Closure& closure_obj = Closure::Cast(obj); | |
| 2326 RawFunction* rf = closure_obj.function(); | 2334 RawFunction* rf = closure_obj.function(); |
| 2327 return Api::NewHandle(isolate, rf); | 2335 return Api::NewHandle(isolate, rf); |
| 2328 } | 2336 } |
| 2329 | 2337 |
| 2330 | 2338 |
| 2331 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 2339 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 2332 int number_of_arguments, | 2340 int number_of_arguments, |
| 2333 Dart_Handle* arguments) { | 2341 Dart_Handle* arguments) { |
| 2334 Isolate* isolate = Isolate::Current(); | 2342 Isolate* isolate = Isolate::Current(); |
| 2335 DARTSCOPE(isolate); | 2343 DARTSCOPE(isolate); |
| 2336 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); | 2344 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure); |
| 2337 if (obj.IsNull()) { | 2345 if (closure_obj.IsNull()) { |
| 2338 return Api::NewError("Null object passed in to invoke closure"); | 2346 RETURN_TYPE_ERROR(isolate, closure, Closure); |
| 2339 } | 2347 } |
| 2340 if (!obj.IsClosure()) { | 2348 if (number_of_arguments < 0) { |
| 2341 return Api::NewError("Invalid closure passed to invoke closure"); | 2349 return Api::NewError( |
| 2350 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 2351 CURRENT_FUNC); |
| 2342 } | 2352 } |
| 2343 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2353 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 2344 | 2354 |
| 2345 // Now try to invoke the closure. | 2355 // Now try to invoke the closure. |
| 2346 const Closure& closure_obj = Closure::Cast(obj); | |
| 2347 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 2356 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
| 2348 for (int i = 0; i < number_of_arguments; i++) { | 2357 for (int i = 0; i < number_of_arguments; i++) { |
| 2349 const Object& arg = | 2358 const Object& arg = |
| 2350 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2359 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
| 2360 if (!arg.IsNull() && !arg.IsInstance()) { |
| 2361 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); |
| 2362 } |
| 2351 dart_arguments.Add(&arg); | 2363 dart_arguments.Add(&arg); |
| 2352 } | 2364 } |
| 2353 const Array& kNoArgumentNames = Array::Handle(isolate); | 2365 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 2354 return Api::NewHandle( | 2366 return Api::NewHandle( |
| 2355 isolate, | 2367 isolate, |
| 2356 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); | 2368 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); |
| 2357 } | 2369 } |
| 2358 | 2370 |
| 2359 | 2371 |
| 2360 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { | 2372 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2398 if (obj.IsClass()) { | 2410 if (obj.IsClass()) { |
| 2399 return Class::Cast(obj).is_interface(); | 2411 return Class::Cast(obj).is_interface(); |
| 2400 } | 2412 } |
| 2401 return false; | 2413 return false; |
| 2402 } | 2414 } |
| 2403 | 2415 |
| 2404 | 2416 |
| 2405 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { | 2417 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { |
| 2406 Isolate* isolate = Isolate::Current(); | 2418 Isolate* isolate = Isolate::Current(); |
| 2407 DARTSCOPE(isolate); | 2419 DARTSCOPE(isolate); |
| 2408 const Class& cls = Class::Handle( | 2420 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); |
| 2409 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | |
| 2410 if (cls.IsNull()) { | 2421 if (cls.IsNull()) { |
| 2411 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2422 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2412 } | 2423 } |
| 2413 return Api::NewHandle(isolate, cls.UserVisibleName()); | 2424 return Api::NewHandle(isolate, cls.UserVisibleName()); |
| 2414 } | 2425 } |
| 2415 | 2426 |
| 2416 | 2427 |
| 2417 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { | 2428 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { |
| 2418 Isolate* isolate = Isolate::Current(); | 2429 Isolate* isolate = Isolate::Current(); |
| 2419 DARTSCOPE(isolate); | 2430 DARTSCOPE(isolate); |
| 2420 const Class& cls = Class::Handle( | 2431 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); |
| 2421 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | |
| 2422 if (cls.IsNull()) { | 2432 if (cls.IsNull()) { |
| 2423 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2433 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2424 } | 2434 } |
| 2425 | 2435 |
| 2426 #if defined(DEBUG) | 2436 #if defined(DEBUG) |
| 2427 const Library& lib = Library::Handle(cls.library()); | 2437 const Library& lib = Library::Handle(cls.library()); |
| 2428 if (lib.IsNull()) { | 2438 if (lib.IsNull()) { |
| 2429 ASSERT(cls.IsDynamicClass() || cls.IsVoidClass()); | 2439 ASSERT(cls.IsDynamicClass() || cls.IsVoidClass()); |
| 2430 } | 2440 } |
| 2431 #endif | 2441 #endif |
| 2432 | 2442 |
| 2433 return Api::NewHandle(isolate, cls.library()); | 2443 return Api::NewHandle(isolate, cls.library()); |
| 2434 } | 2444 } |
| 2435 | 2445 |
| 2436 | 2446 |
| 2437 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { | 2447 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { |
| 2438 Isolate* isolate = Isolate::Current(); | 2448 Isolate* isolate = Isolate::Current(); |
| 2439 DARTSCOPE(isolate); | 2449 DARTSCOPE(isolate); |
| 2440 const Class& cls = Class::Handle( | 2450 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); |
| 2441 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | |
| 2442 if (cls.IsNull()) { | 2451 if (cls.IsNull()) { |
| 2443 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2452 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2444 } | 2453 } |
| 2445 | 2454 |
| 2446 // Finalize all classes. | 2455 // Finalize all classes. |
| 2447 const char* msg = CheckIsolateState(isolate); | 2456 const char* msg = CheckIsolateState(isolate); |
| 2448 if (msg != NULL) { | 2457 if (msg != NULL) { |
| 2449 return Api::NewError(msg); | 2458 return Api::NewError(msg); |
| 2450 } | 2459 } |
| 2451 | 2460 |
| 2452 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { | 2461 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { |
| 2453 return Api::NewHandle(isolate, cls.FactoryClass()); | 2462 return Api::NewHandle(isolate, cls.FactoryClass()); |
| 2454 } | 2463 } |
| 2455 return Api::Null(isolate); | 2464 return Api::Null(isolate); |
| 2456 } | 2465 } |
| 2457 | 2466 |
| 2458 | 2467 |
| 2459 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, | 2468 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, |
| 2460 intptr_t* count) { | 2469 intptr_t* count) { |
| 2461 Isolate* isolate = Isolate::Current(); | 2470 Isolate* isolate = Isolate::Current(); |
| 2462 DARTSCOPE(isolate); | 2471 DARTSCOPE(isolate); |
| 2463 const Class& cls = Class::Handle( | 2472 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); |
| 2464 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | |
| 2465 if (cls.IsNull()) { | 2473 if (cls.IsNull()) { |
| 2466 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2474 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2467 } | 2475 } |
| 2468 | 2476 |
| 2469 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); | 2477 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); |
| 2470 if (interface_types.IsNull()) { | 2478 if (interface_types.IsNull()) { |
| 2471 *count = 0; | 2479 *count = 0; |
| 2472 } else { | 2480 } else { |
| 2473 *count = interface_types.Length(); | 2481 *count = interface_types.Length(); |
| 2474 } | 2482 } |
| 2475 return Api::Success(isolate); | 2483 return Api::Success(isolate); |
| 2476 } | 2484 } |
| 2477 | 2485 |
| 2478 | 2486 |
| 2479 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, | 2487 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, |
| 2480 intptr_t index) { | 2488 intptr_t index) { |
| 2481 Isolate* isolate = Isolate::Current(); | 2489 Isolate* isolate = Isolate::Current(); |
| 2482 DARTSCOPE(isolate); | 2490 DARTSCOPE(isolate); |
| 2483 const Class& cls = Class::Handle( | 2491 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); |
| 2484 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | |
| 2485 if (cls.IsNull()) { | 2492 if (cls.IsNull()) { |
| 2486 RETURN_TYPE_ERROR(isolate, clazz, Class); | 2493 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2487 } | 2494 } |
| 2488 | 2495 |
| 2489 // Finalize all classes. | 2496 // Finalize all classes. |
| 2490 const char* msg = CheckIsolateState(isolate); | 2497 const char* msg = CheckIsolateState(isolate); |
| 2491 if (msg != NULL) { | 2498 if (msg != NULL) { |
| 2492 return Api::NewError(msg); | 2499 return Api::NewError(msg); |
| 2493 } | 2500 } |
| 2494 | 2501 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2999 DARTSCOPE(isolate); | 3006 DARTSCOPE(isolate); |
| 3000 Object& result = Object::Handle(isolate); | 3007 Object& result = Object::Handle(isolate); |
| 3001 | 3008 |
| 3002 if (number_of_arguments < 0) { | 3009 if (number_of_arguments < 0) { |
| 3003 return Api::NewError( | 3010 return Api::NewError( |
| 3004 "%s expects argument 'number_of_arguments' to be non-negative.", | 3011 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3005 CURRENT_FUNC); | 3012 CURRENT_FUNC); |
| 3006 } | 3013 } |
| 3007 | 3014 |
| 3008 // Get the class to instantiate. | 3015 // Get the class to instantiate. |
| 3009 Class& cls = Class::Handle( | 3016 Class& cls = |
| 3010 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | 3017 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
| 3011 if (cls.IsNull()) { | 3018 if (cls.IsNull()) { |
| 3012 RETURN_TYPE_ERROR(isolate, clazz, Class); | 3019 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 3013 } | 3020 } |
| 3014 String& base_constructor_name = String::Handle(); | 3021 String& base_constructor_name = String::Handle(); |
| 3015 base_constructor_name = cls.Name(); | 3022 base_constructor_name = cls.Name(); |
| 3016 | 3023 |
| 3017 // And get the name of the constructor to invoke. | 3024 // And get the name of the constructor to invoke. |
| 3018 String& dot_name = String::Handle(isolate); | 3025 String& dot_name = String::Handle(isolate); |
| 3019 const Object& name_obj = | 3026 const Object& name_obj = |
| 3020 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 3027 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
| 3021 if (name_obj.IsNull()) { | 3028 if (name_obj.IsNull()) { |
| 3022 dot_name = Symbols::Dot(); | 3029 dot_name = Symbols::Dot(); |
| 3023 } else if (name_obj.IsString()) { | 3030 } else if (name_obj.IsString()) { |
| 3024 const String& dot = String::Handle(isolate, Symbols::Dot()); | 3031 const String& dot = String::Handle(isolate, Symbols::Dot()); |
| 3025 dot_name = String::Concat(dot, String::Cast(name_obj)); | 3032 dot_name = String::Concat(dot, String::Cast(name_obj)); |
| 3026 } else { | 3033 } else { |
| 3027 return Api::NewError( | 3034 RETURN_TYPE_ERROR(isolate, constructor_name, String); |
| 3028 "%s expects argument 'constructor_name' to be of type String.", | |
| 3029 CURRENT_FUNC); | |
| 3030 } | 3035 } |
| 3031 | |
| 3032 const char* msg = CheckIsolateState(isolate); | 3036 const char* msg = CheckIsolateState(isolate); |
| 3033 if (msg != NULL) { | 3037 if (msg != NULL) { |
| 3034 return Api::NewError(msg); | 3038 return Api::NewError(msg); |
| 3035 } | 3039 } |
| 3036 | 3040 |
| 3037 // Check for interfaces with default implementations. | 3041 // Check for interfaces with default implementations. |
| 3038 if (cls.is_interface()) { | 3042 if (cls.is_interface()) { |
| 3039 // Make sure that the constructor is found in the interface. | 3043 // Make sure that the constructor is found in the interface. |
| 3040 result = ResolveConstructor( | 3044 result = ResolveConstructor( |
| 3041 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); | 3045 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 const Array& kNoArgNames = Array::Handle(isolate); | 3374 const Array& kNoArgNames = Array::Handle(isolate); |
| 3371 return Api::NewHandle( | 3375 return Api::NewHandle( |
| 3372 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); | 3376 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); |
| 3373 } else if (!field.IsNull()) { | 3377 } else if (!field.IsNull()) { |
| 3374 return Api::NewHandle(isolate, field.value()); | 3378 return Api::NewHandle(isolate, field.value()); |
| 3375 } else { | 3379 } else { |
| 3376 return Api::NewError("%s: did not find top-level variable '%s'.", | 3380 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 3377 CURRENT_FUNC, field_name.ToCString()); | 3381 CURRENT_FUNC, field_name.ToCString()); |
| 3378 } | 3382 } |
| 3379 | 3383 |
| 3384 } else if (obj.IsError()) { |
| 3385 return container; |
| 3380 } else { | 3386 } else { |
| 3381 return Api::NewError( | 3387 return Api::NewError( |
| 3382 "%s expects argument 'container' to be an object, class, or library.", | 3388 "%s expects argument 'container' to be an object, class, or library.", |
| 3383 CURRENT_FUNC); | 3389 CURRENT_FUNC); |
| 3384 } | 3390 } |
| 3385 } | 3391 } |
| 3386 | 3392 |
| 3387 | 3393 |
| 3388 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 3394 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
| 3389 Dart_Handle name, | 3395 Dart_Handle name, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3511 CURRENT_FUNC, field_name.ToCString()); | 3517 CURRENT_FUNC, field_name.ToCString()); |
| 3512 } else { | 3518 } else { |
| 3513 field.set_value(value_instance); | 3519 field.set_value(value_instance); |
| 3514 return Api::Success(isolate); | 3520 return Api::Success(isolate); |
| 3515 } | 3521 } |
| 3516 } else { | 3522 } else { |
| 3517 return Api::NewError("%s: did not find top-level variable '%s'.", | 3523 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 3518 CURRENT_FUNC, field_name.ToCString()); | 3524 CURRENT_FUNC, field_name.ToCString()); |
| 3519 } | 3525 } |
| 3520 | 3526 |
| 3527 } else if (obj.IsError()) { |
| 3528 return container; |
| 3521 } else { | 3529 } else { |
| 3522 return Api::NewError( | 3530 return Api::NewError( |
| 3523 "%s expects argument 'container' to be an object, class, or library.", | 3531 "%s expects argument 'container' to be an object, class, or library.", |
| 3524 CURRENT_FUNC); | 3532 CURRENT_FUNC); |
| 3525 } | 3533 } |
| 3526 } | 3534 } |
| 3527 | 3535 |
| 3528 | 3536 |
| 3529 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 3537 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 3530 Dart_Handle name, | 3538 Dart_Handle name, |
| 3531 int field_count) { | 3539 int field_count) { |
| 3532 Isolate* isolate = Isolate::Current(); | 3540 Isolate* isolate = Isolate::Current(); |
| 3533 DARTSCOPE(isolate); | 3541 DARTSCOPE(isolate); |
| 3534 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 3542 const String& cls_name = Api::UnwrapStringHandle(isolate, name); |
| 3535 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 3543 if (cls_name.IsNull()) { |
| 3544 RETURN_TYPE_ERROR(isolate, name, String); |
| 3545 } |
| 3546 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3547 if (lib.IsNull()) { |
| 3548 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3549 } |
| 3550 if (field_count <= 0) { |
| 3536 return Api::NewError( | 3551 return Api::NewError( |
| 3537 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 3552 "Negative field_count passed to Dart_CreateNativeWrapperClass"); |
| 3538 } | 3553 } |
| 3539 String& cls_name = String::Handle(isolate); | 3554 |
| 3540 cls_name ^= param.raw(); | 3555 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); |
| 3541 cls_name = Symbols::New(cls_name); | |
| 3542 Library& lib = Library::Handle(isolate); | |
| 3543 lib ^= Api::UnwrapHandle(library); | |
| 3544 if (lib.IsNull()) { | |
| 3545 return Api::NewError( | |
| 3546 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | |
| 3547 } | |
| 3548 const Class& cls = Class::Handle( | 3556 const Class& cls = Class::Handle( |
| 3549 isolate, Class::NewNativeWrapper(lib, cls_name, field_count)); | 3557 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
| 3550 if (cls.IsNull()) { | 3558 if (cls.IsNull()) { |
| 3551 return Api::NewError( | 3559 return Api::NewError( |
| 3552 "Unable to create native wrapper class : already exists"); | 3560 "Unable to create native wrapper class : already exists"); |
| 3553 } | 3561 } |
| 3554 return Api::NewHandle(isolate, cls.raw()); | 3562 return Api::NewHandle(isolate, cls.raw()); |
| 3555 } | 3563 } |
| 3556 | 3564 |
| 3557 | 3565 |
| 3558 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 3566 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
| 3559 int* count) { | 3567 int* count) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3606 return Api::Success(isolate); | 3614 return Api::Success(isolate); |
| 3607 } | 3615 } |
| 3608 | 3616 |
| 3609 | 3617 |
| 3610 // --- Exceptions ---- | 3618 // --- Exceptions ---- |
| 3611 | 3619 |
| 3612 | 3620 |
| 3613 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 3621 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 3614 Isolate* isolate = Isolate::Current(); | 3622 Isolate* isolate = Isolate::Current(); |
| 3615 DARTSCOPE(isolate); | 3623 DARTSCOPE(isolate); |
| 3624 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3625 if (excp.IsNull()) { |
| 3626 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3627 } |
| 3616 if (isolate->top_exit_frame_info() == 0) { | 3628 if (isolate->top_exit_frame_info() == 0) { |
| 3617 // There are no dart frames on the stack so it would be illegal to | 3629 // There are no dart frames on the stack so it would be illegal to |
| 3618 // throw an exception here. | 3630 // throw an exception here. |
| 3619 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3631 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3620 } | 3632 } |
| 3621 const Instance& excp = | |
| 3622 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); | |
| 3623 // Unwind all the API scopes till the exit frame before throwing an | 3633 // Unwind all the API scopes till the exit frame before throwing an |
| 3624 // exception. | 3634 // exception. |
| 3625 ApiState* state = isolate->api_state(); | 3635 ApiState* state = isolate->api_state(); |
| 3626 ASSERT(state != NULL); | 3636 ASSERT(state != NULL); |
| 3627 state->UnwindScopes(isolate->top_exit_frame_info()); | 3637 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3628 Exceptions::Throw(excp); | 3638 Exceptions::Throw(excp); |
| 3629 return Api::NewError("Exception was not thrown, internal error"); | 3639 return Api::NewError("Exception was not thrown, internal error"); |
| 3630 } | 3640 } |
| 3631 | 3641 |
| 3632 | 3642 |
| 3633 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 3643 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 3634 Dart_Handle stacktrace) { | 3644 Dart_Handle stacktrace) { |
| 3635 Isolate* isolate = Isolate::Current(); | 3645 Isolate* isolate = Isolate::Current(); |
| 3636 CHECK_ISOLATE(isolate); | 3646 CHECK_ISOLATE(isolate); |
| 3647 DARTSCOPE(isolate); |
| 3648 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3649 if (excp.IsNull()) { |
| 3650 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3651 } |
| 3652 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); |
| 3653 if (stk.IsNull()) { |
| 3654 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); |
| 3655 } |
| 3637 if (isolate->top_exit_frame_info() == 0) { | 3656 if (isolate->top_exit_frame_info() == 0) { |
| 3638 // There are no dart frames on the stack so it would be illegal to | 3657 // There are no dart frames on the stack so it would be illegal to |
| 3639 // throw an exception here. | 3658 // throw an exception here. |
| 3640 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3659 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3641 } | 3660 } |
| 3642 DARTSCOPE(isolate); | |
| 3643 const Instance& excp = | |
| 3644 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); | |
| 3645 const Instance& stk = | |
| 3646 Instance::CheckedHandle(isolate, Api::UnwrapHandle(stacktrace)); | |
| 3647 // Unwind all the API scopes till the exit frame before throwing an | 3661 // Unwind all the API scopes till the exit frame before throwing an |
| 3648 // exception. | 3662 // exception. |
| 3649 ApiState* state = isolate->api_state(); | 3663 ApiState* state = isolate->api_state(); |
| 3650 ASSERT(state != NULL); | 3664 ASSERT(state != NULL); |
| 3651 state->UnwindScopes(isolate->top_exit_frame_info()); | 3665 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3652 Exceptions::ReThrow(excp, stk); | 3666 Exceptions::ReThrow(excp, stk); |
| 3653 return Api::NewError("Exception was not re thrown, internal error"); | 3667 return Api::NewError("Exception was not re thrown, internal error"); |
| 3654 } | 3668 } |
| 3655 | 3669 |
| 3656 | 3670 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4122 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4136 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
| 4123 Dart::set_perf_events_writer(function); | 4137 Dart::set_perf_events_writer(function); |
| 4124 } | 4138 } |
| 4125 | 4139 |
| 4126 | 4140 |
| 4127 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4141 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
| 4128 Dart::set_flow_graph_writer(function); | 4142 Dart::set_flow_graph_writer(function); |
| 4129 } | 4143 } |
| 4130 | 4144 |
| 4131 } // namespace dart | 4145 } // namespace dart |
| OLD | NEW |