21#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
27 int64_t integer_result = 0;
30 return integer_result;
35 const char* result_str =
nullptr;
58 const char* kReloadScript =
70 const char* kScriptChars =
82 const char* kUpdatedScriptChars =
108 nullptr ,
true ,
true );
113 EXPECT_EQ(42,
value);
126 const uint8_t* kernel_buffer =
nullptr;
127 intptr_t kernel_buffer_size = 0;
131 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
134 EXPECT_NOTNULL(kernel_buffer);
142 EXPECT_EQ(24,
value);
145TEST_CASE(IsolateReload_KernelIncrementalCompileAppAndLib) {
149 "file:///test-app.dart",
150 "import 'test-lib.dart';\n"
152 " return WhatsTheMeaningOfAllThis();\n"
156 "file:///test-lib.dart",
157 "WhatsTheMeaningOfAllThis() {\n"
165 nullptr ,
true ,
true );
171 EXPECT_EQ(42,
value);
176 "file:///test-lib.dart",
177 "WhatsTheMeaningOfAllThis() {\n"
185 const uint8_t* kernel_buffer =
nullptr;
186 intptr_t kernel_buffer_size = 0;
188 "file:///test-app.dart",
190 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
193 EXPECT_NOTNULL(kernel_buffer);
201 EXPECT_EQ(24,
value);
204TEST_CASE(IsolateReload_KernelIncrementalCompileGenerics) {
208 "file:///test-app.dart",
209 "import 'test-lib.dart';\n"
211 " int balance() => 42;\n"
213 "class MyAccountState extends State<Account> {\n"
214 " MyAccountState(Account a): super(a) {}\n"
217 " return (new MyAccountState(new Account()))\n"
218 " .howAreTheThings().balance();\n"
222 "file:///test-lib.dart",
226 " T howAreTheThings() => t;\n"
233 nullptr ,
true ,
true );
239 EXPECT_EQ(42,
value);
244 "file:///test-app.dart",
245 "import 'test-lib.dart';\n"
247 " int balance() => 24;\n"
249 "class MyAccountState extends State<Account> {\n"
250 " MyAccountState(Account a): super(a) {}\n"
253 " return (new MyAccountState(new Account()))\n"
254 " .howAreTheThings().balance();\n"
259 const uint8_t* kernel_buffer =
nullptr;
260 intptr_t kernel_buffer_size = 0;
262 "file:///test-app.dart",
264 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
267 EXPECT_NOTNULL(kernel_buffer);
275 EXPECT_EQ(24,
value);
278TEST_CASE(IsolateReload_KernelIncrementalCompileBaseClass) {
280 const char* kSourceFile1 =
281 "class State<T, U> {\n"
285 " t = l[0] is T ? l[0] : null;\n"
286 " u = l[1] is U ? l[1] : null;\n"
291 "file:///test-app.dart",
292 "import 'test-util.dart';\n"
295 " return v == 42 ? 1 : v == null ? -1 : 0;\n"
299 "file:///test-lib.dart",
303 "file:///test-util.dart",
304 "import 'test-lib.dart';\n"
305 "class MyAccountState extends State<int, String> {\n"
306 " MyAccountState(List l): super(l) {}\n"
309 "doWork() => new MyAccountState(<dynamic>[42, 'abc']).first();\n"
316 nullptr ,
true ,
true );
324 const char* kUpdatedSourceFile =
325 "class State<U, T> {\n"
329 " t = l[0] is T ? l[0] : null;\n"
330 " u = l[1] is U ? l[1] : null;\n"
334 "file:///test-lib.dart",
338 const uint8_t* kernel_buffer =
nullptr;
339 intptr_t kernel_buffer_size = 0;
341 "file:///test-app.dart",
343 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
346 EXPECT_NOTNULL(kernel_buffer);
354 EXPECT_EQ(-1,
value);
358 const char* kScript =
372 const char* kReloadScript =
375 " final a kjsdf ksjdf ;\n"
389 const char* kScript =
390 "init() => 'old value';\n"
391 "var value = init();\n"
393 " return 'init()=${init()},value=${value}';\n"
398 EXPECT_STREQ(
"init()=old value,value=old value",
401 const char* kReloadScript =
403 "init() => 'new value';\n"
404 "var value = init();\n"
406 " return 'init()=${init()},value=${value}';\n"
411 EXPECT_STREQ(
"init()=new value,value=old value",
417 const char* kScript =
420 " return x + 'diluvian';\n"
424 " closure = () { return magic().toString() + '!'; };\n"
425 " return closure();\n"
435 const char* kReloadScript =
437 " return 'postapocalyptic';\n"
441 " return closure();\n"
450 const char* kScript =
453 " return 'value1=${value1}';\n"
460 const char* kReloadScript =
464 " return 'value1=${value1},value2=${value2}';\n"
473 const char* kScript =
486 const char* kReloadScript =
502 const char* kScript =
516 const char* kReloadScript =
533 const char* kScript =
547 const char* kReloadScript =
562 const char* kScript =
571 const char* kReloadScript =
574 " toString() => 'hello from A';\n"
577 " return new A().toString();\n"
586 const char* kScript =
588 " toString() => 'hello from A';\n"
590 "List<dynamic> list = <dynamic>[];"
592 " list.add(new A());\n"
593 " return list[0].toString();\n"
600 const char* kReloadScript =
601 "List<dynamic> list = <dynamic>[];\n"
603 " return list[0].toString();\n"
612 const char* kScript =
614 " return max(3, 4);\n"
617 const char* kReloadScript =
618 "import 'dart:math';\n"
620 " return max(3, 4);\n"
633 const char* kScript =
634 "import 'dart:math';\n"
636 " return max(3, 4);\n"
643 const char* kReloadScript =
645 " return max(3, 4);\n"
653 const char* kScript =
662 intptr_t lib_id = -1;
663 bool debuggable =
false;
666 EXPECT_EQ(
true, debuggable);
669 EXPECT_EQ(
false, debuggable);
673 const char* kReloadScript =
684 intptr_t new_lib_id = -1;
687 EXPECT_EQ(
false, debuggable);
694 const char* kScript =
698 "var savedA = new A();\n"
700 " var newA = new A();\n"
701 " return 'saved:${savedA.field} new:${newA.field}';\n"
708 const char* kReloadScript =
712 "var savedA = new A();\n"
714 " var newA = new A();\n"
715 " return 'saved:${savedA.field} new:${newA.field}';\n"
725 const char* kScript =
728 " A() { field = 20; }\n"
730 "var savedA = A();\n"
733 " return 'saved:${savedA.field} new:${newA.field}';\n"
742 const char* kReloadScript =
746 " A() { field = 10; }\n"
748 "var savedA = A();\n"
751 " return 'saved:${savedA.field} new:${newA.field}';\n"
761 const char* kScript =
764 "class B extends A {\n"
766 "var list = [ new A(), new B() ];\n"
768 " return (list.map((x) => '${x is A}/${x is B}')).toString();\n"
775 const char* kReloadScript =
779 "class A extends B {\n"
781 "var list = [ new A(), new B() ];\n"
783 " return (list.map((x) => '${x is A}/${x is B}')).toString();\n"
795 const char* kScript =
798 "class B<T extends A> {\n"
801 " return new B<A>().toString();\n"
808 const char* kReloadScript =
811 "class B<T extends A> {\n"
814 " return new B<A>().toString();\n"
823 const char* kScript =
824 "import 'file:///test:isolate_reload_helper';\n"
828 " var oldType = getType();\n"
830 " var newType = getType();\n"
831 " return identical(oldType, newType).toString();\n"
837 const char* kReloadScript =
838 "import 'file:///test:isolate_reload_helper';\n"
839 "class T extends Stopwatch { }\n"
842 " var oldType = getType();\n"
844 " var newType = getType();\n"
845 " return identical(oldType, newType).toString();\n"
854 const char* kScript =
855 "import 'file:///test:isolate_reload_helper';\n"
857 "getType() => new T<int>().runtimeType;\n"
859 " var oldType = getType();\n"
861 " var newType = getType();\n"
862 " return identical(oldType, newType).toString();\n"
868 const char* kReloadScript =
869 "import 'file:///test:isolate_reload_helper';\n"
870 "class T<G> extends Stopwatch { }\n"
871 "getType() => new T<int>().runtimeType;\n"
873 " var oldType = getType();\n"
875 " var newType = getType();\n"
876 " return identical(oldType, newType).toString();\n"
885 const char* kScript =
886 "import 'dart:mirrors';\n"
887 "import 'file:///test:isolate_reload_helper';\n"
889 "getTypeVar() => reflectType(T).typeVariables[0];\n"
891 " var oldType = getTypeVar();\n"
893 " var newType = getTypeVar();\n"
894 " return (oldType == newType).toString();\n"
900 const char* kReloadScript =
901 "import 'dart:mirrors';\n"
902 "import 'file:///test:isolate_reload_helper';\n"
903 "class T<G> extends Stopwatch { }\n"
904 "getTypeVar() => reflectType(T).typeVariables[0];\n"
906 " var oldType = getTypeVar();\n"
908 " var newType = getTypeVar();\n"
909 " return (oldType == newType).toString();\n"
918 const char* kScript =
920 " var field = 'mixin1';\n"
921 " func() => 'mixin1';\n"
923 "class B extends Object with Mixin1 {\n"
925 "var saved = new B();\n"
927 " return 'saved:field=${saved.field},func=${saved.func()}';\n"
932 EXPECT_STREQ(
"saved:field=mixin1,func=mixin1",
SimpleInvokeStr(lib,
"main"));
934 const char* kReloadScript =
936 " var field = 'mixin2';\n"
937 " func() => 'mixin2';\n"
939 "class B extends Object with Mixin2 {\n"
941 "var saved = new B();\n"
943 " var newer = new B();\n"
944 " return 'saved:field=${saved.field},func=${saved.func()} '\n"
945 " 'newer:field=${newer.field},func=${newer.func()}';\n"
954 "saved:field=mixin1,func=mixin2 "
955 "newer:field=mixin2,func=mixin2",
960 const char* kScript =
965 "class B extends A {\n"
966 " B(name) : super(name);\n"
968 "class C extends B {\n"
969 " C(name) : super(name);\n"
971 "var list = <dynamic>[ new A('a'), new B('b'), new C('c') ];\n"
973 " return (list.map((x) {\n"
974 " return '${x.name} is A(${x is A})/ B(${x is B})/ C(${x is C})';\n"
981 "(a is A(true)/ B(false)/ C(false),"
982 " b is A(true)/ B(true)/ C(false),"
983 " c is A(true)/ B(true)/ C(true))",
986 const char* kReloadScript =
991 "class X extends C {\n"
992 " X(name) : super(name);\n"
994 "class A extends X {\n"
995 " A(name) : super(name);\n"
999 " list.add(new X('x'));\n"
1000 " return (list.map((x) {\n"
1001 " return '${x.name} is A(${x is A})/ C(${x is C})/ X(${x is X})';\n"
1002 " })).toString();\n"
1008 "(a is A(true)/ C(true)/ X(true),"
1009 " b is A(true)/ C(true)/ X(true),"
1010 " c is A(false)/ C(true)/ X(false),"
1011 " x is A(false)/ C(true)/ X(true))",
1016 const char* kReloadScript2 =
1021 "class A extends X{\n"
1022 " A(name) : super(name);\n"
1024 "class B extends X {\n"
1025 " B(name) : super(name);\n"
1027 "class C extends A {\n"
1028 " C(name) : super(name);\n"
1032 " return (list.map((x) {\n"
1033 " return '${x.name} is '\n"
1034 " 'A(${x is A})/ B(${x is B})/ C(${x is C})/ X(${x is X})';\n"
1035 " })).toString();\n"
1041 "(a is A(true)/ B(false)/ C(false)/ X(true),"
1042 " b is A(false)/ B(true)/ C(false)/ X(true),"
1043 " c is A(true)/ B(false)/ C(true)/ X(true),"
1044 " x is A(false)/ B(false)/ C(false)/ X(true))",
1049 const char* kScript =
1050 "import 'file:///test:isolate_reload_helper';\n"
1052 "alpha() { var x = helper(); reloadTest(); return x + helper(); }\n"
1053 "foo() => alpha();\n"
1062 const char* kReloadScript =
1063 "import 'file:///test:isolate_reload_helper';\n"
1064 "helper() => 100;\n"
1065 "alpha() => 5 + helper();\n"
1066 "foo() => alpha();\n"
1082 const char* kImportScript =
"importedFunc() => 'a';\n";
1085 const char* kScript =
1098 const char* kReloadScript =
1099 "import 'test:lib1';\n"
1101 " return importedFunc();\n"
1123 const char* kImportScript =
"importedFunc() => 'a';\n";
1128 const char* kScript =
1129 "import 'test:lib1' hide importedFunc;\n"
1131 " return importedFunc();\n"
1141 const char* kReloadScript =
1142 "import 'test:lib1';\n"
1144 " return importedFunc();\n"
1153 const char* kImportScript =
1154 "importedFunc() => 'a';\n"
1155 "importedIntFunc() => 4;\n";
1160 const char* kScript =
1161 "import 'test:lib1' show importedIntFunc;\n"
1163 " return importedFunc();\n"
1166 " return importedIntFunc();\n"
1179 const char* kReloadScript =
1180 "import 'test:lib1' show importedFunc;\n"
1182 " return importedFunc();\n"
1185 " return importedIntFunc();\n"
1195 const char* kImportScript =
"importedIntFunc() => 4;\n";
1198 const char* kScript =
1199 "import 'file:///test:isolate_reload_helper';\n"
1200 "import 'test:lib1' show importedIntFunc;\n"
1202 " var x = importedIntFunc();\n"
1203 " var y = importedIntFunc();\n"
1220 const char* kImportScript =
1221 "mixin ImportedMixin {\n"
1222 " mixinFunc() => 'mixin';\n"
1226 const char* kScript =
1227 "import 'test:lib1' show ImportedMixin;\n"
1228 "class A extends Object with ImportedMixin {\n"
1230 "var func = new A().mixinFunc;\n"
1240 const char* kReloadScript =
1241 "import 'test:lib1' show ImportedMixin;\n"
1242 "class A extends Object with ImportedMixin {\n"
1255 const char* kScript =
1264 const char* kReloadScript =
1265 "kjsadkfjaksldfjklsadf;\n"
1272 "Variables must be declared using the keywords"
1273 " 'const', 'final', 'var' or a type name.");
1276TEST_CASE(IsolateReload_PendingUnqualifiedCall_StaticToInstance) {
1277 const char* kScript =
1278 "import 'file:///test:isolate_reload_helper';\n"
1280 " static foo() => 'static';\n"
1287 " return new C().test();\n"
1293 const char* kReloadScript =
1294 "import 'file:///test:isolate_reload_helper';\n"
1296 " foo() => 'instance';\n"
1303 " return new C().test();\n"
1308 const char* expected =
"instance";
1310 EXPECT_STREQ(expected,
result);
1313 if ((
result ==
nullptr) || (strcmp(expected,
result) != 0)) {
1322TEST_CASE(IsolateReload_PendingUnqualifiedCall_InstanceToStatic) {
1323 const char* kScript =
1324 "import 'file:///test:isolate_reload_helper';\n"
1326 " foo() => 'instance';\n"
1333 " return new C().test();\n"
1339 const char* kReloadScript =
1340 "import 'file:///test:isolate_reload_helper';\n"
1342 " static foo() => 'static';\n"
1349 " return new C().test();\n"
1353 const char* expected =
"static";
1360 EXPECT_STREQ(expected,
result);
1367TEST_CASE(IsolateReload_PendingConstructorCall_AbstractToConcrete) {
1368 const char* kScript =
1369 "import 'file:///test:isolate_reload_helper';\n"
1370 "abstract class Foo {}\n"
1378 " new C().test();\n"
1381 " return 'exception';\n"
1388 const char* kReloadScript =
1389 "import 'file:///test:isolate_reload_helper';\n"
1394 " return new Foo();\n"
1399 " new C().test();\n"
1402 " return 'exception';\n"
1408 const char* expected =
"okay";
1410 EXPECT_STREQ(expected,
result);
1413 if ((
result ==
nullptr) || (strcmp(expected,
result) != 0)) {
1422TEST_CASE(IsolateReload_PendingConstructorCall_ConcreteToAbstract) {
1423 const char* kScript =
1424 "import 'file:///test:isolate_reload_helper';\n"
1429 " return new Foo();\n"
1434 " new C().test();\n"
1437 " return 'exception';\n"
1444 const char* kReloadScript =
1445 "import 'file:///test:isolate_reload_helper';\n"
1446 "abstract class Foo {}\n"
1450 " return new Foo();\n"
1455 " new C().test();\n"
1458 " return 'exception';\n"
1467 const char* kScript =
1468 "import 'file:///test:isolate_reload_helper';\n"
1470 " static foo() => 'static';\n"
1473 " return C.foo();\n"
1478 " return new C().test();\n"
1480 " return 'exception';\n"
1487 const char* kReloadScript =
1488 "import 'file:///test:isolate_reload_helper';\n"
1492 " return C.foo();\n"
1497 " return new C().test();\n"
1499 " return 'exception';\n"
1504 const char* expected =
"exception";
1512 EXPECT_STREQ(expected,
result);
1520 const char* kScript =
1521 "import 'file:///test:isolate_reload_helper';\n"
1525 " return C.foo();\n"
1530 " return new C().test();\n"
1532 " return 'exception';\n"
1539 const char* kReloadScript =
1540 "import 'file:///test:isolate_reload_helper';\n"
1542 " static foo() => 'static';\n"
1545 " return C.foo();\n"
1550 " return new C().test();\n"
1552 " return 'exception';\n"
1558 const char* expected =
"static";
1565 EXPECT_STREQ(expected,
result);
1573 const char* kScript =
1574 "import 'file:///test:isolate_reload_helper';\n"
1578 "class C extends S {\n"
1581 " var n = super.foo();\n"
1583 " return n + super.foo();\n"
1587 " return new C().test();\n"
1593 const char* kReloadScript =
1594 "import 'file:///test:isolate_reload_helper';\n"
1598 "class C extends S {\n"
1601 " var n = super.foo();\n"
1603 " return n + super.foo();\n"
1607 " return new C().test();\n"
1616 const char* kScript =
1617 "import 'file:///test:isolate_reload_helper';\n"
1619 " foo() => 'old';\n"
1622 " var c = new C();\n"
1623 " var f1 = c.foo;\n"
1625 " var f2 = c.foo;\n"
1626 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1632 const char* kReloadScript =
1633 "import 'file:///test:isolate_reload_helper';\n"
1635 " foo() => 'new';\n"
1638 " var c = new C();\n"
1639 " var f1 = c.foo;\n"
1641 " var f2 = c.foo;\n"
1642 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1654 const char* kScript =
1655 "import 'file:///test:isolate_reload_helper';\n"
1657 " static foo() => 'old';\n"
1660 " var f1 = C.foo;\n"
1668 const char* kReloadScript =
1669 "import 'file:///test:isolate_reload_helper';\n"
1671 " static foo(i) => 'new:$i';\n"
1674 " var f1 = C.foo;\n"
1684 "/test-lib:8:12: Error: Too few positional"
1685 " arguments: 1 required, 0 given.\n"
1691 const char* kScript =
1692 "import 'file:///test:isolate_reload_helper';\n"
1694 " static foo({String bar = 'bar'}) => 'old';\n"
1697 " var f1 = C.foo;\n"
1701 " } catch(e) { return '$e'; }\n"
1707 const char* kReloadScript =
1708 "import 'file:///test:isolate_reload_helper';\n"
1716 " } catch(e) { return '$e'; }\n"
1722 "NoSuchMethodError: No static method 'foo' declared in class 'C'.",
1730 const char* kScript =
1731 "import 'file:///test:isolate_reload_helper';\n"
1733 " static foo() => 'old';\n"
1735 "getFoo() => C.foo;\n"
1737 " var f1 = getFoo();\n"
1739 " var f2 = getFoo();\n"
1740 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1746 const char* kReloadScript =
1747 "import 'file:///test:isolate_reload_helper';\n"
1749 " static foo() => 'new';\n"
1751 "getFoo() => C.foo;\n"
1753 " var f1 = getFoo();\n"
1755 " var f2 = getFoo();\n"
1756 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1768 const char* kScript =
1769 "import 'file:///test:isolate_reload_helper';\n"
1771 "getFoo() => foo;\n"
1773 " var f1 = getFoo();\n"
1775 " var f2 = getFoo();\n"
1776 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1782 const char* kReloadScript =
1783 "import 'file:///test:isolate_reload_helper';\n"
1785 "getFoo() => foo;\n"
1787 " var f1 = getFoo();\n"
1789 " var f2 = getFoo();\n"
1790 " return '${f1()} ${f2()} ${f1 == f2} ${identical(f1, f2)}';\n"
1802 const char* kScript =
1803 "import 'file:///test:isolate_reload_helper';\n"
1805 " foo() => 'old';\n"
1807 "List list = List<dynamic>.filled(2, null);\n"
1808 "Set set = Set();\n"
1811 " list[0] = c.foo;\n"
1812 " list[1] = c.foo;\n"
1813 " set.add(c.foo);\n"
1814 " set.add(c.foo);\n"
1815 " int countBefore = set.length;\n"
1817 " list[1] = c.foo;\n"
1818 " set.add(c.foo);\n"
1819 " set.add(c.foo);\n"
1820 " int countAfter = set.length;\n"
1821 " return '${list[0]()} ${list[1]()} ${list[0] == list[1]} '\n"
1822 " '${countBefore == 1} ${countAfter == 1} ${(set.first)()} '\n"
1823 " '${set.first == c.foo} ${set.first == c.foo} '\n"
1824 " '${set.remove(c.foo)}';\n"
1830 const char* kReloadScript =
1831 "import 'file:///test:isolate_reload_helper';\n"
1833 " foo() => 'new';\n"
1835 "List list = List<dynamic>.filled(2, null);\n"
1836 "Set set = Set();\n"
1839 " list[0] = c.foo;\n"
1840 " list[1] = c.foo;\n"
1841 " set.add(c.foo);\n"
1842 " set.add(c.foo);\n"
1843 " int countBefore = set.length;\n"
1845 " list[1] = c.foo;\n"
1846 " set.add(c.foo);\n"
1847 " set.add(c.foo);\n"
1848 " int countAfter = set.length;\n"
1849 " return '${list[0]()} ${list[1]()} ${list[0] == list[1]} '\n"
1850 " '${countBefore == 1} ${countAfter == 1} ${(set.first)()} '\n"
1851 " '${set.first == c.foo} ${set.first == c.foo} '\n"
1852 " '${set.remove(c.foo)}';\n"
1857 EXPECT_STREQ(
"new new true true true new true true true",
1865 const char* kScript =
1866 "import 'file:///test:isolate_reload_helper';\n"
1874 " return e.toString().split('\\n').first;\n"
1878 " var c = new C();\n"
1880 " var r1 = invoke(f, 1);\n"
1882 " var r2 = invoke(f, 1);\n"
1883 " return '$r1 $r2';\n"
1889 const char* kReloadScript =
1890 "import 'file:///test:isolate_reload_helper';\n"
1892 " foo(x, y, z) => x + y + z;\n"
1898 " return e.toString().split('\\n').first;\n"
1902 " var c = new C();\n"
1904 " var r1 = invoke(f, 1);\n"
1906 " var r2 = invoke(f, 1);\n"
1907 " return '$r1 $r2';\n"
1913 "1 NoSuchMethodError: Class 'C' has no instance method "
1914 "'foo' with matching arguments.",
1922 const char* kScript =
1923 "import 'file:///test:isolate_reload_helper';\n"
1925 " static foo(x) => x;\n"
1931 " return e.toString().split('\\n').first;\n"
1936 " var r1 = invoke(f, 1);\n"
1938 " var r2 = invoke(f, 1);\n"
1939 " return '$r1 $r2';\n"
1945 const char* kReloadScript =
1946 "import 'file:///test:isolate_reload_helper';\n"
1948 " static foo(x, y, z) => x + y + z;\n"
1954 " return e.toString().split('\\n').first;\n"
1959 " var r1 = invoke(f, 1);\n"
1961 " var r2 = invoke(f, 1);\n"
1962 " return '$r1 $r2';\n"
1968 "1 NoSuchMethodError: Closure call with mismatched arguments: "
1977 const char* kScript =
1984 " x = Fruit.Banana;\n"
1985 " return Fruit.Apple.toString();\n"
1993 const char* kReloadScript =
2000 " if (x == Fruit.Banana) {\n"
2013 const char* kScript =
2020 " x = Fruit.Banana;\n"
2021 " return Fruit.Apple.toString();\n"
2028 const char* kReloadScript =
2035 " if (identical(x, Fruit.Banana)) {\n"
2048 const char* kScript =
2055 " x = Fruit.Banana;\n"
2056 " return Fruit.Apple.toString();\n"
2063 const char* kReloadScript =
2070 " if (identical(x, Fruit.Banana)) {\n"
2083 const char* kScript =
2090 " return Fruit.Apple.toString();\n"
2097 const char* kReloadScript =
2105 " String r = '${Fruit.Apple.index}/${Fruit.Apple} ';\n"
2106 " r += '${Fruit.Cantaloupe.index}/${Fruit.Cantaloupe} ';\n"
2107 " r += '${Fruit.Banana.index}/${Fruit.Banana}';\n"
2113 EXPECT_STREQ(
"0/Fruit.Apple 1/Fruit.Cantaloupe 2/Fruit.Banana",
2118 const char* kScript =
2123 " return Fruit.Apple.toString();\n"
2130 const char* kReloadScript =
2132 " final int zero = 0;\n"
2135 " return new Fruit().zero.toString();\n"
2143 const char* kScript =
2145 " final int zero = 0;\n"
2148 " return new Fruit().zero.toString();\n"
2155 const char* kReloadScript =
2160 " return Fruit.Apple.toString();\n"
2168 const char* kScript =
2176 " x = Fruit.Cantaloupe;\n"
2177 " return Fruit.Apple.toString();\n"
2187 const char* kReloadScript =
2194 " String r = '$x ${x.hashCode is int} ${x.index}';\n"
2200 EXPECT_STREQ(
"Fruit.Deleted enum value from Fruit true -1",
2205 const char* kScript =
2216 " x = { Fruit.Apple: Fruit.Apple.index,\n"
2217 " Fruit.Banana: Fruit.Banana.index,\n"
2218 " Fruit.Cantaloupe: Fruit.Cantaloupe.index};\n"
2219 " y = Fruit.Apple;\n"
2220 " z = Fruit.Banana;\n"
2221 " w = Fruit.Cantaloupe;\n"
2222 " return Fruit.Apple.toString();\n"
2229 const char* kReloadScript =
2239 "bool identityCheck(Fruit f, int index) {\n"
2240 " return identical(Fruit.values[index], f);\n"
2244 " x.forEach((key, value) {\n"
2245 " r += '${identityCheck(key, value)} ';\n"
2247 " r += '${x[Fruit.Apple] == Fruit.Apple.index} ';\n"
2248 " r += '${x[Fruit.Banana] == Fruit.Banana.index} ';\n"
2249 " r += '${x[Fruit.Cantaloupe] == Fruit.Cantaloupe.index} ';\n"
2250 " r += '${identical(y, Fruit.values[x[Fruit.Apple]])} ';\n"
2251 " r += '${identical(z, Fruit.values[x[Fruit.Banana]])} ';\n"
2252 " r += '${identical(w, Fruit.values[x[Fruit.Cantaloupe]])} ';\n"
2258 EXPECT_STREQ(
"true true true true true true true true true ",
2263 const char* kScript =
2264 "enum Fruit { Apple, Banana }\n"
2267 " retained = Fruit.Apple;\n"
2268 " return retained.toString();\n"
2275 const char* kReloadScript =
2277 " Apple('Apple', 'A'),\n"
2278 " Banana('Banana', 'B');\n"
2279 " const Fruit(this.name, this.initial);\n"
2280 " final String name;\n"
2281 " final String initial;\n"
2285 " return retained.initial;\n"
2294 const char* kScript =
2295 "enum Fruit { Apple, Banana }\n"
2298 " retained = Fruit.Apple;\n"
2299 " return retained.toString();\n"
2306 const char* kReloadScript =
2308 " Apple('Apple', 'A'),\n"
2309 " Banana('Banana', 'B'),\n"
2310 " Cherry('Cherry', 'C');\n"
2311 " const Fruit(this.name, this.initial);\n"
2312 " final String name;\n"
2313 " final String initial;\n"
2317 " return Fruit.Cherry.initial;\n"
2326 const char* kScript =
2327 "enum Fruit { Apple, Banana }\n"
2330 " retained = Fruit.Banana;\n"
2331 " return retained.toString();\n"
2338 const char* kReloadScript =
2340 " Apple('Apple', 'A');\n"
2341 " const Fruit(this.name, this.initial);\n"
2342 " final String name;\n"
2343 " final String initial;\n"
2347 " return retained.toString();\n"
2352 EXPECT_STREQ(
"Fruit.Deleted enum value from Fruit",
2357 const char* kScript =
2360 " const Box(this.x);\n"
2363 " Apple('Apple', const Box('A')),\n"
2364 " Banana('Banana', const Box('B')),\n"
2365 " Cherry('Cherry', const Box('C')),\n"
2366 " Durian('Durian', const Box('D')),\n"
2367 " Elderberry('Elderberry', const Box('E')),\n"
2368 " Fig('Fig', const Box('F')),\n"
2369 " Grape('Grape', const Box('G')),\n"
2370 " Huckleberry('Huckleberry', const Box('H')),\n"
2371 " Jackfruit('Jackfruit', const Box('J'));\n"
2372 " const Fruit(this.name, this.initial);\n"
2373 " final String name;\n"
2374 " final Box initial;\n"
2378 " retained = Fruit.Apple;\n"
2379 " return retained.toString();\n"
2386 const char* kReloadScript =
2391 " const Box(this.x, this.y, this.z);\n"
2394 " Apple('Apple', const Box('A', 0, 0)),\n"
2395 " Banana('Banana', const Box('B', 0, 0)),\n"
2396 " Cherry('Cherry', const Box('C', 0, 0)),\n"
2397 " Durian('Durian', const Box('D', 0, 0)),\n"
2398 " Elderberry('Elderberry', const Box('E', 0, 0)),\n"
2399 " Fig('Fig', const Box('F', 0, 0)),\n"
2400 " Grape('Grape', const Box('G', 0, 0)),\n"
2401 " Huckleberry('Huckleberry', const Box('H', 0, 0)),\n"
2402 " Jackfruit('Jackfruit', const Box('J', 0, 0)),\n"
2403 " Lemon('Lemon', const Box('L', 0, 0));\n"
2404 " const Fruit(this.name, this.initial);\n"
2405 " final String name;\n"
2406 " final Box initial;\n"
2410 " return retained.toString();\n"
2419 const char* kScript =
2421 " final String name;\n"
2422 " const Fruit(this.name);\n"
2423 " String toString() => name;\n"
2427 " x = const Fruit('Pear');\n"
2428 " return x.toString();\n"
2435 const char* kReloadScript =
2437 " final String name;\n"
2438 " const Fruit(this.name);\n"
2439 " String toString() => name;\n"
2443 " if (identical(x, const Fruit('Pear'))) {\n"
2456 const char* kScript =
2457 "deleted() { return 'hello'; }\n"
2460 " retained = () => deleted();\n"
2461 " return retained();\n"
2468 const char* kReloadScript =
2472 " return retained();\n"
2474 " return e.toString();\n"
2481 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2482 EXPECT_SUBSTRING(
"deleted",
result);
2485TEST_CASE(IsolateReload_CallDeleted_TopLevelFunctionArityChange) {
2486 const char* kScript =
2487 "deleted() { return 'hello'; }\n"
2490 " retained = () => deleted();\n"
2491 " return retained();\n"
2498 const char* kReloadScript =
2499 "deleted(newParameter) { return 'hello'; }\n"
2503 " return retained();\n"
2505 " return e.toString();\n"
2512 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2513 EXPECT_SUBSTRING(
"deleted",
result);
2516TEST_CASE(IsolateReload_CallDeleted_TopLevelAddTypeArguments) {
2517 const char* kScript =
2518 "deleted() { return 'hello'; }\n"
2521 " retained = () => deleted();\n"
2522 " return retained();\n"
2529 const char* kReloadScript =
2530 "deleted<A, B, C>() { return 'hello'; }\n"
2534 " return retained();\n"
2536 " return e.toString();\n"
2545TEST_CASE(IsolateReload_CallDeleted_TopLevelRemoveTypeArguments) {
2546 const char* kScript =
2547 "deleted<A, B, C>() { return 'hello'; }\n"
2550 " retained = () => deleted<int, int, int>();\n"
2551 " return retained();\n"
2558 const char* kReloadScript =
2559 "deleted() { return 'hello'; }\n"
2563 " return retained();\n"
2565 " return e.toString();\n"
2572 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2573 EXPECT_SUBSTRING(
"deleted",
result);
2576TEST_CASE(IsolateReload_CallDeleted_TopLevelMissingPassingTypeArguments) {
2577 const char* kScript =
2578 "deleted<A, B, C>() { return 'hello'; }\n"
2581 " retained = () => deleted<int, int, int>();\n"
2582 " return retained();\n"
2589 const char* kReloadScript =
2593 " return retained();\n"
2595 " return e.toString();\n"
2602 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2603 EXPECT_SUBSTRING(
"deleted",
result);
2606TEST_CASE(IsolateReload_CallDeleted_TopLevelFunctionEvaluationOrder) {
2607 const char* kScript =
2608 "first(flag) { if (flag) throw 'first!'; }\n"
2609 "deleted(_) { return 'hello'; }\n"
2612 " retained = (bool flag) => deleted(first(flag));\n"
2613 " return retained(false);\n"
2620 const char* kReloadScript =
2621 "first(flag) { if (flag) throw 'first!'; }\n"
2625 " return retained(true);\n"
2627 " return e.toString();\n"
2634 EXPECT_STREQ(
"first!",
result);
2637TEST_CASE(IsolateReload_CallDeleted_TopLevelFunctionLibraryDeleted) {
2641 "file:///test-app.dart",
2643 "import 'test-lib.dart';\n"
2646 " retained = () => deleted();\n"
2647 " return retained();\n"
2651 "file:///test-lib.dart",
2653 "deleted() { return 'hello'; }\n",
2660 NULL ,
true ,
true );
2667 "file:///test-app.dart",
2672 " return retained();\n"
2674 " return e.toString();\n"
2681 const uint8_t* kernel_buffer = NULL;
2682 intptr_t kernel_buffer_size = 0;
2684 "file:///test-app.dart",
2686 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
2689 EXPECT_NOTNULL(kernel_buffer);
2694 EXPECT_STREQ(
result,
"hello");
2702 const char* kScript =
2703 "get deleted { return 'hello'; }\n"
2706 " retained = () => deleted;\n"
2707 " return retained();\n"
2714 const char* kReloadScript =
2718 " return retained();\n"
2720 " return e.toString();\n"
2727 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2728 EXPECT_SUBSTRING(
"deleted",
result);
2732 const char* kScript =
2733 "set deleted(x) {}\n"
2736 " retained = () => deleted = 'hello';\n"
2737 " return retained();\n"
2744 const char* kReloadScript =
2748 " return retained();\n"
2750 " return e.toString();\n"
2757 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2758 EXPECT_SUBSTRING(
"deleted",
result);
2761TEST_CASE(IsolateReload_CallDeleted_TopLevelSetterEvaluationOrder) {
2762 const char* kScript =
2763 "first(flag) { if (flag) throw 'first!'; return 'hello'; }\n"
2764 "set deleted(x) {}\n"
2767 " retained = (bool flag) => deleted = first(flag);\n"
2768 " return retained(false);\n"
2775 const char* kReloadScript =
2776 "first(flag) { if (flag) throw 'first!'; return 'hello'; }\n"
2780 " return retained(true);\n"
2782 " return e.toString();\n"
2789 EXPECT_STREQ(
"first!",
result);
2793 const char* kScript =
2794 "class C { static deleted() { return 'hello'; } }\n"
2797 " retained = () => C.deleted();\n"
2798 " return retained();\n"
2805 const char* kReloadScript =
2809 " return retained();\n"
2811 " return e.toString();\n"
2818 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2819 EXPECT_SUBSTRING(
"deleted",
result);
2822TEST_CASE(IsolateReload_CallDeleted_ClassFunctionArityChange) {
2823 const char* kScript =
2824 "class C { static deleted() { return 'hello'; } }\n"
2827 " retained = () => C.deleted();\n"
2828 " return retained();\n"
2835 const char* kReloadScript =
2836 "class C { static deleted(newParameter) { return 'hello'; } }\n"
2840 " return retained();\n"
2842 " return e.toString();\n"
2849 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2850 EXPECT_SUBSTRING(
"deleted",
result);
2853TEST_CASE(IsolateReload_CallDeleted_ClassFunctionEvaluationOrder) {
2854 const char* kScript =
2855 "first(flag) { if (flag) throw 'first!'; }\n"
2856 "class C { static deleted(_) { return 'hello'; } }\n"
2859 " retained = (bool flag) => C.deleted(first(flag));\n"
2860 " return retained(false);\n"
2867 const char* kReloadScript =
2868 "first(flag) { if (flag) throw 'first!'; }\n"
2873 " return retained(true);\n"
2875 " return e.toString();\n"
2882 EXPECT_STREQ(
"first!",
result);
2886 const char* kScript =
2887 "class C { static get deleted { return 'hello'; } }\n"
2890 " retained = () => C.deleted;\n"
2891 " return retained();\n"
2898 const char* kReloadScript =
2902 " return retained();\n"
2904 " return e.toString();\n"
2911 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2912 EXPECT_SUBSTRING(
"deleted",
result);
2916 const char* kScript =
2917 "class C { static set deleted(x) {}}\n"
2920 " retained = () => C.deleted = 'hello';\n"
2921 " return retained();\n"
2928 const char* kReloadScript =
2932 " return retained();\n"
2934 " return e.toString();\n"
2941 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
2942 EXPECT_SUBSTRING(
"deleted",
result);
2945TEST_CASE(IsolateReload_CallDeleted_ClassSetterEvaluationOrder) {
2946 const char* kScript =
2947 "first(flag) { if (flag) throw 'first!'; return 'hello'; }\n"
2948 "class C { static set deleted(x) {}}\n"
2951 " retained = (bool flag) => C.deleted = first(flag);\n"
2952 " return retained(false);\n"
2959 const char* kReloadScript =
2960 "first(flag) { if (flag) throw 'first!'; return 'hello'; }\n"
2964 " return retained(true);\n"
2966 " return e.toString();\n"
2973 EXPECT_STREQ(
"first!",
result);
2976TEST_CASE(IsolateReload_CallDeleted_ClassGenerativeConstructor) {
2977 const char* kScript =
2978 "class C { C.deleted(); }\n"
2981 " retained = () => C.deleted().toString();\n"
2982 " return retained();\n"
2989 const char* kReloadScript =
2994 " return retained();\n"
2996 " return e.toString();\n"
3003 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3004 EXPECT_SUBSTRING(
"deleted",
result);
3007TEST_CASE(IsolateReload_CallDeleted_ClassGenerativeConstructorArityChange) {
3008 const char* kScript =
3009 "class C { C.deleted(); }\n"
3012 " retained = () => C.deleted().toString();\n"
3013 " return retained();\n"
3020 const char* kReloadScript =
3021 "class C { C.deleted(newParameter); }\n"
3025 " return retained();\n"
3027 " return e.toString();\n"
3034 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3035 EXPECT_SUBSTRING(
"deleted",
result);
3038TEST_CASE(IsolateReload_CallDeleted_ClassGenerativeConstructorClassDeleted) {
3039 const char* kScript =
3040 "class C { C.deleted(); }\n"
3043 " retained = () => C.deleted().toString();\n"
3044 " return retained();\n"
3051 const char* kReloadScript =
3055 " return retained();\n"
3057 " return e.toString();\n"
3064 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3065 EXPECT_SUBSTRING(
"deleted",
result);
3068TEST_CASE(IsolateReload_CallDeleted_ClassFactoryConstructor) {
3069 const char* kScript =
3070 "class C { factory C.deleted() => new C(); C(); }\n"
3073 " retained = () => C.deleted().toString();\n"
3074 " return retained();\n"
3081 const char* kReloadScript =
3086 " return retained();\n"
3088 " return e.toString();\n"
3095 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3096 EXPECT_SUBSTRING(
"deleted",
result);
3099TEST_CASE(IsolateReload_CallDeleted_ClassFactoryConstructorArityChange) {
3100 const char* kScript =
3101 "class C { factory C.deleted() => new C(); C(); }\n"
3104 " retained = () => C.deleted().toString();\n"
3105 " return retained();\n"
3112 const char* kReloadScript =
3113 "class C { factory C.deleted(newParameter) => new C(); C(); }\n"
3117 " return retained();\n"
3119 " return e.toString();\n"
3126 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3127 EXPECT_SUBSTRING(
"deleted",
result);
3130TEST_CASE(IsolateReload_CallDeleted_ClassFactoryConstructorClassDeleted) {
3131 const char* kScript =
3132 "class C { factory C.deleted() => new C(); C(); }\n"
3135 " retained = () => C.deleted().toString();\n"
3136 " return retained();\n"
3143 const char* kReloadScript =
3147 " return retained();\n"
3149 " return e.toString();\n"
3156 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3157 EXPECT_SUBSTRING(
"deleted",
result);
3161 const char* kScript =
3162 "class C { deleted() { return 'hello'; } }\n"
3163 "class D extends C { curry() => () => super.deleted(); }\n"
3166 " retained = new D().curry();\n"
3167 " return retained();\n"
3174 const char* kReloadScript =
3176 "class D extends C {}\n"
3180 " return retained();\n"
3182 " return e.toString();\n"
3189 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3190 EXPECT_SUBSTRING(
"deleted",
result);
3193TEST_CASE(IsolateReload_CallDeleted_SuperFunctionArityChange) {
3194 const char* kScript =
3195 "class C { deleted() { return 'hello'; } }\n"
3196 "class D extends C { curry() => () => super.deleted(); }\n"
3199 " retained = new D().curry();\n"
3200 " return retained();\n"
3207 const char* kReloadScript =
3208 "class C { deleted(newParameter) { return 'hello'; } }\n"
3209 "class D extends C {}\n"
3213 " return retained();\n"
3215 " return e.toString();\n"
3222 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3223 EXPECT_SUBSTRING(
"deleted",
result);
3227 const char* kScript =
3228 "class C { get deleted { return 'hello'; } }\n"
3229 "class D extends C { curry() => () => super.deleted; }\n"
3232 " retained = new D().curry();\n"
3233 " return retained();\n"
3240 const char* kReloadScript =
3242 "class D extends C {}\n"
3246 " return retained();\n"
3248 " return e.toString();\n"
3255 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3256 EXPECT_SUBSTRING(
"deleted",
result);
3260 const char* kScript =
3261 "class C { set deleted(x) {} }\n"
3262 "class D extends C { curry() => () => super.deleted = 'hello'; }\n"
3265 " retained = new D().curry();\n"
3266 " return retained();\n"
3273 const char* kReloadScript =
3275 "class D extends C {}\n"
3279 " return retained();\n"
3281 " return e.toString();\n"
3288 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3289 EXPECT_SUBSTRING(
"deleted",
result);
3293 const char* kScript =
3294 "class C { var deleted = 'hello'; }\n"
3295 "class D extends C { curry() => () => super.deleted; }\n"
3298 " retained = new D().curry();\n"
3299 " return retained();\n"
3306 const char* kReloadScript =
3308 "class D extends C {}\n"
3312 " return retained();\n"
3314 " return e.toString();\n"
3321 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3322 EXPECT_SUBSTRING(
"deleted",
result);
3326 const char* kScript =
3327 "class C { var deleted; }\n"
3328 "class D extends C { curry() => () => super.deleted = 'hello'; }\n"
3331 " retained = new D().curry();\n"
3332 " return retained();\n"
3339 const char* kReloadScript =
3341 "class D extends C {}\n"
3345 " return retained();\n"
3347 " return e.toString();\n"
3354 EXPECT_SUBSTRING(
"NoSuchMethodError",
result);
3355 EXPECT_SUBSTRING(
"deleted",
result);
3359 const char* kScript =
3367 " r += Fruit.Apple.toString();\n"
3369 " r += Fruit.Banana.toString();\n"
3375 EXPECT_STREQ(
"Fruit.Apple Fruit.Banana",
SimpleInvokeStr(lib,
"main"));
3379 const char* kReloadScript =
3388 " r += Fruit.Apple.toString();\n"
3390 " r += Fruit.Cantaloupe.toString();\n"
3392 " r += Fruit.Banana.toString();\n"
3398 EXPECT_STREQ(
"Fruit.Apple Fruit.Cantaloupe Fruit.Banana",
3415 intptr_t saved_subclass_count = subclasses.IsNull() ? 0 : subclasses.Length();
3417 const char* kScript =
3418 "class AStopwatch extends Stopwatch {\n"
3421 " new AStopwatch();\n"
3434 EXPECT_EQ(saved_subclass_count + 1, subclasses.Length());
3437 new_subclass = subclasses.At(subclasses.Length() - 1);
3438 name = Class::Cast(new_subclass).Name();
3439 EXPECT_STREQ(
"AStopwatch",
name.ToCString());
3441 const char* kReloadScript =
3442 "class AStopwatch {\n"
3444 "class BStopwatch extends Stopwatch {\n"
3447 " new AStopwatch();\n"
3448 " new BStopwatch();\n"
3461 EXPECT_EQ(saved_subclass_count + 1, subclasses.Length());
3464 new_subclass = subclasses.At(subclasses.Length() - 1);
3465 name = Class::Cast(new_subclass).Name();
3466 EXPECT_STREQ(
"BStopwatch",
name.ToCString());
3482 intptr_t saved_subclass_count = subclasses.IsNull() ? 0 : subclasses.Length();
3484 const char* kScript =
3485 "class AStopwatch extends Stopwatch {\n"
3488 " new AStopwatch();\n"
3501 EXPECT_EQ(saved_subclass_count + 1, subclasses.Length());
3504 new_subclass = subclasses.At(subclasses.Length() - 1);
3505 name = Class::Cast(new_subclass).Name();
3506 EXPECT_STREQ(
"AStopwatch",
name.ToCString());
3508 const char* kReloadScript =
3509 "class BStopwatch extends Stopwatch {\n"
3512 " new BStopwatch();\n"
3525 EXPECT_EQ(saved_subclass_count + 2, subclasses.Length());
3528 new_subclass = subclasses.At(subclasses.Length() - 2);
3529 name = Class::Cast(new_subclass).Name();
3530 EXPECT_STREQ(
"AStopwatch",
name.ToCString());
3532 new_subclass = subclasses.At(subclasses.Length() - 1);
3533 name = Class::Cast(new_subclass).Name();
3534 EXPECT_STREQ(
"BStopwatch",
name.ToCString());
3551 intptr_t saved_subclass_count = subclasses.IsNull() ? 0 : subclasses.Length();
3553 const char* kScript =
3554 "class AStopwatch extends Stopwatch {\n"
3561 " new AStopwatch();\n"
3575 EXPECT_EQ(saved_subclass_count + 1, subclasses.Length());
3579 new_subclass = subclasses.At(subclasses.Length() - 1);
3580 name = Class::Cast(new_subclass).Name();
3581 EXPECT_STREQ(
"AStopwatch",
name.ToCString());
3584 const char* kReloadScript =
3585 "class BStopwatch extends Stopwatch {\n"
3588 " final a kjsdf ksjdf ;\n"
3592 " new BStopwatch();\n"
3607 EXPECT_EQ(saved_subclass_count + 1, subclasses.Length());
3610 new_subclass = subclasses.At(subclasses.Length() - 1);
3611 name = Class::Cast(new_subclass).Name();
3612 EXPECT_STREQ(
"AStopwatch",
name.ToCString());
3619 const char* kScript =
3636 const char* kReloadScript =
3654 const char* kScript =
3667 const char* kReloadScript =
3673 " return (f.c == null) ? 42: 21;\n"
3685 const char* kScript =
3700 const char* kReloadScript =
3721 const char* kScript =
3722 "class Foo<A,B> {\n"
3742 const char* kReloadScript =
3743 "class Foo<A,B> {\n"
3761 const char* kScript =
3765 "class Foo extends Bar{\n"
3780 const char* kReloadScript =
3798 const char* kScript =
3803 "class Foo extends Bar{\n"
3817 const char* kReloadScript =
3821 "class Foo extends Bar {\n"
3837 const char* kScript =
3838 "class Foo<A, B> {\n"
3851 const char* kReloadScript =
3864 const char* kScript =
3865 "class Foo<A, B> {\n"
3873 const char* kReloadScript =
3884 const char* kScript =
3889 " var x, y, z, w;\n"
3895 " return '$a $b';\n"
3900 EXPECT_STREQ(
"Instance of 'A' Instance of 'B'",
SimpleInvokeStr(lib,
"main"));
3902 const char* kReloadScript =
3907 " var x, y, z, w, v;\n"
3911 " return '$a $b';\n"
3916 EXPECT_STREQ(
"Instance of 'A' Instance of 'B'",
SimpleInvokeStr(lib,
"main"));
3923 const char* kScript =
3927 "class Bar<B, C> extends Foo<B> {}\n"
3928 "class Baz extends Foo<String> {}"
3938 const char* kReloadScript =
3942 "class Bar<B, C> extends Foo<B> {}\n"
3943 "class Baz extends Bar<String, double> {}"
3953 const char* kScript =
3956 " get yourself => this;\n"
3961 " retained1 = new A();\n"
3962 " retained2 = new A();\n"
3963 " retained1.x = retained2;\n"
3964 " retained2.x = retained1;\n"
3965 " return '${identical(retained1.x.yourself, retained2)}'\n"
3966 " '${identical(retained2.x.yourself, retained1)}';\n"
3973 const char* kReloadScript =
3979 " get yourself => this;\n"
3984 " return '${identical(retained1.x.yourself, retained2)}'\n"
3985 " '${identical(retained2.x.yourself, retained1)}';\n"
3994 const char* kScript =
3998 "var a, hash1, hash2;\n"
4001 " hash1 = a.hashCode;\n"
4009 const char* kReloadScript =
4013 "var a, hash1, hash2;\n"
4015 " hash2 = a.hashCode;\n"
4016 " return (hash1 == hash2).toString();\n"
4025 const char* kScript =
4028 " const A(this.x);\n"
4030 "var a, hash1, hash2;\n"
4032 " a = const A(1);\n"
4033 " hash1 = a.hashCode;\n"
4041 const char* kReloadScript =
4044 " const A(this.x, this.y, this.z);\n"
4046 "var a, hash1, hash2;\n"
4048 " hash2 = a.hashCode;\n"
4049 " return (hash1 == hash2).toString();\n"
4065 const char* kScript = R
"(
4066 import 'file:///test:isolate_reload_helper';
4083 const char* kReloadScript = R
"(
4084 import 'file:///test:isolate_reload_helper';
4087 const A(this.x, this.y, this.z);
4091 a = const A(1, null, null);
4101 const char* kReloadScript2 = R
"(
4102 import 'file:///test:isolate_reload_helper';
4104 final x, y, z, w, u;
4105 const A(this.x, this.y, this.z, this.w, this.u);
4109 a = const A(1, null, null, null, null);
4121 const char* kScript = R
"(
4122 import 'file:///test:isolate_reload_helper';
4125 const A(this.x, this.y, this.z);
4129 a = const A(1, 2, 3);
4139 const char* kReloadScript = R
"(
4140 import 'file:///test:isolate_reload_helper';
4143 const A(this.x, this.y);
4147 a = const A(1, null);
4155 "Const class cannot remove fields: "
4156 "Library:'file:///test-lib' Class: A");
4159 const char* kReloadScript2 = R
"(
4160 import 'file:///test:isolate_reload_helper';
4163 const A(this.x, this.y, this.w);
4167 a = const A(1, null, null);
4175 "Const class cannot remove fields: "
4176 "Library:'file:///test-lib' Class: A");
4180 const char* kScript = R
"(
4181 @pragma('vm:deeply-immutable')
4196 const char* kReloadScript = R
"(
4209 "Classes cannot change their @pragma('vm:deeply-immutable'): "
4210 "Library:'file:///test-lib' Class: A");
4214 const char* kScript = R
"(
4229 const char* kReloadScript = R
"(
4230 @pragma('vm:deeply-immutable')
4243 "Classes cannot change their @pragma('vm:deeply-immutable'): "
4244 "Library:'file:///test-lib' Class: A");
4251 "file:///test-app.dart",
4253 import 'test-lib.dart';
4255 @pragma('vm:deeply-immutable')
4267 "file:///test-lib.dart",
4269 @pragma('vm:deeply-immutable')
4280 nullptr ,
true ,
true );
4286 EXPECT_EQ(42,
value);
4291 "file:///test-lib.dart",
4302 const uint8_t* kernel_buffer =
nullptr;
4303 intptr_t kernel_buffer_size = 0;
4305 "file:///test-app.dart",
4307 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
4311 EXPECT_NULLPTR(kernel_buffer);
4315TEST_CASE(IsolateReload_DeeplyImmutableChange_TypeBound) {
4319 "file:///test-app.dart",
4321 import 'test-lib.dart';
4323 @pragma('vm:deeply-immutable')
4324 final class A<T extends B> {
4335 "file:///test-lib.dart",
4337 @pragma('vm:deeply-immutable')
4348 nullptr ,
true ,
true );
4354 EXPECT_EQ(42,
value);
4359 "file:///test-lib.dart",
4370 const uint8_t* kernel_buffer =
nullptr;
4371 intptr_t kernel_buffer_size = 0;
4373 "file:///test-app.dart",
4375 updated_sourcefiles, &kernel_buffer, &kernel_buffer_size,
4379 EXPECT_NULLPTR(kernel_buffer);
4383TEST_CASE(IsolateReload_ConstToNonConstClass) {
4384 const char* kScript = R
"(
4400 const char* kReloadScript = R
"(
4413 "Const class cannot become non-const: "
4414 "Library:'file:///test-lib' Class: A");
4417TEST_CASE(IsolateReload_ConstToNonConstClass_Empty) {
4418 const char* kScript = R
"(
4433 const char* kReloadScript = R
"(
4446 "Const class cannot become non-const: "
4447 "Library:'file:///test-lib' Class: A");
4450TEST_CASE(IsolateReload_StaticTearOffRetainsHash) {
4451 const char* kScript =
4453 "var hash1, hash2;\n"
4455 " hash1 = foo.hashCode;\n"
4463 const char* kReloadScript =
4465 "var hash1, hash2;\n"
4467 " hash2 = foo.hashCode;\n"
4468 " return (hash1 == hash2).toString();\n"
4480TEST_CASE(IsolateReload_NoLibsModified) {
4481 const char* kImportScript =
"importedFunc() => 'fancy';";
4484 const char* kScript =
4485 "import 'test:lib1';\n"
4487 " return importedFunc() + ' feast';\n"
4494 const char* kReloadImportScript =
"importedFunc() => 'bossy';";
4497 const char* kReloadScript =
4498 "import 'test:lib1';\n"
4500 " return importedFunc() + ' pants';\n"
4513 if ((strcmp(url,
"test-lib") == 0) ||
4514 (strcmp(url,
"file:///test-lib") == 0)) {
4520TEST_CASE(IsolateReload_MainLibModified) {
4521 const char* kImportScript =
"importedFunc() => 'fancy';";
4524 const char* kScript =
4525 "import 'test:lib1';\n"
4527 " return importedFunc() + ' feast';\n"
4534 const char* kReloadImportScript =
"importedFunc() => 'bossy';";
4537 const char* kReloadScript =
4538 "import 'test:lib1';\n"
4540 " return importedFunc() + ' pants';\n"
4553 if (strcmp(url,
"test:lib1") == 0) {
4559TEST_CASE(IsolateReload_ImportedLibModified) {
4560 const char* kImportScript =
"importedFunc() => 'fancy';";
4563 const char* kScript =
4564 "import 'test:lib1';\n"
4566 " return importedFunc() + ' feast';\n"
4573 const char* kReloadImportScript =
"importedFunc() => 'bossy';";
4576 const char* kReloadScript =
4577 "import 'test:lib1';\n"
4579 " return importedFunc() + ' pants';\n"
4591TEST_CASE(IsolateReload_PrefixImportedLibModified) {
4592 const char* kImportScript =
"importedFunc() => 'fancy';";
4595 const char* kScript =
4596 "import 'test:lib1' as cobra;\n"
4598 " return cobra.importedFunc() + ' feast';\n"
4605 const char* kReloadImportScript =
"importedFunc() => 'bossy';";
4608 const char* kReloadScript =
4609 "import 'test:lib1' as cobra;\n"
4611 " return cobra.importedFunc() + ' pants';\n"
4625 if (strcmp(url,
"test:exportlib") == 0) {
4631TEST_CASE(IsolateReload_ExportedLibModified) {
4632 const char* kImportScript =
"export 'test:exportlib';";
4635 const char* kExportScript =
"exportedFunc() => 'fancy';";
4638 const char* kScript =
4639 "import 'test:importlib';\n"
4641 " return exportedFunc() + ' feast';\n"
4648 const char* kReloadExportScript =
"exportedFunc() => 'bossy';";
4651 const char* kReloadScript =
4652 "import 'test:importlib';\n"
4654 " return exportedFunc() + ' pants';\n"
4666TEST_CASE(IsolateReload_SimpleConstFieldUpdate) {
4667 const char* kScript =
4668 "const value = 'a';\n"
4670 " return 'value=${value}';\n"
4677 const char* kReloadScript =
4678 "const value = 'b';\n"
4680 " return 'value=${value}';\n"
4688TEST_CASE(IsolateReload_ConstFieldUpdate) {
4689 const char* kScript =
4690 "const value = const Duration(seconds: 1);\n"
4692 " return 'value=${value}';\n"
4699 const char* kReloadScript =
4700 "const value = const Duration(seconds: 2);\n"
4702 " return 'value=${value}';\n"
4710TEST_CASE(IsolateReload_RunNewFieldInitializers) {
4712 const char* kScript =
4719 " return value.x;\n"
4729 const char* kReloadScript =
4736 " return value.y;\n"
4746TEST_CASE(IsolateReload_RunNewFieldInitializersReferenceStaticField) {
4748 const char* kScript =
4749 "int myInitialValue = 8 * 7;\n"
4756 " return value.x;\n"
4766 const char* kReloadScript =
4767 "int myInitialValue = 8 * 7;\n"
4770 " int y = myInitialValue;\n"
4774 " return value.y;\n"
4784TEST_CASE(IsolateReload_RunNewFieldInitializersLazy) {
4786 const char* kScript =
4787 "int myInitialValue = 8 * 7;\n"
4792 "late Foo value1;\n"
4795 " value1 = Foo();\n"
4796 " return value.x;\n"
4806 const char* kReloadScript =
4807 "int myInitialValue = 8 * 7;\n"
4810 " int y = myInitialValue++;\n"
4813 "late Foo value1;\n"
4815 " return '${myInitialValue} ${value.y} ${value1.y} "
4816 "${myInitialValue}';\n"
4826TEST_CASE(IsolateReload_RunNewFieldInitializersLazyConst) {
4828 const char* kScript =
4835 " return value.x;\n"
4848 const char* kReloadScript =
4864 const char* kReloadScript2 =
4871 " return value.y;\n"
4879TEST_CASE(IsolateReload_RunNewFieldInitializersLazyTransitive) {
4881 const char* kScript =
4882 "int myInitialValue = 8 * 7;\n"
4887 "late Foo value1;\n"
4890 " value1 = Foo();\n"
4891 " return value.x;\n"
4901 const char* kReloadScript =
4902 "int myInitialValue = 8 * 7;\n"
4905 " int y = myInitialValue++;\n"
4908 "late Foo value1;\n"
4910 " return '${myInitialValue}';\n"
4921 const char* kReloadScript2 =
4922 "int myInitialValue = 8 * 7;\n"
4925 " int y = myInitialValue++;\n"
4928 "late Foo value1;\n"
4930 " return '${myInitialValue} ${value.y} ${value1.y} "
4931 "${myInitialValue}';\n"
4941TEST_CASE(IsolateReload_RunNewFieldInitializersThrows) {
4943 const char* kScript =
4950 " return value.x;\n"
4960 const char* kReloadScript =
4963 " int y = throw 'exception';\n"
4968 " return value.y.toString();\n"
4970 " return e.toString();\n"
4981TEST_CASE(IsolateReload_RunNewFieldInitializersCyclicInitialization) {
4983 const char* kScript =
4990 " return value.x;\n"
5000 const char* kReloadScript =
5003 " int y = value.y;\n"
5008 " return value.y.toString();\n"
5010 " return e.toString();\n"
5021TEST_CASE(IsolateReload_RunNewFieldInitializersSyntaxError) {
5023 const char* kScript =
5030 " return value.x;\n"
5040 const char* kReloadScript =
5043 " int y = ......;\n"
5047 " return '${value.y == null}';"
5059TEST_CASE(IsolateReload_RunNewFieldInitializersSyntaxError2) {
5061 const char* kScript =
5063 " Foo() { /* default constructor */ }\n"
5069 " return value.x;\n"
5079 const char* kReloadScript =
5081 " Foo() { /* default constructor */ }\n"
5083 " int y = ......;\n"
5087 " return '${value.y == null}';"
5099TEST_CASE(IsolateReload_RunNewFieldInitializersSyntaxError3) {
5101 const char* kScript =
5103 " Foo() { /* default constructor */ }\n"
5109 " return value.x;\n"
5119 const char* kReloadScript =
5121 " Foo() { /* default constructor */ }\n"
5127 " return '${value.y == null}';"
5137TEST_CASE(IsolateReload_RunNewFieldInitializersSuperClass) {
5139 const char* kScript =
5141 " static var foo = 'right';\n"
5143 "class Foo extends Super {\n"
5144 " static var foo = 'wrong';\n"
5160 const char* kReloadScript =
5162 " static var foo = 'right';\n"
5163 " var newField = foo;\n"
5165 "class Foo extends Super {\n"
5166 " static var foo = 'wrong';\n"
5170 " return value.newField;\n"
5179 EXPECT(actual !=
nullptr);
5180 if (actual !=
nullptr) {
5181 EXPECT_STREQ(
"right", actual);
5185TEST_CASE(IsolateReload_RunNewFieldInitializersWithConsts) {
5187 const char* kScript =
5190 " const C(this.x);\n"
5192 "var a = const C(const C(1));\n"
5193 "var b = const C(const C(2));\n"
5194 "var c = const C(const C(3));\n"
5195 "var d = const C(const C(4));\n"
5211 const char* kReloadScript =
5214 " const C(this.x);\n"
5216 "var a = const C(const C(1));\n"
5217 "var b = const C(const C(2));\n"
5218 "var c = const C(const C(3));\n"
5219 "var d = const C(const C(4));\n"
5221 " var d = const C(const C(4));\n"
5222 " var c = const C(const C(3));\n"
5223 " var b = const C(const C(2));\n"
5224 " var a = const C(const C(1));\n"
5228 " return '${identical(a, value.a)} ${identical(b, value.b)}'"
5229 " ' ${identical(c, value.c)} ${identical(d, value.d)}';\n"
5239TEST_CASE(IsolateReload_RunNewFieldInitializersWithGenerics) {
5241 const char* kScript =
5245 "late Foo value1;\n"
5246 "late Foo value2;\n"
5248 " value1 = Foo<String>();\n"
5249 " value2 = Foo<int>();\n"
5259 const char* kReloadScript =
5262 " List<T> y = List<T>.empty();"
5263 " dynamic z = <T,T>{};"
5265 "late Foo value1;\n"
5266 "late Foo value2;\n"
5268 " return '${value1.y.runtimeType} ${value1.z.runtimeType}'"
5269 " ' ${value2.y.runtimeType} ${value2.z.runtimeType}';\n"
5277 EXPECT_STREQ(
"List<String> _Map<String, String> List<int> _Map<int, int>",
5281TEST_CASE(IsolateReload_AddNewStaticField) {
5282 const char* kScript =
5293 const char* kReloadScript =
5295 " static var x = 42;\n"
5298 " return '${C.x}';\n"
5306TEST_CASE(IsolateReload_StaticFieldInitialValueDoesnotChange) {
5307 const char* kScript =
5309 " static var x = 42;\n"
5312 " return '${C.x}';\n"
5319 const char* kReloadScript =
5321 " static var x = 13;\n"
5324 " return '${C.x}';\n"
5333class CidCountingVisitor :
public ObjectVisitor {
5339 if (obj->GetClassId() == cid_) {
5344 intptr_t
count()
const {
return count_; }
5348 intptr_t count_ = 0;
5351TEST_CASE(IsolateReload_DeleteStaticField) {
5352 const char* kScript =
5356 "static var x = C();\n"
5364 intptr_t
cid = 1118;
5376 const char* kReloadScript =
5382 " return '${Foo()}';\n"
5390 TransitionNativeToVM transition(thread);
5394 HeapIterationScope iteration(thread);
5395 CidCountingVisitor counting_visitor(
cid);
5396 iteration.IterateObjects(&counting_visitor);
5400 EXPECT_NE(counting_visitor.count(), 0);
5408 const char* from_type,
5409 const char* from_init,
5410 const char* to_type,
5411 const char* to_init) {
5415 import 'dart:typed_data';
5417 void doubleEq(double got, double expected) {
5418 if (got != expected) throw 'expected $expected got $got';
5421 void float32x4Eq(Float32x4 got, Float32x4 expected) {
5422 if (got.equal(expected).signMask != 0xf) throw 'expected $expected got $got';
5450 import 'dart:typed_data';
5452 void doubleEq(double got, double expected) {
5453 if (got != expected) throw 'expected $expected got $got';
5456 void float32x4Eq(Float32x4 got, Float32x4 expected) {
5457 if (got.equal(expected).signMask != 0xf) throw 'expected $expected got $got';
5469 return value.x.toString();
5471 return e.toString();
5483 "type '%s' is not a subtype of type '%s' of 'function result'",
5484 from_type, to_type),
5488TEST_CASE(IsolateReload_ExistingFieldChangesType) {
5494TEST_CASE(IsolateReload_ExistingFieldChangesTypeWithOtherUnboxedFields) {
5497 "Float32x4 b = Float32x4(1.0, 2.0, 3.0, 4.0);",
5498 "doubleEq(value.a, 1.5); float32x4Eq(value.b, Float32x4(1.0, 2.0, 3.0, "
5500 "int",
"42",
"double",
5504TEST_CASE(IsolateReload_ExistingFieldUnboxedToBoxed) {
5507 "Float32x4 b = Float32x4(1.0, 2.0, 3.0, 4.0);",
5508 "doubleEq(value.a, 1.5); float32x4Eq(value.b, Float32x4(1.0, 2.0, 3.0, "
5510 "double",
"42.0",
"String",
5514TEST_CASE(IsolateReload_ExistingFieldBoxedToUnboxed) {
5518 "Float32x4 b = Float32x4(1.0, 2.0, 3.0, 4.0);",
5519 "doubleEq(value.a, 1.5); float32x4Eq(value.b, Float32x4(1.0, 2.0, 3.0, "
5521 "String",
"'42.0'",
"double",
5525TEST_CASE(IsolateReload_ExistingFieldUnboxedToUnboxed) {
5529 "Float32x4 b = Float32x4(1.0, 2.0, 3.0, 4.0);",
5530 "doubleEq(value.a, 1.5); float32x4Eq(value.b, Float32x4(1.0, 2.0, 3.0, "
5532 "double",
"42.0",
"Float32x4",
5533 "Float32x4(1.0, 2.0, 3.0, 4.0)");
5536TEST_CASE(IsolateReload_ExistingStaticFieldChangesType) {
5537 const char* kScript = R
"(
5541 return value.toString();
5549 const char* kReloadScript = R
"(
5550 double value = init();
5554 return value.toString();
5556 return e.toString();
5564 "type 'int' is not a subtype of type 'double' of 'function result'",
5568TEST_CASE(IsolateReload_ExistingFieldChangesTypeIndirect) {
5570 const char* kScript = R
"(
5572 class B extends A {}
5591 const char* kReloadScript = R
"(
5601 return value.x.toString();
5603 return e.toString();
5611 EXPECT_STREQ(
"type 'B' is not a subtype of type 'A' of 'function result'",
5615TEST_CASE(IsolateReload_ExistingStaticFieldChangesTypeIndirect) {
5616 const char* kScript = R
"(
5618 class B extends A {}
5622 return value.toString();
5631 const char* kReloadScript = R
"(
5638 return value.toString();
5640 return e.toString();
5647 EXPECT_STREQ("type 'B' is not a subtype of type 'A' of 'function result'",
5651TEST_CASE(IsolateReload_ExistingFieldChangesTypeIndirectGeneric) {
5653 const char* kScript = R
"(
5655 class B extends A {}
5662 value = Foo(List<B>.empty());
5674 const char* kReloadScript = R
"(
5684 return value.x.toString();
5686 return e.toString();
5695 "type 'List<B>' is not a subtype of type 'List<A>' of 'function result'",
5699TEST_CASE(IsolateReload_ExistingStaticFieldChangesTypeIndirectGeneric) {
5700 const char* kScript = R
"(
5702 class B extends A {}
5703 List<A> value = init();
5704 init() => List<B>.empty();
5706 return value.toString();
5715 const char* kReloadScript = R
"(
5718 List<A> value = init();
5719 init() => List<A>.empty();
5722 return value.toString();
5724 return e.toString();
5732 "type 'List<B>' is not a subtype of type 'List<A>' of 'function result'",
5736TEST_CASE(IsolateReload_ExistingFieldChangesTypeIndirectFunction) {
5738 const char* kScript = R
"(
5740 class B extends A {}
5741 typedef bool Predicate(B b);
5748 value = Foo((A a) => true);
5760 const char* kReloadScript = R
"(
5763 typedef bool Predicate(B b);
5771 return value.x.toString();
5773 return e.toString();
5782 "type '(A) => bool' is not a subtype of type '(B) => bool' of 'function "
5787TEST_CASE(IsolateReload_ExistingStaticFieldChangesTypeIndirectFunction) {
5788 const char* kScript = R
"(
5790 class B extends A {}
5791 typedef bool Predicate(B b);
5792 Predicate value = init();
5793 init() => (A a) => true;
5795 return value.toString();
5804 const char* kReloadScript = R
"(
5807 typedef bool Predicate(B b);
5808 Predicate value = init();
5809 init() => (B a) => true;
5812 return value.toString();
5814 return e.toString();
5822 "type '(A) => bool' is not a subtype of type '(B) => bool' of 'function "
5827TEST_CASE(IsolateReload_TypedefToNotTypedef) {
5831 const char* kScript =
5832 "typedef bool Predicate(dynamic x);\n"
5834 " return (42 is Predicate).toString();\n"
5841 const char* kReloadScript =
5842 "class Predicate {\n"
5843 " bool call(dynamic x) { return false; }\n"
5846 " return (42 is Predicate).toString();\n"
5853TEST_CASE(IsolateReload_NotTypedefToTypedef) {
5854 const char* kScript =
5855 "class Predicate {\n"
5856 " bool call(dynamic x) { return false; }\n"
5859 " return (42 is Predicate).toString();\n"
5869 const char* kReloadScript =
5870 "typedef bool Predicate(dynamic x);\n"
5872 " return (42 is Predicate).toString();\n"
5879TEST_CASE(IsolateReload_TypedefAddParameter) {
5880 const char* kScript =
5881 "typedef bool Predicate(dynamic x);\n"
5883 " bool foo(x) => true;\n"
5884 " return (foo is Predicate).toString();\n"
5891 const char* kReloadScript =
5892 "typedef bool Predicate(dynamic x, dynamic y);\n"
5894 " bool foo(x) => true;\n"
5895 " return (foo is Predicate).toString();\n"
5903TEST_CASE(IsolateReload_PatchStaticInitializerWithClosure) {
5904 const char* kScript =
5905 "dynamic field = (a) => 'a$a';\n"
5907 " dynamic f = field;\n"
5915 const char* kReloadScript =
5916 "extraFunction() => 'Just here to change kernel offsets';\n"
5917 "dynamic field = (_, __) => 'Not executed';\n"
5919 " dynamic f = field;\n"
5928TEST_CASE(IsolateReload_StaticTargetArityChange) {
5929 const char* kScript = R
"(
5933 const A(this.x, this.y);
5939 closure = () => A(1, 2);
5948 const char* kReloadScript = R
"(
5957 // Call the old closure, which will try to call A(1, 2).
5967 "Unhandled exception:\n"
5968 "NoSuchMethodError: No constructor 'A.' "
5969 "with matching arguments declared in class 'A'.");
5972TEST_CASE(IsolateReload_SuperGetterReboundToMethod) {
5973 const char* kScript = R
"(
5974 import 'file:///test:isolate_reload_helper';
5982 var old_x = super.x;
5984 var new_x = super.x;
5985 return "$old_x:$new_x";
5990 return B().f().toString();
5997 const char* kReloadScript = R
"(
5998 import 'file:///test:isolate_reload_helper';
6006 var old_x = super.x;
6008 var new_x = super.x;
6009 return "$old_x:$new_x";
6020 EXPECT_STREQ("123:Closure: () => dynamic from Function 'x':.",
6034 const uint8_t** kernel_buffer,
6035 intptr_t* kernel_buffer_size) {
6042 EXPECT_NOTNULL(kernel_buffer);
6049class KernelTagHandler {
6051 KernelTagHandler(uint8_t* kernel_buffer, intptr_t kernel_buffer_size)
6052 : kernel_buffer_(kernel_buffer), kernel_buffer_size_(kernel_buffer_size) {
6057 ~KernelTagHandler() {
6059 instance_ =
nullptr;
6062 static KernelTagHandler* Current() {
return instance_; }
6064 bool was_called()
const {
return was_called_; }
6065 bool was_finalized()
const {
return was_finalized_; }
6068 static void Finalizer(
void* isolate_callback_data,
void* peer) {
6069 if (
auto handler = KernelTagHandler::Current()) {
6070 handler->was_finalized_ =
true;
6078 auto handler = KernelTagHandler::Current();
6079 handler->was_called_ =
true;
6083 handler->kernel_buffer_size_);
6085 handler->kernel_buffer_size_, &
Finalizer);
6092 static KernelTagHandler* instance_;
6093 uint8_t* kernel_buffer_;
6094 intptr_t kernel_buffer_size_;
6095 bool was_finalized_ =
false;
6096 bool was_called_ =
false;
6099KernelTagHandler* KernelTagHandler::instance_ =
nullptr;
6102TEST_CASE(IsolateReload_RegressB179030011) {
6105 const uint8_t* kernel_buffer;
6106 intptr_t kernel_buffer_size;
6110 std::array<Component, 2> components = {{
6129 for (
auto& component : components) {
6130 CompileToKernel(component.source, &component.kernel_buffer,
6131 &component.kernel_buffer_size);
6136 intptr_t kernel_buffer_size = 0;
6137 for (
auto component : components) {
6138 kernel_buffer_size += component.kernel_buffer_size;
6140 uint8_t* kernel_buffer =
static_cast<uint8_t*
>(
malloc(kernel_buffer_size));
6143 for (
auto component : components) {
6144 memcpy(kernel_buffer +
pos, component.kernel_buffer,
6145 component.kernel_buffer_size);
6146 pos += component.kernel_buffer_size;
6152 components[0].kernel_buffer, components[0].kernel_buffer_size);
6157 KernelTagHandler handler(kernel_buffer, kernel_buffer_size);
6165 EXPECT(handler.was_called());
6169 TransitionNativeToVM transition(thread);
6171 EXPECT(!handler.was_finalized());
6176TEST_CASE(IsolateReload_GenericConstructorTearOff) {
6177 const char* kScript = R
"(
6178 typedef Create<T, R> = T Function(R ref);
6181 Base(void Function(Create<void, Input> create) factory) : _factory = factory;
6183 final void Function(Create<void, Input> create) _factory;
6185 void fn() => _factory((ref) {});
6189 Check(Create<Object?, List<T>> create);
6192 final f = Base<List<int>>(Check<int>.new);
6210TEST_CASE(IsolateReload_ImplicitGetterWithLoadGuard) {
6211 const char* kLibScript = R
"(
6212 import 'file:///test:isolate_reload_helper';
6217 A.withUinitializedObject(int Function() callback) : x = callback();
6224 // Trigger OSR and optimize this function.
6225 for (int i = 0; i < 30000; ++i) {
6228 // Make sure A.get:x is compiled.
6230 // Reload while having an uninitialized
6231 // object A on the stack. This should result in
6232 // a load guard for A.x.
6233 A.withUinitializedObject(() {
6237 // Trigger OSR and optimize this function once again.
6238 for (int i = 0; i < 30000; ++i) {
6241 // Trigger deoptimization in A.get:x.
6242 // It should correctly deoptimize into an implicit
6243 // getter with a load guard.
6244 a.x = 0x8070605040302010;
6245 int z = a.x & 0xffff;
6246 return "y: $y, z: $z";
6254 const char* kMainScript = R
"(
6267TEST_CASE(IsolateReload_EnumInMainLibraryModified) {
6268 const char* kScript =
6269 "enum Bar { bar }\n"
6270 "class Foo { int? a; toString() => 'foo'; }"
6272 " return Foo().toString();\n"
6280 const char* kReloadScript =
6281 "enum Bar { bar }\n"
6282 "class Foo { int? a; String? b; toString() => 'foo'; }"
6284 " return Foo().toString();\n"
6296 const char* kScript =
6297 "import 'file:///test:isolate_reload_helper';\n"
6299 " @pragma('vm:prefer-inline')\n"
6311 const char* kReloadScript =
6312 "import 'file:///test:isolate_reload_helper';\n"
6331 TransitionNativeToVM transition(thread);
6341 Symbols::vm_prefer_inline()));
6343 Symbols::vm_prefer_inline()));
6347 const char* kScript =
6349 " member1({Enum2.member1, Enum2.member2}),\n"
6350 " member2({Enum2.member2}),\n"
6351 " member3({Enum2.member1}),\n"
6352 " member4({Enum2.member2, Enum2.member1}),\n"
6353 " member5({Enum2.member1}),\n"
6354 " member6({Enum2.member1});\n"
6355 " const Enum1(this.set);\n"
6356 " final Set<Enum2> set;\n"
6358 "enum Enum2 { member1, member2; }\n"
6361 " retained = Enum1.member4;\n"
6368 const char* kReloadScript =
6369 "enum Enum2 { member1, member2; }\n"
6371 " member1({Enum2.member1, Enum2.member2}),\n"
6372 " member2({Enum2.member2}),\n"
6373 " member3({Enum2.member1}),\n"
6374 " member4({Enum2.member2, Enum2.member1}),\n"
6375 " member5({Enum2.member1}),\n"
6376 " member6({Enum2.member1});\n"
6377 " const Enum1(this.set);\n"
6378 " final Set<Enum2> set;\n"
6382 " return switch (e as Enum1) {\n"
6383 " Enum1.member1 => \"a\",\n"
6384 " Enum1.member2 => \"b\",\n"
6385 " Enum1.member3 => \"c\",\n"
6386 " Enum1.member4 => \"d\",\n"
6387 " Enum1.member5 => \"e\",\n"
6388 " Enum1.member6 => \"f\",\n"
6392 " return foo(retained);\n"
6411 for (intptr_t
i = 0;
i < constants.
Length();
i++) {
6412 constants.
SetAt(
i, Object::sentinel());
6421 const char* kScript =
6422 "import 'file:///test:isolate_reload_helper';\n"
6424 " @pragma('vm:prefer-inline')\n"
6436 const char* kReloadScript =
6437 "import 'file:///test:isolate_reload_helper';\n"
6439 " @pragma('vm:never-inline')\n"
6457 TransitionNativeToVM transition(thread);
6465 Symbols::vm_prefer_inline()));
6467 Symbols::vm_never_inline()));
6469 Symbols::vm_prefer_inline()));
6471 Symbols::vm_never_inline()));
6476 const char* kScript =
6477 "import 'file:///test:isolate_reload_helper';\n"
6490 const char* kReloadScript =
6491 "import 'file:///test:isolate_reload_helper';\n"
6493 " @pragma('vm:never-inline')\n"
6511 TransitionNativeToVM transition(thread);
6519 Symbols::vm_never_inline()));
6522 Symbols::vm_never_inline()));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static ObjectPtr UnwrapHandle(Dart_Handle object)
static intptr_t ClassId(Dart_Handle handle)
void SetAt(intptr_t index, const Object &value) const
virtual void VisitObject(ObjectPtr obj)
CidCountingVisitor(intptr_t cid)
virtual ~CidCountingVisitor()
GrowableObjectArrayPtr direct_subclasses_unsafe() const
ObjectStore * object_store() const
static IsolateGroup * Current()
static bool FindPragma(Thread *T, bool only_core, const Object &object, const String &pragma_name, bool multiple=false, Object *options=nullptr)
ClassPtr LookupClass(const String &name) const
KernelProgramInfoPtr kernel_program_info() const
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static ObjectPtr RawCast(ObjectPtr obj)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static void AddToKernelBuffers(const uint8_t *kernel_buffer)
static Dart_Handle TriggerReload(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
static Dart_Handle LoadTestScriptWithDFE(int sourcefiles_count, Dart_SourceFile sourcefiles[], Dart_NativeEntryResolver resolver=nullptr, bool finalize=true, bool incrementally=true, bool allow_compile_errors=false, const char *entry_script_uri=nullptr, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr)
static void AddTestLib(const char *url, const char *source)
static Dart_Handle LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri=RESOLVED_USER_TEST_URI, bool finalize=true, bool allow_compile_errors=false)
static Dart_Handle ReloadTestScript(const char *script)
static char * CompileTestScriptWithDFE(const char *url, const char *source, const uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool incrementally=true, bool allow_compile_errors=false, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr)
static Dart_Handle SetReloadTestScript(const char *script)
static Dart_Handle LoadTestScriptWithErrors(const char *script, Dart_NativeEntryResolver resolver=nullptr, const char *lib_uri=RESOLVED_USER_TEST_URI, bool finalize=true)
static Dart_Handle LoadTestLibrary(const char *lib_uri, const char *script, Dart_NativeEntryResolver resolver=nullptr)
static Dart_Handle ReloadTestKernel(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
static Thread * Current()
struct _Dart_Handle * Dart_Handle
const uint8_t uint32_t uint32_t GError ** error
Dart_NativeFunction function
DART_EXPORT bool Dart_IsLibrary(Dart_Handle object)
Dart_Handle Dart_GetLibraryDebuggable(intptr_t library_id, bool *is_debuggable)
DART_EXPORT void Dart_EnterScope()
CAllocUniquePtr< char > CStringUniquePtr
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_RootLibrary()
const char * SimpleInvokeStr(Dart_Handle lib, const char *method)
static bool NothingModifiedCallback(const char *url, int64_t since)
void * malloc(size_t size)
static bool MainModifiedCallback(const char *url, int64_t since)
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
DART_EXPORT Dart_FinalizableHandle Dart_NewFinalizableHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT char * Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback)
Dart_Handle Dart_SetLibraryDebuggable(intptr_t library_id, bool is_debuggable)
static void TestReloadWithFieldChange(const char *prefix, const char *suffix, const char *verify, const char *from_type, const char *from_init, const char *to_type, const char *to_init)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, void *data, intptr_t length)
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)
static void Finalizer(void *isolate_callback_data, void *buffer)
static bool ExportModifiedCallback(const char *url, int64_t since)
Dart_Handle Dart_LibraryId(Dart_Handle library, intptr_t *library_id)
TEST_CASE(DirectoryCurrent)
Dart_Handle NewString(const char *str)
int64_t SimpleInvoke(Dart_Handle lib, const char *method)
DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler)
DART_EXPORT void Dart_ExitScope()
DART_EXPORT Dart_Handle Dart_FinalizeAllClasses()
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
static void CollectAllGarbage(Thread *thread, JSONStream *js)
DART_EXPORT bool Dart_IsInteger(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_Null()
DART_EXPORT bool Dart_IsString(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, const char **cstr)
static bool ImportModifiedCallback(const char *url, int64_t since)
Dart_Handle SimpleInvokeError(Dart_Handle lib, const char *method)
DART_EXPORT Dart_Handle Dart_LoadLibraryFromKernel(const uint8_t *buffer, intptr_t buffer_size)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
#define EXPECT_ERROR(handle, substring)
#define EXPECT_NON_NULL(handle)
#define EXPECT_VALID(handle)
#define ARRAY_SIZE(array)