| 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 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/utils.h" | 7 #include "platform/utils.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_state.h" | 10 #include "vm/dart_api_state.h" |
| (...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); | 1796 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); |
| 1797 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 1797 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| 1798 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); | 1798 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); |
| 1799 Dart_ShutdownIsolate(); | 1799 Dart_ShutdownIsolate(); |
| 1800 } | 1800 } |
| 1801 | 1801 |
| 1802 | 1802 |
| 1803 // Only ia32 and x64 can run execution tests. | 1803 // Only ia32 and x64 can run execution tests. |
| 1804 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 1804 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 1805 | 1805 |
| 1806 |
| 1807 static void TestFieldOk(Dart_Handle container, |
| 1808 Dart_Handle name, |
| 1809 bool final, |
| 1810 const char* initial_value) { |
| 1811 Dart_Handle result; |
| 1812 |
| 1813 // Make sure we have the right initial value. |
| 1814 result = Dart_GetField(container, name); |
| 1815 EXPECT_VALID(result); |
| 1816 const char* value = ""; |
| 1817 EXPECT_VALID(Dart_StringToCString(result, &value)); |
| 1818 EXPECT_STREQ(initial_value, value); |
| 1819 |
| 1820 // Use a unique expected value. |
| 1821 static int counter = 0; |
| 1822 char buffer[256]; |
| 1823 OS::SNPrint(buffer, 256, "Expected%d", ++counter); |
| 1824 |
| 1825 // Try to change the field value. |
| 1826 result = Dart_SetField(container, name, Dart_NewString(buffer)); |
| 1827 if (final) { |
| 1828 EXPECT(Dart_IsError(result)); |
| 1829 } else { |
| 1830 EXPECT_VALID(result); |
| 1831 } |
| 1832 |
| 1833 // Make sure we have the right final value. |
| 1834 result = Dart_GetField(container, name); |
| 1835 EXPECT_VALID(result); |
| 1836 EXPECT_VALID(Dart_StringToCString(result, &value)); |
| 1837 if (final) { |
| 1838 EXPECT_STREQ(initial_value, value); |
| 1839 } else { |
| 1840 EXPECT_STREQ(buffer, value); |
| 1841 } |
| 1842 } |
| 1843 |
| 1844 |
| 1845 static void TestFieldNotFound(Dart_Handle container, |
| 1846 Dart_Handle name) { |
| 1847 EXPECT(Dart_IsError(Dart_GetField(container, name))); |
| 1848 EXPECT(Dart_IsError(Dart_SetField(container, name, Dart_Null()))); |
| 1849 } |
| 1850 |
| 1851 |
| 1806 TEST_CASE(FieldAccess) { | 1852 TEST_CASE(FieldAccess) { |
| 1807 const char* kScriptChars = | 1853 const char* kScriptChars = |
| 1854 "class BaseFields {\n" |
| 1855 " BaseFields()\n" |
| 1856 " : this.inherited_fld = 'inherited' {\n" |
| 1857 " }\n" |
| 1858 " var inherited_fld;\n" |
| 1859 " static var non_inherited_fld;\n" |
| 1860 "}\n" |
| 1861 "\n" |
| 1862 "class Fields extends BaseFields {\n" |
| 1863 " Fields()\n" |
| 1864 " : this.instance_fld = 'instance',\n" |
| 1865 " this._instance_fld = 'hidden instance',\n" |
| 1866 " this.final_instance_fld = 'final instance',\n" |
| 1867 " this._final_instance_fld = 'hidden final instance' {\n" |
| 1868 " instance_getset_fld = 'instance getset';\n" |
| 1869 " _instance_getset_fld = 'hidden instance getset';\n" |
| 1870 " }\n" |
| 1871 "\n" |
| 1872 " static Init() {\n" |
| 1873 " static_fld = 'static';\n" |
| 1874 " _static_fld = 'hidden static';\n" |
| 1875 " static_getset_fld = 'static getset';\n" |
| 1876 " _static_getset_fld = 'hidden static getset';\n" |
| 1877 " }\n" |
| 1878 "\n" |
| 1879 " var instance_fld;\n" |
| 1880 " var _instance_fld;\n" |
| 1881 " final final_instance_fld;\n" |
| 1882 " final _final_instance_fld;\n" |
| 1883 " static var static_fld;\n" |
| 1884 " static var _static_fld;\n" |
| 1885 " static final final_static_fld = 'final static';\n" |
| 1886 " static final _final_static_fld = 'hidden final static';\n" |
| 1887 "\n" |
| 1888 " get instance_getset_fld() { return _gs_fld1; }\n" |
| 1889 " void set instance_getset_fld(var value) { _gs_fld1 = value; }\n" |
| 1890 " get _instance_getset_fld() { return _gs_fld2; }\n" |
| 1891 " void set _instance_getset_fld(var value) { _gs_fld2 = value; }\n" |
| 1892 " var _gs_fld1;\n" |
| 1893 " var _gs_fld2;\n" |
| 1894 "\n" |
| 1895 " static get static_getset_fld() { return _gs_fld3; }\n" |
| 1896 " static void set static_getset_fld(var value) { _gs_fld3 = value; }\n" |
| 1897 " static get _static_getset_fld() { return _gs_fld4; }\n" |
| 1898 " static void set _static_getset_fld(var value) { _gs_fld4 = value; }\n" |
| 1899 " static var _gs_fld3;\n" |
| 1900 " static var _gs_fld4;\n" |
| 1901 "}\n" |
| 1902 "var top_fld;\n" |
| 1903 "var _top_fld;\n" |
| 1904 "final final_top_fld = 'final top';\n" |
| 1905 "final _final_top_fld = 'hidden final top';\n" |
| 1906 "\n" |
| 1907 "get top_getset_fld() { return _gs_fld5; }\n" |
| 1908 "void set top_getset_fld(var value) { _gs_fld5 = value; }\n" |
| 1909 "get _top_getset_fld() { return _gs_fld6; }\n" |
| 1910 "void set _top_getset_fld(var value) { _gs_fld6 = value; }\n" |
| 1911 "var _gs_fld5;\n" |
| 1912 "var _gs_fld6;\n" |
| 1913 "\n" |
| 1914 "Fields test() {\n" |
| 1915 " Fields.Init();\n" |
| 1916 " top_fld = 'top';\n" |
| 1917 " _top_fld = 'hidden top';\n" |
| 1918 " top_getset_fld = 'top getset';\n" |
| 1919 " _top_getset_fld = 'hidden top getset';\n" |
| 1920 " return new Fields();\n" |
| 1921 "}\n"; |
| 1922 |
| 1923 // Shared setup. |
| 1924 Dart_Handle result; |
| 1925 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1926 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); |
| 1927 EXPECT_VALID(cls); |
| 1928 Dart_Handle instance = Dart_InvokeStatic(lib, |
| 1929 Dart_Null(), |
| 1930 Dart_NewString("test"), |
| 1931 0, |
| 1932 NULL); |
| 1933 EXPECT_VALID(instance); |
| 1934 Dart_Handle name; |
| 1935 int64_t value = 0; |
| 1936 |
| 1937 // Instance field. |
| 1938 name = Dart_NewString("instance_fld"); |
| 1939 TestFieldNotFound(lib, name); |
| 1940 TestFieldNotFound(cls, name); |
| 1941 TestFieldOk(instance, name, false, "instance"); |
| 1942 |
| 1943 // Hidden instance field. |
| 1944 name = Dart_NewString("_instance_fld"); |
| 1945 TestFieldNotFound(lib, name); |
| 1946 TestFieldNotFound(cls, name); |
| 1947 TestFieldOk(instance, name, false, "hidden instance"); |
| 1948 |
| 1949 // Final instance field. |
| 1950 name = Dart_NewString("final_instance_fld"); |
| 1951 TestFieldNotFound(lib, name); |
| 1952 TestFieldNotFound(cls, name); |
| 1953 TestFieldOk(instance, name, true, "final instance"); |
| 1954 |
| 1955 // Hidden final instance field. |
| 1956 name = Dart_NewString("_final_instance_fld"); |
| 1957 TestFieldNotFound(lib, name); |
| 1958 TestFieldNotFound(cls, name); |
| 1959 TestFieldOk(instance, name, true, "hidden final instance"); |
| 1960 |
| 1961 // Inherited field. |
| 1962 name = Dart_NewString("inherited_fld"); |
| 1963 TestFieldNotFound(lib, name); |
| 1964 TestFieldNotFound(cls, name); |
| 1965 TestFieldOk(instance, name, false, "inherited"); |
| 1966 |
| 1967 // Instance get/set field. |
| 1968 name = Dart_NewString("instance_getset_fld"); |
| 1969 TestFieldNotFound(lib, name); |
| 1970 TestFieldNotFound(cls, name); |
| 1971 TestFieldOk(instance, name, false, "instance getset"); |
| 1972 |
| 1973 // Hidden instance get/set field. |
| 1974 name = Dart_NewString("_instance_getset_fld"); |
| 1975 TestFieldNotFound(lib, name); |
| 1976 TestFieldNotFound(cls, name); |
| 1977 TestFieldOk(instance, name, false, "hidden instance getset"); |
| 1978 |
| 1979 // Static field. |
| 1980 name = Dart_NewString("static_fld"); |
| 1981 TestFieldNotFound(lib, name); |
| 1982 TestFieldNotFound(instance, name); |
| 1983 TestFieldOk(cls, name, false, "static"); |
| 1984 |
| 1985 // Hidden static field. |
| 1986 name = Dart_NewString("_static_fld"); |
| 1987 TestFieldNotFound(lib, name); |
| 1988 TestFieldNotFound(instance, name); |
| 1989 TestFieldOk(cls, name, false, "hidden static"); |
| 1990 |
| 1991 // Static final field. |
| 1992 name = Dart_NewString("final_static_fld"); |
| 1993 TestFieldNotFound(lib, name); |
| 1994 TestFieldNotFound(instance, name); |
| 1995 TestFieldOk(cls, name, true, "final static"); |
| 1996 |
| 1997 // Hidden static final field. |
| 1998 name = Dart_NewString("_final_static_fld"); |
| 1999 TestFieldNotFound(lib, name); |
| 2000 TestFieldNotFound(instance, name); |
| 2001 TestFieldOk(cls, name, true, "hidden final static"); |
| 2002 |
| 2003 // Static non-inherited field. Not found at any level. |
| 2004 name = Dart_NewString("non_inherited_fld"); |
| 2005 TestFieldNotFound(lib, name); |
| 2006 TestFieldNotFound(instance, name); |
| 2007 TestFieldNotFound(cls, name); |
| 2008 |
| 2009 // Static get/set field. |
| 2010 name = Dart_NewString("static_getset_fld"); |
| 2011 TestFieldNotFound(lib, name); |
| 2012 TestFieldNotFound(instance, name); |
| 2013 TestFieldOk(cls, name, false, "static getset"); |
| 2014 |
| 2015 // Hidden static get/set field. |
| 2016 name = Dart_NewString("_static_getset_fld"); |
| 2017 TestFieldNotFound(lib, name); |
| 2018 TestFieldNotFound(instance, name); |
| 2019 TestFieldOk(cls, name, false, "hidden static getset"); |
| 2020 |
| 2021 // Top-Level field. |
| 2022 name = Dart_NewString("top_fld"); |
| 2023 TestFieldNotFound(cls, name); |
| 2024 TestFieldNotFound(instance, name); |
| 2025 TestFieldOk(lib, name, false, "top"); |
| 2026 |
| 2027 // Hidden top-level field. |
| 2028 name = Dart_NewString("_top_fld"); |
| 2029 TestFieldNotFound(cls, name); |
| 2030 TestFieldNotFound(instance, name); |
| 2031 TestFieldOk(lib, name, false, "hidden top"); |
| 2032 |
| 2033 // Top-Level final field. |
| 2034 name = Dart_NewString("final_top_fld"); |
| 2035 TestFieldNotFound(cls, name); |
| 2036 TestFieldNotFound(instance, name); |
| 2037 TestFieldOk(lib, name, true, "final top"); |
| 2038 |
| 2039 // Hidden top-level final field. |
| 2040 name = Dart_NewString("_final_top_fld"); |
| 2041 TestFieldNotFound(cls, name); |
| 2042 TestFieldNotFound(instance, name); |
| 2043 TestFieldOk(lib, name, true, "hidden final top"); |
| 2044 |
| 2045 // Top-Level get/set field. |
| 2046 name = Dart_NewString("top_getset_fld"); |
| 2047 TestFieldNotFound(cls, name); |
| 2048 TestFieldNotFound(instance, name); |
| 2049 TestFieldOk(lib, name, false, "top getset"); |
| 2050 |
| 2051 // Hidden top-level get/set field. |
| 2052 name = Dart_NewString("_top_getset_fld"); |
| 2053 TestFieldNotFound(cls, name); |
| 2054 TestFieldNotFound(instance, name); |
| 2055 TestFieldOk(lib, name, false, "hidden top getset"); |
| 2056 } |
| 2057 |
| 2058 |
| 2059 TEST_CASE(FieldAccessOld) { |
| 2060 const char* kScriptChars = |
| 1808 "class Fields {\n" | 2061 "class Fields {\n" |
| 1809 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" | 2062 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 1810 " int fld1;\n" | 2063 " int fld1;\n" |
| 1811 " final int fld2;\n" | 2064 " final int fld2;\n" |
| 1812 " static int fld3;\n" | 2065 " static int fld3;\n" |
| 1813 " static final int fld4 = 10;\n" | 2066 " static final int fld4 = 10;\n" |
| 1814 "}\n" | 2067 "}\n" |
| 1815 "class FieldsTest {\n" | 2068 "class FieldsTest {\n" |
| 1816 " static Fields testMain() {\n" | 2069 " static Fields testMain() {\n" |
| 1817 " Fields obj = new Fields(10, 20);\n" | 2070 " Fields obj = new Fields(10, 20);\n" |
| (...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4002 // We should have received the expected number of interrupts. | 4255 // We should have received the expected number of interrupts. |
| 4003 EXPECT_EQ(kInterruptCount, interrupt_count); | 4256 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 4004 | 4257 |
| 4005 // Give the spawned thread enough time to properly exit. | 4258 // Give the spawned thread enough time to properly exit. |
| 4006 Isolate::SetInterruptCallback(saved); | 4259 Isolate::SetInterruptCallback(saved); |
| 4007 } | 4260 } |
| 4008 | 4261 |
| 4009 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 4262 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 4010 | 4263 |
| 4011 } // namespace dart | 4264 } // namespace dart |
| OLD | NEW |