| OLD | NEW | 
|     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 1887 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1898   // the list of subclasses, which would be bad.  Make sure that |  1898   // the list of subclasses, which would be bad.  Make sure that | 
|  1899   // Iterator still has only one non-core subclass... |  1899   // Iterator still has only one non-core subclass... | 
|  1900   EXPECT_EQ(saved_subclass_count + 1, subclasses.Length()); |  1900   EXPECT_EQ(saved_subclass_count + 1, subclasses.Length()); | 
|  1901  |  1901  | 
|  1902   // ...and the non-core subclass is still named AIterator. |  1902   // ...and the non-core subclass is still named AIterator. | 
|  1903   new_subclass = subclasses.At(subclasses.Length() - 1); |  1903   new_subclass = subclasses.At(subclasses.Length() - 1); | 
|  1904   name = Class::Cast(new_subclass).Name(); |  1904   name = Class::Cast(new_subclass).Name(); | 
|  1905   EXPECT_STREQ("AIterator", name.ToCString()); |  1905   EXPECT_STREQ("AIterator", name.ToCString()); | 
|  1906 } |  1906 } | 
|  1907  |  1907  | 
 |  1908  | 
 |  1909 static bool NothingModifiedCallback(const char* url, int64_t since) { | 
 |  1910   return false; | 
 |  1911 } | 
 |  1912  | 
 |  1913  | 
 |  1914 TEST_CASE(IsolateReload_NoLibsModified) { | 
 |  1915   const char* kImportScript = | 
 |  1916       "importedFunc() => 'fancy';"; | 
 |  1917   TestCase::SetImportableTestLibScript(kImportScript); | 
 |  1918  | 
 |  1919   const char* kScript = | 
 |  1920       "import 'test:importable_lib';\n" | 
 |  1921       "main() {\n" | 
 |  1922       "  return importedFunc() + ' feast';\n" | 
 |  1923       "}\n"; | 
 |  1924  | 
 |  1925   Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
 |  1926   EXPECT_VALID(lib); | 
 |  1927   EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); | 
 |  1928  | 
 |  1929   const char* kReloadImportScript = | 
 |  1930       "importedFunc() => 'bossy';"; | 
 |  1931   TestCase::SetImportableTestLibScript(kReloadImportScript); | 
 |  1932  | 
 |  1933   const char* kReloadScript = | 
 |  1934       "import 'test:importable_lib';\n" | 
 |  1935       "main() {\n" | 
 |  1936       "  return importedFunc() + ' pants';\n" | 
 |  1937       "}\n"; | 
 |  1938  | 
 |  1939   Dart_SetFileModifiedCallback(&NothingModifiedCallback); | 
 |  1940   lib = TestCase::ReloadTestScript(kReloadScript); | 
 |  1941   EXPECT_VALID(lib); | 
 |  1942   Dart_SetFileModifiedCallback(NULL); | 
 |  1943  | 
 |  1944   // No reload occurred because no files were "modified". | 
 |  1945   EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); | 
 |  1946 } | 
 |  1947  | 
 |  1948  | 
 |  1949 static bool MainModifiedCallback(const char* url, int64_t since) { | 
 |  1950   if (strcmp(url, "test-lib") == 0) { | 
 |  1951     return true; | 
 |  1952   } | 
 |  1953   return false; | 
 |  1954 } | 
 |  1955  | 
 |  1956  | 
 |  1957 TEST_CASE(IsolateReload_MainLibModified) { | 
 |  1958   const char* kImportScript = | 
 |  1959       "importedFunc() => 'fancy';"; | 
 |  1960   TestCase::SetImportableTestLibScript(kImportScript); | 
 |  1961  | 
 |  1962   const char* kScript = | 
 |  1963       "import 'test:importable_lib';\n" | 
 |  1964       "main() {\n" | 
 |  1965       "  return importedFunc() + ' feast';\n" | 
 |  1966       "}\n"; | 
 |  1967  | 
 |  1968   Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
 |  1969   EXPECT_VALID(lib); | 
 |  1970   EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); | 
 |  1971  | 
 |  1972   const char* kReloadImportScript = | 
 |  1973       "importedFunc() => 'bossy';"; | 
 |  1974   TestCase::SetImportableTestLibScript(kReloadImportScript); | 
 |  1975  | 
 |  1976   const char* kReloadScript = | 
 |  1977       "import 'test:importable_lib';\n" | 
 |  1978       "main() {\n" | 
 |  1979       "  return importedFunc() + ' pants';\n" | 
 |  1980       "}\n"; | 
 |  1981  | 
 |  1982   Dart_SetFileModifiedCallback(&MainModifiedCallback); | 
 |  1983   lib = TestCase::ReloadTestScript(kReloadScript); | 
 |  1984   EXPECT_VALID(lib); | 
 |  1985   Dart_SetFileModifiedCallback(NULL); | 
 |  1986  | 
 |  1987   // Imported library is not reloaded. | 
 |  1988   EXPECT_STREQ("fancy pants", SimpleInvokeStr(lib, "main")); | 
 |  1989 } | 
 |  1990  | 
 |  1991  | 
 |  1992 static bool ImportModifiedCallback(const char* url, int64_t since) { | 
 |  1993   if (strcmp(url, "test:importable_lib") == 0) { | 
 |  1994     return true; | 
 |  1995   } | 
 |  1996   return false; | 
 |  1997 } | 
 |  1998  | 
 |  1999  | 
 |  2000 TEST_CASE(IsolateReload_ImportedLibModified) { | 
 |  2001   const char* kImportScript = | 
 |  2002       "importedFunc() => 'fancy';"; | 
 |  2003   TestCase::SetImportableTestLibScript(kImportScript); | 
 |  2004  | 
 |  2005   const char* kScript = | 
 |  2006       "import 'test:importable_lib';\n" | 
 |  2007       "main() {\n" | 
 |  2008       "  return importedFunc() + ' feast';\n" | 
 |  2009       "}\n"; | 
 |  2010  | 
 |  2011   Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
 |  2012   EXPECT_VALID(lib); | 
 |  2013   EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); | 
 |  2014  | 
 |  2015   const char* kReloadImportScript = | 
 |  2016       "importedFunc() => 'bossy';"; | 
 |  2017   TestCase::SetImportableTestLibScript(kReloadImportScript); | 
 |  2018  | 
 |  2019   const char* kReloadScript = | 
 |  2020       "import 'test:importable_lib';\n" | 
 |  2021       "main() {\n" | 
 |  2022       "  return importedFunc() + ' pants';\n" | 
 |  2023       "}\n"; | 
 |  2024  | 
 |  2025   Dart_SetFileModifiedCallback(&ImportModifiedCallback); | 
 |  2026   lib = TestCase::ReloadTestScript(kReloadScript); | 
 |  2027   EXPECT_VALID(lib); | 
 |  2028   Dart_SetFileModifiedCallback(NULL); | 
 |  2029  | 
 |  2030   // Modification of an imported library propagates to the importing library. | 
 |  2031   EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); | 
 |  2032 } | 
 |  2033  | 
 |  2034  | 
 |  2035 TEST_CASE(IsolateReload_PrefixImportedLibModified) { | 
 |  2036   const char* kImportScript = | 
 |  2037       "importedFunc() => 'fancy';"; | 
 |  2038   TestCase::SetImportableTestLibScript(kImportScript); | 
 |  2039  | 
 |  2040   const char* kScript = | 
 |  2041       "import 'test:importable_lib' as cobra;\n" | 
 |  2042       "main() {\n" | 
 |  2043       "  return cobra.importedFunc() + ' feast';\n" | 
 |  2044       "}\n"; | 
 |  2045  | 
 |  2046   Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 
 |  2047   EXPECT_VALID(lib); | 
 |  2048   EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); | 
 |  2049  | 
 |  2050   const char* kReloadImportScript = | 
 |  2051       "importedFunc() => 'bossy';"; | 
 |  2052   TestCase::SetImportableTestLibScript(kReloadImportScript); | 
 |  2053  | 
 |  2054   const char* kReloadScript = | 
 |  2055       "import 'test:importable_lib' as cobra;\n" | 
 |  2056       "main() {\n" | 
 |  2057       "  return cobra.importedFunc() + ' pants';\n" | 
 |  2058       "}\n"; | 
 |  2059  | 
 |  2060   Dart_SetFileModifiedCallback(&ImportModifiedCallback); | 
 |  2061   lib = TestCase::ReloadTestScript(kReloadScript); | 
 |  2062   EXPECT_VALID(lib); | 
 |  2063   Dart_SetFileModifiedCallback(NULL); | 
 |  2064  | 
 |  2065   // Modification of an prefix-imported library propagates to the | 
 |  2066   // importing library. | 
 |  2067   EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); | 
 |  2068 } | 
 |  2069  | 
|  1908 #endif  // !PRODUCT |  2070 #endif  // !PRODUCT | 
|  1909  |  2071  | 
|  1910 }  // namespace dart |  2072 }  // namespace dart | 
| OLD | NEW |