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_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
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/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_message.h" | 10 #include "vm/dart_api_message.h" |
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 " var list = new List(kArrayLength);\n" | 1793 " var list = new List(kArrayLength);\n" |
1794 " for (var i = 0; i < kArrayLength; i++) list[i] = bigint;\n" | 1794 " for (var i = 0; i < kArrayLength; i++) list[i] = bigint;\n" |
1795 " return list;\n" | 1795 " return list;\n" |
1796 "}\n" | 1796 "}\n" |
1797 "getDoubleList() {\n" | 1797 "getDoubleList() {\n" |
1798 " var d = 3.14;\n" | 1798 " var d = 3.14;\n" |
1799 " var list = new List<double>(kArrayLength);\n" | 1799 " var list = new List<double>(kArrayLength);\n" |
1800 " for (var i = 0; i < kArrayLength; i++) list[i] = d;\n" | 1800 " for (var i = 0; i < kArrayLength; i++) list[i] = d;\n" |
1801 " return list;\n" | 1801 " return list;\n" |
1802 "}\n" | 1802 "}\n" |
1803 "getByteArrayList() {\n" | 1803 "getTypedDataList() {\n" |
1804 " var byte_array = new Uint8List(256);\n" | 1804 " var byte_array = new Uint8List(256);\n" |
1805 " var list = new List(kArrayLength);\n" | 1805 " var list = new List(kArrayLength);\n" |
1806 " for (var i = 0; i < kArrayLength; i++) list[i] = byte_array;\n" | 1806 " for (var i = 0; i < kArrayLength; i++) list[i] = byte_array;\n" |
1807 " return list;\n" | 1807 " return list;\n" |
1808 "}\n" | 1808 "}\n" |
| 1809 "getTypedDataViewList() {\n" |
| 1810 " var uint8_list = new Uint8List(256);\n" |
| 1811 " uint8_list[64] = 1;\n" |
| 1812 " var uint8_list_view =\n" |
| 1813 " new Uint8List.view(uint8_list.buffer, 64, 128);\n" |
| 1814 " var list = new List(kArrayLength);\n" |
| 1815 " for (var i = 0; i < kArrayLength; i++) list[i] = uint8_list_view;\n" |
| 1816 " return list;\n" |
| 1817 "}\n" |
1809 "getMixedList() {\n" | 1818 "getMixedList() {\n" |
1810 " var list = new List(kArrayLength);\n" | 1819 " var list = new List(kArrayLength);\n" |
1811 " for (var i = 0; i < kArrayLength; i++) {\n" | 1820 " for (var i = 0; i < kArrayLength; i++) {\n" |
1812 " list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n" | 1821 " list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n" |
1813 " }\n" | 1822 " }\n" |
1814 " return list;\n" | 1823 " return list;\n" |
1815 "}\n" | 1824 "}\n" |
1816 "getSelfRefList() {\n" | 1825 "getSelfRefList() {\n" |
1817 " var list = new List(kArrayLength);\n" | 1826 " var list = new List(kArrayLength);\n" |
1818 " for (var i = 0; i < kArrayLength; i++) {\n" | 1827 " for (var i = 0; i < kArrayLength; i++) {\n" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1892 EXPECT_EQ(Dart_CObject::kArray, root->type); |
1884 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1893 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1885 for (int i = 0; i < kArrayLength; i++) { | 1894 for (int i = 0; i < kArrayLength; i++) { |
1886 Dart_CObject* element = root->value.as_array.values[i]; | 1895 Dart_CObject* element = root->value.as_array.values[i]; |
1887 EXPECT_EQ(root->value.as_array.values[0], element); | 1896 EXPECT_EQ(root->value.as_array.values[0], element); |
1888 EXPECT_EQ(Dart_CObject::kDouble, element->type); | 1897 EXPECT_EQ(Dart_CObject::kDouble, element->type); |
1889 EXPECT_EQ(3.14, element->value.as_double); | 1898 EXPECT_EQ(3.14, element->value.as_double); |
1890 } | 1899 } |
1891 } | 1900 } |
1892 { | 1901 { |
1893 // Generate a list of doubles from Dart code. | 1902 // Generate a list of Uint8Lists from Dart code. |
1894 ApiNativeScope scope; | 1903 ApiNativeScope scope; |
1895 Dart_CObject* root = GetDeserializedDartMessage(lib, "getByteArrayList"); | 1904 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
1896 EXPECT_NOTNULL(root); | 1905 EXPECT_NOTNULL(root); |
1897 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1906 EXPECT_EQ(Dart_CObject::kArray, root->type); |
1898 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1907 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1899 for (int i = 0; i < kArrayLength; i++) { | 1908 for (int i = 0; i < kArrayLength; i++) { |
1900 Dart_CObject* element = root->value.as_array.values[i]; | 1909 Dart_CObject* element = root->value.as_array.values[i]; |
1901 EXPECT_EQ(root->value.as_array.values[0], element); | 1910 EXPECT_EQ(root->value.as_array.values[0], element); |
1902 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 1911 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); |
1903 EXPECT_EQ(256, element->value.as_byte_array.length); | 1912 EXPECT_EQ(256, element->value.as_byte_array.length); |
1904 } | 1913 } |
1905 } | 1914 } |
1906 { | 1915 { |
| 1916 // Generate a list of Uint8List views from Dart code. |
| 1917 ApiNativeScope scope; |
| 1918 Dart_CObject* root = |
| 1919 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
| 1920 EXPECT_NOTNULL(root); |
| 1921 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 1922 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1923 for (int i = 0; i < kArrayLength; i++) { |
| 1924 Dart_CObject* element = root->value.as_array.values[i]; |
| 1925 EXPECT_EQ(root->value.as_array.values[0], element); |
| 1926 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); |
| 1927 EXPECT_EQ(128, element->value.as_byte_array.length); |
| 1928 EXPECT_EQ(1, element->value.as_byte_array.values[0]); |
| 1929 EXPECT_EQ(0, element->value.as_byte_array.values[1]); |
| 1930 } |
| 1931 } |
| 1932 { |
1907 // Generate a list of objects of different types from Dart code. | 1933 // Generate a list of objects of different types from Dart code. |
1908 ApiNativeScope scope; | 1934 ApiNativeScope scope; |
1909 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 1935 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
1910 EXPECT_NOTNULL(root); | 1936 EXPECT_NOTNULL(root); |
1911 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1937 EXPECT_EQ(Dart_CObject::kArray, root->type); |
1912 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1938 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1913 for (int i = 0; i < kArrayLength; i++) { | 1939 for (int i = 0; i < kArrayLength; i++) { |
1914 Dart_CObject* element = root->value.as_array.values[i]; | 1940 Dart_CObject* element = root->value.as_array.values[i]; |
1915 if ((i % 2) == 0) { | 1941 if ((i % 2) == 0) { |
1916 EXPECT_EQ(root->value.as_array.values[0], element); | 1942 EXPECT_EQ(root->value.as_array.values[0], element); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 "}\n" | 1992 "}\n" |
1967 "getDoubleList() {\n" | 1993 "getDoubleList() {\n" |
1968 " var d = 3.14;\n" | 1994 " var d = 3.14;\n" |
1969 " var list = [3.14, 3.14, 3.14, 3.14, 3.14, 3.14];\n" | 1995 " var list = [3.14, 3.14, 3.14, 3.14, 3.14, 3.14];\n" |
1970 " list.add(3.14);;\n" | 1996 " list.add(3.14);;\n" |
1971 " list.add(3.14);;\n" | 1997 " list.add(3.14);;\n" |
1972 " list.add(3.14);;\n" | 1998 " list.add(3.14);;\n" |
1973 " list.add(3.14);;\n" | 1999 " list.add(3.14);;\n" |
1974 " return list;\n" | 2000 " return list;\n" |
1975 "}\n" | 2001 "}\n" |
1976 "getByteArrayList() {\n" | 2002 "getTypedDataList() {\n" |
1977 " var byte_array = new Uint8List(256);\n" | 2003 " var byte_array = new Uint8List(256);\n" |
1978 " var list = [];\n" | 2004 " var list = [];\n" |
1979 " for (var i = 0; i < kArrayLength; i++) {\n" | 2005 " for (var i = 0; i < kArrayLength; i++) {\n" |
1980 " list.add(byte_array);\n" | 2006 " list.add(byte_array);\n" |
1981 " }\n" | 2007 " }\n" |
1982 " return list;\n" | 2008 " return list;\n" |
1983 "}\n" | 2009 "}\n" |
| 2010 "getTypedDataViewList() {\n" |
| 2011 " var uint8_list = new Uint8List(256);\n" |
| 2012 " uint8_list[64] = 1;\n" |
| 2013 " var uint8_list_view =\n" |
| 2014 " new Uint8List.view(uint8_list.buffer, 64, 128);\n" |
| 2015 " var list = [];\n" |
| 2016 " for (var i = 0; i < kArrayLength; i++) {\n" |
| 2017 " list.add(uint8_list_view);\n" |
| 2018 " }\n" |
| 2019 " return list;\n" |
| 2020 "}\n" |
1984 "getMixedList() {\n" | 2021 "getMixedList() {\n" |
1985 " var list = [];\n" | 2022 " var list = [];\n" |
1986 " for (var i = 0; i < kArrayLength; i++) {\n" | 2023 " for (var i = 0; i < kArrayLength; i++) {\n" |
1987 " list.add(((i % 2) == 0) ? '.' : 2.72);\n" | 2024 " list.add(((i % 2) == 0) ? '.' : 2.72);\n" |
1988 " }\n" | 2025 " }\n" |
1989 " return list;\n" | 2026 " return list;\n" |
1990 "}\n" | 2027 "}\n" |
1991 "getSelfRefList() {\n" | 2028 "getSelfRefList() {\n" |
1992 " var list = [];\n" | 2029 " var list = [];\n" |
1993 " for (var i = 0; i < kArrayLength; i++) {\n" | 2030 " for (var i = 0; i < kArrayLength; i++) {\n" |
1994 " list.add(list);\n" | 2031 " list.add(list);\n" |
1995 " }\n" | 2032 " }\n" |
1996 " return list;\n" | 2033 " return list;\n" |
1997 "}\n"; | 2034 "}\n"; |
1998 | 2035 |
1999 TestCase::CreateTestIsolate(); | 2036 TestCase::CreateTestIsolate(); |
2000 Isolate* isolate = Isolate::Current(); | 2037 Isolate* isolate = Isolate::Current(); |
2001 EXPECT(isolate != NULL); | 2038 EXPECT(isolate != NULL); |
2002 Dart_EnterScope(); | 2039 Dart_EnterScope(); |
2003 | 2040 |
2004 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2041 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2005 EXPECT_VALID(lib); | 2042 EXPECT_VALID(lib); |
2006 | 2043 |
2007 { | 2044 { |
2008 DARTSCOPE(isolate); | 2045 DARTSCOPE(isolate); |
2009 | |
2010 { | 2046 { |
2011 // Generate a list of strings from Dart code. | 2047 // Generate a list of strings from Dart code. |
2012 ApiNativeScope scope; | 2048 ApiNativeScope scope; |
2013 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2049 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); |
2014 EXPECT_NOTNULL(root); | 2050 EXPECT_NOTNULL(root); |
2015 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2051 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2016 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2052 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2017 for (int i = 0; i < kArrayLength; i++) { | 2053 for (int i = 0; i < kArrayLength; i++) { |
2018 Dart_CObject* element = root->value.as_array.values[i]; | 2054 Dart_CObject* element = root->value.as_array.values[i]; |
2019 EXPECT_EQ(root->value.as_array.values[0], element); | 2055 EXPECT_EQ(root->value.as_array.values[0], element); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2094 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2059 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2095 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2060 for (int i = 0; i < kArrayLength; i++) { | 2096 for (int i = 0; i < kArrayLength; i++) { |
2061 Dart_CObject* element = root->value.as_array.values[i]; | 2097 Dart_CObject* element = root->value.as_array.values[i]; |
2062 EXPECT_EQ(root->value.as_array.values[0], element); | 2098 EXPECT_EQ(root->value.as_array.values[0], element); |
2063 EXPECT_EQ(Dart_CObject::kDouble, element->type); | 2099 EXPECT_EQ(Dart_CObject::kDouble, element->type); |
2064 EXPECT_EQ(3.14, element->value.as_double); | 2100 EXPECT_EQ(3.14, element->value.as_double); |
2065 } | 2101 } |
2066 } | 2102 } |
2067 { | 2103 { |
2068 // Generate a list of doubles from Dart code. | 2104 // Generate a list of Uint8Lists from Dart code. |
2069 ApiNativeScope scope; | 2105 ApiNativeScope scope; |
2070 Dart_CObject* root = GetDeserializedDartMessage(lib, "getByteArrayList"); | 2106 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
2071 EXPECT_NOTNULL(root); | 2107 EXPECT_NOTNULL(root); |
2072 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2108 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2073 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2109 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2074 for (int i = 0; i < kArrayLength; i++) { | 2110 for (int i = 0; i < kArrayLength; i++) { |
2075 Dart_CObject* element = root->value.as_array.values[i]; | 2111 Dart_CObject* element = root->value.as_array.values[i]; |
2076 EXPECT_EQ(root->value.as_array.values[0], element); | 2112 EXPECT_EQ(root->value.as_array.values[0], element); |
2077 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 2113 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); |
2078 EXPECT_EQ(256, element->value.as_byte_array.length); | 2114 EXPECT_EQ(256, element->value.as_byte_array.length); |
2079 } | 2115 } |
2080 } | 2116 } |
2081 { | 2117 { |
| 2118 // Generate a list of Uint8List views from Dart code. |
| 2119 ApiNativeScope scope; |
| 2120 Dart_CObject* root = |
| 2121 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
| 2122 EXPECT_NOTNULL(root); |
| 2123 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2124 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2125 for (int i = 0; i < kArrayLength; i++) { |
| 2126 Dart_CObject* element = root->value.as_array.values[i]; |
| 2127 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2128 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); |
| 2129 EXPECT_EQ(128, element->value.as_byte_array.length); |
| 2130 EXPECT_EQ(1, element->value.as_byte_array.values[0]); |
| 2131 EXPECT_EQ(0, element->value.as_byte_array.values[1]); |
| 2132 } |
| 2133 } |
| 2134 { |
2082 // Generate a list of objects of different types from Dart code. | 2135 // Generate a list of objects of different types from Dart code. |
2083 ApiNativeScope scope; | 2136 ApiNativeScope scope; |
2084 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2137 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
2085 EXPECT_NOTNULL(root); | 2138 EXPECT_NOTNULL(root); |
2086 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2139 EXPECT_EQ(Dart_CObject::kArray, root->type); |
2087 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2140 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2088 for (int i = 0; i < kArrayLength; i++) { | 2141 for (int i = 0; i < kArrayLength; i++) { |
2089 Dart_CObject* element = root->value.as_array.values[i]; | 2142 Dart_CObject* element = root->value.as_array.values[i]; |
2090 if ((i % 2) == 0) { | 2143 if ((i % 2) == 0) { |
2091 EXPECT_EQ(root->value.as_array.values[0], element); | 2144 EXPECT_EQ(root->value.as_array.values[0], element); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 EXPECT(Dart_ErrorHasException(result)); | 2263 EXPECT(Dart_ErrorHasException(result)); |
2211 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2264 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
2212 Dart_GetError(result)); | 2265 Dart_GetError(result)); |
2213 | 2266 |
2214 Dart_ExitScope(); | 2267 Dart_ExitScope(); |
2215 } | 2268 } |
2216 | 2269 |
2217 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2270 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
2218 | 2271 |
2219 } // namespace dart | 2272 } // namespace dart |
OLD | NEW |