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

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

Issue 2204593011: Reload: Have dangling extracted properties raise NoSuchMethod. (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') | runtime/vm/parser.cc » ('J')
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 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 TestCase::SetReloadTestScript(kReloadScript); 1480 TestCase::SetReloadTestScript(kReloadScript);
1481 1481
1482 EXPECT_STREQ("new new true true true new true true true", 1482 EXPECT_STREQ("new new true true true new true true true",
1483 SimpleInvokeStr(lib, "main")); 1483 SimpleInvokeStr(lib, "main"));
1484 1484
1485 lib = TestCase::GetReloadErrorOrRootLibrary(); 1485 lib = TestCase::GetReloadErrorOrRootLibrary();
1486 EXPECT_VALID(lib); 1486 EXPECT_VALID(lib);
1487 } 1487 }
1488 1488
1489 1489
1490 TEST_CASE(IsolateReload_DanglingGetter_Instance) {
1491 const char* kScript =
1492 "import 'test:isolate_reload_helper';\n"
1493 "class C {\n"
1494 " var x = 3;\n"
1495 " var y = 4;\n"
1496 "}\n"
1497 "invoke(f) {\n"
1498 " try {\n"
1499 " return f();\n"
1500 " } catch (e) {\n"
1501 " return e.toString().split('\\n').first;\n"
1502 " }\n"
1503 "}\n"
1504 "main() {\n"
1505 " var c = new C();\n"
1506 " var f = c#y;\n"
1507 " var r1 = invoke(f);\n"
1508 " reloadTest();\n"
1509 " var r2 = invoke(f);\n"
1510 " return '$r1 $r2';\n"
1511 "}\n";
1512
1513 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1514 EXPECT_VALID(lib);
1515
1516 const char* kReloadScript =
1517 "import 'test:isolate_reload_helper';\n"
1518 "class C {\n"
1519 " var x = 3;\n"
1520 "}\n"
1521 "invoke(f) {\n"
1522 " try {\n"
1523 " return f();\n"
1524 " } catch (e) {\n"
1525 " return e.toString().split('\\n').first;\n"
1526 " }\n"
1527 "}\n"
1528 "main() {\n"
1529 " var c = new C();\n"
1530 " var f = c#y;\n"
1531 " var r1 = invoke(f);\n"
1532 " reloadTest();\n"
1533 " var r2 = invoke(f);\n"
1534 " return '$r1 $r2';\n"
1535 "}\n";
1536
1537 TestCase::SetReloadTestScript(kReloadScript);
1538
1539 EXPECT_STREQ("4 Class 'C' has no instance getter 'y'.",
1540 SimpleInvokeStr(lib, "main"));
1541
1542 lib = TestCase::GetReloadErrorOrRootLibrary();
1543 EXPECT_VALID(lib);
1544 }
1545
1546
1547 TEST_CASE(IsolateReload_DanglingGetter_Class) {
1548 const char* kScript =
1549 "import 'test:isolate_reload_helper';\n"
1550 "class C {\n"
1551 " static var x;\n"
1552 " static var y;\n"
1553 "}\n"
1554 "invoke(f) {\n"
1555 " try {\n"
1556 " return f();\n"
1557 " } catch (e) {\n"
1558 " return e.toString().split('\\n').first;\n"
1559 " }\n"
1560 "}\n"
1561 "main() {\n"
1562 " C.x = 3;\n"
1563 " C.y = 4;\n"
1564 " var f = C#y;\n"
1565 " var r1 = invoke(f);\n"
1566 " reloadTest();\n"
1567 " var r2 = invoke(f);\n"
1568 " return '$r1 $r2';\n"
1569 "}\n";
1570
1571 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1572 EXPECT_VALID(lib);
1573
1574 const char* kReloadScript =
1575 "import 'test:isolate_reload_helper';\n"
1576 "class C {\n"
1577 " static var x;\n"
1578 "}\n"
1579 "invoke(f) {\n"
1580 " try {\n"
1581 " return f();\n"
1582 " } catch (e) {\n"
1583 " return e.toString().split('\\n').first;\n"
1584 " }\n"
1585 "}\n"
1586 "main() {\n"
1587 " C.x = 3;\n"
1588 " C.y = 4;\n"
1589 " var f = C#y;\n"
1590 " var r1 = invoke(f);\n"
1591 " reloadTest();\n"
1592 " var r2 = invoke(f);\n"
1593 " return '$r1 $r2';\n"
1594 "}\n";
1595
1596 TestCase::SetReloadTestScript(kReloadScript);
1597
1598 EXPECT_STREQ("4 No static getter 'y' declared in class 'C'.",
1599 SimpleInvokeStr(lib, "main"));
1600
1601 lib = TestCase::GetReloadErrorOrRootLibrary();
1602 EXPECT_VALID(lib);
1603 }
1604
1605
1606 static void IsolateReload_DanlingGetter_LibraryReload(
1607 Dart_NativeArguments native_args) {
1608 const char* kImportScript2 =
1609 "var x;\n";
1610 TestCase::AddTestLib("test:other", kImportScript2);
1611
1612 DART_CHECK_VALID(TestCase::TriggerReload());
1613 }
1614
1615
1616 static Dart_NativeFunction IsolateReload_DanlingGetter_LibraryNativeResolver(
1617 Dart_Handle name,
1618 int num_of_arguments,
1619 bool* auto_setup_scope) {
1620 return IsolateReload_DanlingGetter_LibraryReload;
1621 }
1622
1623
1624 TEST_CASE(IsolateReload_DanglingGetter_Library) {
1625 const char* kImportScript =
1626 "var x;\n"
1627 "var y;\n";
1628 TestCase::AddTestLib("test:other", kImportScript);
1629
1630 const char* kScript =
1631 "import 'test:other' as prefix;\n"
1632 "reloadTest() native 'ReloadTest';\n"
1633 "invoke(f) {\n"
1634 " try {\n"
1635 " return f();\n"
1636 " } catch (e) {\n"
1637 " return e.toString().split('\\n').first;\n"
1638 " }\n"
1639 "}\n"
1640 "main() {\n"
1641 " prefix.x = 3;\n"
1642 " prefix.y = 4;\n"
1643 " var f = prefix#y;\n"
1644 " var r1 = invoke(f);\n"
1645 " reloadTest();\n"
1646 " var r2 = invoke(f);\n"
1647 " return '$r1 $r2';\n"
1648 "}\n";
1649
1650 Dart_Handle lib = TestCase::LoadTestScript(
1651 kScript, IsolateReload_DanlingGetter_LibraryNativeResolver);
1652 EXPECT_VALID(lib);
1653
1654 TestCase::SetReloadTestScript(kScript); // Root library does not change.
1655
1656 EXPECT_STREQ("4 No top-level getter 'y' declared.",
1657 SimpleInvokeStr(lib, "main"));
1658
1659 lib = TestCase::GetReloadErrorOrRootLibrary();
1660 EXPECT_VALID(lib);
1661 }
1662
1663
1664 TEST_CASE(IsolateReload_DanglingSetter_Instance) {
1665 const char* kScript =
1666 "import 'test:isolate_reload_helper';\n"
1667 "class C {\n"
1668 " var x = 3;\n"
1669 " var y = 4;\n"
1670 "}\n"
1671 "invoke(f, a) {\n"
1672 " try {\n"
1673 " return f(a);\n"
1674 " } catch (e) {\n"
1675 " return e.toString().split('\\n').first;\n"
1676 " }\n"
1677 "}\n"
1678 "main() {\n"
1679 " var c = new C();\n"
1680 " var f = c#y=;\n"
1681 " var r1 = invoke(f, 5);\n"
1682 " reloadTest();\n"
1683 " var r2 = invoke(f, 6);\n"
1684 " return '$r1 $r2';\n"
1685 "}\n";
1686
1687 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1688 EXPECT_VALID(lib);
1689
1690 const char* kReloadScript =
1691 "import 'test:isolate_reload_helper';\n"
1692 "class C {\n"
1693 " var x = 3;\n"
1694 "}\n"
1695 "invoke(f, a) {\n"
1696 " try {\n"
1697 " return f(a);\n"
1698 " } catch (e) {\n"
1699 " return e.toString().split('\\n').first;\n"
1700 " }\n"
1701 "}\n"
1702 "main() {\n"
1703 " var c = new C();\n"
1704 " var f = c#y=;\n"
1705 " var r1 = invoke(f, 5);\n"
1706 " reloadTest();\n"
1707 " var r2 = invoke(f, 6);\n"
1708 " return '$r1 $r2';\n"
1709 "}\n";
1710
1711 TestCase::SetReloadTestScript(kReloadScript);
1712
1713 EXPECT_STREQ("null Class 'C' has no instance setter 'y='.",
1714 SimpleInvokeStr(lib, "main"));
1715
1716 lib = TestCase::GetReloadErrorOrRootLibrary();
1717 EXPECT_VALID(lib);
1718 }
1719
1720
1721 TEST_CASE(IsolateReload_DanglingSetter_Class) {
1722 const char* kScript =
1723 "import 'test:isolate_reload_helper';\n"
1724 "class C {\n"
1725 " static var x;\n"
1726 " static var y;\n"
1727 "}\n"
1728 "invoke(f, a) {\n"
1729 " try {\n"
1730 " return f(a);\n"
1731 " } catch (e) {\n"
1732 " return e.toString().split('\\n').first;\n"
1733 " }\n"
1734 "}\n"
1735 "main() {\n"
1736 " C.x = 3;\n"
1737 " C.y = 4;\n"
1738 " var f = C#y=;\n"
1739 " var r1 = invoke(f, 5);\n"
1740 " reloadTest();\n"
1741 " var r2 = invoke(f, 6);\n"
1742 " return '$r1 $r2';\n"
1743 "}\n";
1744
1745 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1746 EXPECT_VALID(lib);
1747
1748 const char* kReloadScript =
1749 "import 'test:isolate_reload_helper';\n"
1750 "class C {\n"
1751 " static var x;\n"
1752 "}\n"
1753 "invoke(f, a) {\n"
1754 " try {\n"
1755 " return f(a);\n"
1756 " } catch (e) {\n"
1757 " return e.toString().split('\\n').first;\n"
1758 " }\n"
1759 "}\n"
1760 "main() {\n"
1761 " C.x = 3;\n"
1762 " C.y = 4;\n"
1763 " var f = C#y=;\n"
1764 " var r1 = invoke(f, 5);\n"
1765 " reloadTest();\n"
1766 " var r2 = invoke(f, 6);\n"
1767 " return '$r1 $r2';\n"
1768 "}\n";
1769
1770 TestCase::SetReloadTestScript(kReloadScript);
1771
1772 EXPECT_STREQ("5 No static setter 'y=' declared in class 'C'.",
1773 SimpleInvokeStr(lib, "main"));
1774
1775 lib = TestCase::GetReloadErrorOrRootLibrary();
1776 EXPECT_VALID(lib);
1777 }
1778
1779
1780 static void IsolateReload_DanlingSetter_LibraryReload(
1781 Dart_NativeArguments native_args) {
1782 const char* kImportScript2 =
1783 "var x;\n";
1784 TestCase::AddTestLib("test:other", kImportScript2);
1785
1786 DART_CHECK_VALID(TestCase::TriggerReload());
1787 }
1788
1789
1790 static Dart_NativeFunction IsolateReload_DanlingSetter_LibraryNativeResolver(
1791 Dart_Handle name,
1792 int num_of_arguments,
1793 bool* auto_setup_scope) {
1794 return IsolateReload_DanlingSetter_LibraryReload;
1795 }
1796
1797
1798 TEST_CASE(IsolateReload_DanglingSetter_Library) {
1799 const char* kImportScript =
1800 "var x;\n"
1801 "var y;\n";
1802 TestCase::AddTestLib("test:other", kImportScript);
1803
1804 const char* kScript =
1805 "import 'test:other' as prefix;\n"
1806 "reloadTest() native 'ReloadTest';\n"
1807 "invoke(f, a) {\n"
1808 " try {\n"
1809 " return f(a);\n"
1810 " } catch (e) {\n"
1811 " return e.toString().split('\\n').first;\n"
1812 " }\n"
1813 "}\n"
1814 "main() {\n"
1815 " prefix.x = 3;\n"
1816 " prefix.y = 4;\n"
1817 " var f = prefix#y=;\n"
1818 " var r1 = invoke(f, 5);\n"
1819 " reloadTest();\n"
1820 " var r2 = invoke(f, 6);\n"
1821 " return '$r1 $r2';\n"
1822 "}\n";
1823
1824 Dart_Handle lib = TestCase::LoadTestScript(
1825 kScript, IsolateReload_DanlingSetter_LibraryNativeResolver);
1826 EXPECT_VALID(lib);
1827
1828 TestCase::SetReloadTestScript(kScript); // Root library does not change.
1829
1830 EXPECT_STREQ("5 No top-level setter 'y=' declared.",
1831 SimpleInvokeStr(lib, "main"));
1832
1833 lib = TestCase::GetReloadErrorOrRootLibrary();
1834 EXPECT_VALID(lib);
1835 }
1836
1837
1490 TEST_CASE(IsolateReload_EnumEquality) { 1838 TEST_CASE(IsolateReload_EnumEquality) {
1491 const char* kScript = 1839 const char* kScript =
1492 "enum Fruit {\n" 1840 "enum Fruit {\n"
1493 " Apple,\n" 1841 " Apple,\n"
1494 " Banana,\n" 1842 " Banana,\n"
1495 "}\n" 1843 "}\n"
1496 "var x;\n" 1844 "var x;\n"
1497 "main() {\n" 1845 "main() {\n"
1498 " x = Fruit.Banana;\n" 1846 " x = Fruit.Banana;\n"
1499 " return Fruit.Apple.toString();\n" 1847 " return Fruit.Apple.toString();\n"
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 EXPECT_VALID(lib); 2870 EXPECT_VALID(lib);
2523 Dart_SetFileModifiedCallback(NULL); 2871 Dart_SetFileModifiedCallback(NULL);
2524 2872
2525 // Modification of an exported library propagates. 2873 // Modification of an exported library propagates.
2526 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); 2874 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
2527 } 2875 }
2528 2876
2529 #endif // !PRODUCT 2877 #endif // !PRODUCT
2530 2878
2531 } // namespace dart 2879 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698