Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: runtime/vm/isolate_reload_test.cc

Issue 2241603004: Reload: Don't crash when a tearoff adds arguments and is called with too few. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 "include/dart_tools_api.h" 6 #include "include/dart_tools_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 TestCase::SetReloadTestScript(kScript); // Root library does not change. 1828 TestCase::SetReloadTestScript(kScript); // Root library does not change.
1829 1829
1830 EXPECT_STREQ("5 No top-level setter 'y=' declared.", 1830 EXPECT_STREQ("5 No top-level setter 'y=' declared.",
1831 SimpleInvokeStr(lib, "main")); 1831 SimpleInvokeStr(lib, "main"));
1832 1832
1833 lib = TestCase::GetReloadErrorOrRootLibrary(); 1833 lib = TestCase::GetReloadErrorOrRootLibrary();
1834 EXPECT_VALID(lib); 1834 EXPECT_VALID(lib);
1835 } 1835 }
1836 1836
1837 1837
1838 TEST_CASE(IsolateReload_TearOff_AddArguments) {
1839 const char* kScript =
1840 "import 'test:isolate_reload_helper';\n"
1841 "class C {\n"
1842 " foo(x) => x;\n"
1843 "}\n"
1844 "invoke(f, a) {\n"
1845 " try {\n"
1846 " return f(a);\n"
1847 " } catch (e) {\n"
1848 " return e.toString().split('\\n').first;\n"
1849 " }\n"
1850 "}\n"
1851 "main() {\n"
1852 " var c = new C();\n"
1853 " var f = c#foo;\n"
1854 " var r1 = invoke(f, 1);\n"
1855 " reloadTest();\n"
1856 " var r2 = invoke(f, 1);\n"
1857 " return '$r1 $r2';\n"
1858 "}\n";
1859
1860 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1861 EXPECT_VALID(lib);
1862
1863 const char* kReloadScript =
1864 "import 'test:isolate_reload_helper';\n"
1865 "class C {\n"
1866 " foo(x, y, z) => x + y + z;\n"
1867 "}\n"
1868 "invoke(f, a) {\n"
1869 " try {\n"
1870 " return f(a);\n"
1871 " } catch (e) {\n"
1872 " return e.toString().split('\\n').first;\n"
1873 " }\n"
1874 "}\n"
1875 "main() {\n"
1876 " var c = new C();\n"
1877 " var f = c#foo;\n"
1878 " var r1 = invoke(f, 1);\n"
1879 " reloadTest();\n"
1880 " var r2 = invoke(f, 1);\n"
1881 " return '$r1 $r2';\n"
1882 "}\n";
1883
1884 TestCase::SetReloadTestScript(kReloadScript);
1885
1886 EXPECT_STREQ("1 Class 'C' has no instance method 'foo' with matching"
1887 " arguments.", SimpleInvokeStr(lib, "main"));
1888
1889 lib = TestCase::GetReloadErrorOrRootLibrary();
1890 EXPECT_VALID(lib);
1891 }
1892
1893
1894 TEST_CASE(IsolateReload_TearOff_AddArguments2) {
1895 const char* kScript =
1896 "import 'test:isolate_reload_helper';\n"
1897 "class C {\n"
1898 " static foo(x) => x;\n"
1899 "}\n"
1900 "invoke(f, a) {\n"
1901 " try {\n"
1902 " return f(a);\n"
1903 " } catch (e) {\n"
1904 " return e.toString().split('\\n').first;\n"
1905 " }\n"
1906 "}\n"
1907 "main() {\n"
1908 " var f = C#foo;\n"
1909 " var r1 = invoke(f, 1);\n"
1910 " reloadTest();\n"
1911 " var r2 = invoke(f, 1);\n"
1912 " return '$r1 $r2';\n"
1913 "}\n";
1914
1915 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1916 EXPECT_VALID(lib);
1917
1918 const char* kReloadScript =
1919 "import 'test:isolate_reload_helper';\n"
1920 "class C {\n"
1921 " static foo(x, y, z) => x + y + z;\n"
1922 "}\n"
1923 "invoke(f, a) {\n"
1924 " try {\n"
1925 " return f(a);\n"
1926 " } catch (e) {\n"
1927 " return e.toString().split('\\n').first;\n"
1928 " }\n"
1929 "}\n"
1930 "main() {\n"
1931 " var f = C#foo;\n"
1932 " var r1 = invoke(f, 1);\n"
1933 " reloadTest();\n"
1934 " var r2 = invoke(f, 1);\n"
1935 " return '$r1 $r2';\n"
1936 "}\n";
1937
1938 TestCase::SetReloadTestScript(kReloadScript);
1939
1940 EXPECT_STREQ("1 Closure call with mismatched arguments: function 'C.foo'",
1941 SimpleInvokeStr(lib, "main"));
1942
1943 lib = TestCase::GetReloadErrorOrRootLibrary();
1944 EXPECT_VALID(lib);
1945 }
1946
1947
1838 TEST_CASE(IsolateReload_EnumEquality) { 1948 TEST_CASE(IsolateReload_EnumEquality) {
1839 const char* kScript = 1949 const char* kScript =
1840 "enum Fruit {\n" 1950 "enum Fruit {\n"
1841 " Apple,\n" 1951 " Apple,\n"
1842 " Banana,\n" 1952 " Banana,\n"
1843 "}\n" 1953 "}\n"
1844 "var x;\n" 1954 "var x;\n"
1845 "main() {\n" 1955 "main() {\n"
1846 " x = Fruit.Banana;\n" 1956 " x = Fruit.Banana;\n"
1847 " return Fruit.Apple.toString();\n" 1957 " return Fruit.Apple.toString();\n"
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 EXPECT_VALID(lib); 2980 EXPECT_VALID(lib);
2871 Dart_SetFileModifiedCallback(NULL); 2981 Dart_SetFileModifiedCallback(NULL);
2872 2982
2873 // Modification of an exported library propagates. 2983 // Modification of an exported library propagates.
2874 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); 2984 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
2875 } 2985 }
2876 2986
2877 #endif // !PRODUCT 2987 #endif // !PRODUCT
2878 2988
2879 } // namespace dart 2989 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698