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

Side by Side Diff: test/cctest/test-debug.cc

Issue 2530093002: [debug] do not retroactively apply script break points. (Closed)
Patch Set: rebase Created 4 years 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 | « src/debug/liveedit.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 CHECK_EQ(1, break_point_hit_count); 1593 CHECK_EQ(1, break_point_hit_count);
1594 1594
1595 EnableScriptBreakPointFromJS(isolate, sbp); 1595 EnableScriptBreakPointFromJS(isolate, sbp);
1596 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1596 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1597 CHECK_EQ(2, break_point_hit_count); 1597 CHECK_EQ(2, break_point_hit_count);
1598 1598
1599 DisableScriptBreakPointFromJS(isolate, sbp); 1599 DisableScriptBreakPointFromJS(isolate, sbp);
1600 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1600 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1601 CHECK_EQ(2, break_point_hit_count); 1601 CHECK_EQ(2, break_point_hit_count);
1602 1602
1603 // Reload the script and get f again checking that the disabling survives.
1604 v8::Script::Compile(context, script, &origin)
1605 .ToLocalChecked()
1606 ->Run(context)
1607 .ToLocalChecked();
1608 f = v8::Local<v8::Function>::Cast(
1609 env->Global()->Get(context, v8_str(isolate, "f")).ToLocalChecked());
1610 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1611 CHECK_EQ(2, break_point_hit_count);
1612
1613 EnableScriptBreakPointFromJS(isolate, sbp);
1614 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1615 CHECK_EQ(3, break_point_hit_count);
1616
1617 v8::Debug::SetDebugEventListener(isolate, nullptr); 1603 v8::Debug::SetDebugEventListener(isolate, nullptr);
1618 CheckDebuggerUnloaded(isolate); 1604 CheckDebuggerUnloaded(isolate);
1619 } 1605 }
1620 1606
1621 1607
1622 // Test conditional script break points. 1608 // Test conditional script break points.
1623 TEST(ConditionalScriptBreakPoint) { 1609 TEST(ConditionalScriptBreakPoint) {
1624 break_point_hit_count = 0; 1610 break_point_hit_count = 0;
1625 DebugLocalContext env; 1611 DebugLocalContext env;
1626 v8::HandleScope scope(env->GetIsolate()); 1612 v8::HandleScope scope(env->GetIsolate());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1650 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1665 CHECK_EQ(1, break_point_hit_count); 1651 CHECK_EQ(1, break_point_hit_count);
1666 1652
1667 ChangeScriptBreakPointConditionFromJS(env->GetIsolate(), sbp1, "x % 2 == 0"); 1653 ChangeScriptBreakPointConditionFromJS(env->GetIsolate(), sbp1, "x % 2 == 0");
1668 break_point_hit_count = 0; 1654 break_point_hit_count = 0;
1669 for (int i = 0; i < 10; i++) { 1655 for (int i = 0; i < 10; i++) {
1670 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked(); 1656 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1671 } 1657 }
1672 CHECK_EQ(5, break_point_hit_count); 1658 CHECK_EQ(5, break_point_hit_count);
1673 1659
1674 // Reload the script and get f again checking that the condition survives.
1675 v8::Script::Compile(context, script, &origin)
1676 .ToLocalChecked()
1677 ->Run(context)
1678 .ToLocalChecked();
1679 f = v8::Local<v8::Function>::Cast(
1680 env->Global()
1681 ->Get(context, v8_str(env->GetIsolate(), "f"))
1682 .ToLocalChecked());
1683
1684 break_point_hit_count = 0;
1685 for (int i = 0; i < 10; i++) {
1686 f->Call(env.context(), env->Global(), 0, NULL).ToLocalChecked();
1687 }
1688 CHECK_EQ(5, break_point_hit_count);
1689
1690 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 1660 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1691 CheckDebuggerUnloaded(env->GetIsolate()); 1661 CheckDebuggerUnloaded(env->GetIsolate());
1692 } 1662 }
1693
1694
1695 // Test that script break points survive when a script is reloaded.
1696 TEST(ScriptBreakPointReload) {
1697 break_point_hit_count = 0;
1698 DebugLocalContext env;
1699 v8::HandleScope scope(env->GetIsolate());
1700 env.ExposeDebug();
1701
1702 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1703 DebugEventBreakPointHitCount);
1704
1705 v8::Local<v8::Context> context = env.context();
1706 v8::Local<v8::Function> f;
1707 v8::Local<v8::String> script = v8_str(env->GetIsolate(),
1708 "function f() {\n"
1709 " function h() {\n"
1710 " a = 0; // line 2\n"
1711 " }\n"
1712 " b = 1; // line 4\n"
1713 " return h();\n"
1714 "}");
1715
1716 v8::ScriptOrigin origin_1 = v8::ScriptOrigin(v8_str(env->GetIsolate(), "1"));
1717 v8::ScriptOrigin origin_2 = v8::ScriptOrigin(v8_str(env->GetIsolate(), "2"));
1718
1719 // Set a script break point before the script is loaded.
1720 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "1", 2, 0);
1721
1722 // Compile the script and get the function.
1723 v8::Script::Compile(context, script, &origin_1)
1724 .ToLocalChecked()
1725 ->Run(context)
1726 .ToLocalChecked();
1727 f = v8::Local<v8::Function>::Cast(
1728 env->Global()
1729 ->Get(context, v8_str(env->GetIsolate(), "f"))
1730 .ToLocalChecked());
1731
1732 // Call f and check that the script break point is active.
1733 break_point_hit_count = 0;
1734 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1735 CHECK_EQ(1, break_point_hit_count);
1736
1737 // Compile the script again with a different script data and get the
1738 // function.
1739 v8::Script::Compile(context, script, &origin_2)
1740 .ToLocalChecked()
1741 ->Run(context)
1742 .ToLocalChecked();
1743 f = v8::Local<v8::Function>::Cast(
1744 env->Global()
1745 ->Get(context, v8_str(env->GetIsolate(), "f"))
1746 .ToLocalChecked());
1747
1748 // Call f and check that no break points are set.
1749 break_point_hit_count = 0;
1750 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1751 CHECK_EQ(0, break_point_hit_count);
1752
1753 // Compile the script again and get the function.
1754 v8::Script::Compile(context, script, &origin_1)
1755 .ToLocalChecked()
1756 ->Run(context)
1757 .ToLocalChecked();
1758 f = v8::Local<v8::Function>::Cast(
1759 env->Global()
1760 ->Get(context, v8_str(env->GetIsolate(), "f"))
1761 .ToLocalChecked());
1762
1763 // Call f and check that the script break point is active.
1764 break_point_hit_count = 0;
1765 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1766 CHECK_EQ(1, break_point_hit_count);
1767
1768 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
1769 CheckDebuggerUnloaded(env->GetIsolate());
1770 }
1771 1663
1772 1664
1773 // Test when several scripts has the same script data 1665 // Test when several scripts has the same script data
1774 TEST(ScriptBreakPointMultiple) { 1666 TEST(ScriptBreakPointMultiple) {
1775 break_point_hit_count = 0; 1667 break_point_hit_count = 0;
1776 DebugLocalContext env; 1668 DebugLocalContext env;
1777 v8::HandleScope scope(env->GetIsolate()); 1669 v8::HandleScope scope(env->GetIsolate());
1778 env.ExposeDebug(); 1670 env.ExposeDebug();
1779 1671
1780 v8::Debug::SetDebugEventListener(env->GetIsolate(), 1672 v8::Debug::SetDebugEventListener(env->GetIsolate(),
1781 DebugEventBreakPointHitCount); 1673 DebugEventBreakPointHitCount);
1782 1674
1783 v8::Local<v8::Context> context = env.context(); 1675 v8::Local<v8::Context> context = env.context();
1784 v8::Local<v8::Function> f; 1676 v8::Local<v8::Function> f;
1785 v8::Local<v8::String> script_f = v8_str(env->GetIsolate(), 1677 v8::Local<v8::String> script_f = v8_str(env->GetIsolate(),
1786 "function f() {\n" 1678 "function f() {\n"
1787 " a = 0; // line 1\n" 1679 " a = 0; // line 1\n"
1788 "}"); 1680 "}");
1789 1681
1790 v8::Local<v8::Function> g; 1682 v8::Local<v8::Function> g;
1791 v8::Local<v8::String> script_g = v8_str(env->GetIsolate(), 1683 v8::Local<v8::String> script_g = v8_str(env->GetIsolate(),
1792 "function g() {\n" 1684 "function g() {\n"
1793 " b = 0; // line 1\n" 1685 " b = 0; // line 1\n"
1794 "}"); 1686 "}");
1795 1687
1796 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(env->GetIsolate(), "test")); 1688 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str(env->GetIsolate(), "test"));
1797 1689
1798 // Set a script break point before the scripts are loaded.
1799 int sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
1800
1801 // Compile the scripts with same script data and get the functions. 1690 // Compile the scripts with same script data and get the functions.
1802 v8::Script::Compile(context, script_f, &origin) 1691 v8::Script::Compile(context, script_f, &origin)
1803 .ToLocalChecked() 1692 .ToLocalChecked()
1804 ->Run(context) 1693 ->Run(context)
1805 .ToLocalChecked(); 1694 .ToLocalChecked();
1806 f = v8::Local<v8::Function>::Cast( 1695 f = v8::Local<v8::Function>::Cast(
1807 env->Global() 1696 env->Global()
1808 ->Get(context, v8_str(env->GetIsolate(), "f")) 1697 ->Get(context, v8_str(env->GetIsolate(), "f"))
1809 .ToLocalChecked()); 1698 .ToLocalChecked());
1810 v8::Script::Compile(context, script_g, &origin) 1699 v8::Script::Compile(context, script_g, &origin)
1811 .ToLocalChecked() 1700 .ToLocalChecked()
1812 ->Run(context) 1701 ->Run(context)
1813 .ToLocalChecked(); 1702 .ToLocalChecked();
1814 g = v8::Local<v8::Function>::Cast( 1703 g = v8::Local<v8::Function>::Cast(
1815 env->Global() 1704 env->Global()
1816 ->Get(context, v8_str(env->GetIsolate(), "g")) 1705 ->Get(context, v8_str(env->GetIsolate(), "g"))
1817 .ToLocalChecked()); 1706 .ToLocalChecked());
1818 1707
1708 int sbp = SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test", 1, 0);
1709
1819 // Call f and g and check that the script break point is active. 1710 // Call f and g and check that the script break point is active.
1820 break_point_hit_count = 0; 1711 break_point_hit_count = 0;
1821 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1712 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1822 CHECK_EQ(1, break_point_hit_count); 1713 CHECK_EQ(1, break_point_hit_count);
1823 g->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1714 g->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1824 CHECK_EQ(2, break_point_hit_count); 1715 CHECK_EQ(2, break_point_hit_count);
1825 1716
1826 // Clear the script break point. 1717 // Clear the script break point.
1827 ClearBreakPointFromJS(env->GetIsolate(), sbp); 1718 ClearBreakPointFromJS(env->GetIsolate(), sbp);
1828 1719
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 v8_str(env->GetIsolate(), 1755 v8_str(env->GetIsolate(),
1865 "function f() {\n" 1756 "function f() {\n"
1866 " a = 0; // line 8 as this script has line offset 7\n" 1757 " a = 0; // line 8 as this script has line offset 7\n"
1867 " b = 0; // line 9 as this script has line offset 7\n" 1758 " b = 0; // line 9 as this script has line offset 7\n"
1868 "}"); 1759 "}");
1869 1760
1870 // Create script origin both name and line offset. 1761 // Create script origin both name and line offset.
1871 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), "test.html"), 1762 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), "test.html"),
1872 v8::Integer::New(env->GetIsolate(), 7)); 1763 v8::Integer::New(env->GetIsolate(), 7));
1873 1764
1874 // Set two script break points before the script is loaded.
1875 int sbp1 =
1876 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 8, 0);
1877 int sbp2 =
1878 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0);
1879
1880 // Compile the script and get the function. 1765 // Compile the script and get the function.
1881 v8::Script::Compile(context, script, &origin) 1766 v8::Script::Compile(context, script, &origin)
1882 .ToLocalChecked() 1767 .ToLocalChecked()
1883 ->Run(context) 1768 ->Run(context)
1884 .ToLocalChecked(); 1769 .ToLocalChecked();
1770
1771 int sbp1 =
1772 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 8, 0);
1773 int sbp2 =
1774 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 9, 0);
1775
1885 f = v8::Local<v8::Function>::Cast( 1776 f = v8::Local<v8::Function>::Cast(
1886 env->Global() 1777 env->Global()
1887 ->Get(context, v8_str(env->GetIsolate(), "f")) 1778 ->Get(context, v8_str(env->GetIsolate(), "f"))
1888 .ToLocalChecked()); 1779 .ToLocalChecked());
1889 1780
1890 // Call f and check that the script break point is active. 1781 // Call f and check that the script break point is active.
1891 break_point_hit_count = 0; 1782 break_point_hit_count = 0;
1892 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1783 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
1893 CHECK_EQ(2, break_point_hit_count); 1784 CHECK_EQ(2, break_point_hit_count);
1894 1785
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 " a = 2; // line 4\n" 1831 " a = 2; // line 4\n"
1941 " /* xx */ function g() { // line 5\n" 1832 " /* xx */ function g() { // line 5\n"
1942 " function h() { // line 6\n" 1833 " function h() { // line 6\n"
1943 " a = 3; // line 7\n" 1834 " a = 3; // line 7\n"
1944 " }\n" 1835 " }\n"
1945 " h(); // line 9\n" 1836 " h(); // line 9\n"
1946 " a = 4; // line 10\n" 1837 " a = 4; // line 10\n"
1947 " }\n" 1838 " }\n"
1948 " a=5; // line 12"); 1839 " a=5; // line 12");
1949 1840
1950 // Set a couple script break point before the script is loaded. 1841 // Compile the script and get the function.
1842 break_point_hit_count = 0;
1843 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), "test.html"),
1844 v8::Integer::New(env->GetIsolate(), 0));
1845 v8::Local<v8::Script> compiled =
1846 v8::Script::Compile(context, script, &origin).ToLocalChecked();
1847
1951 int sbp1 = 1848 int sbp1 =
1952 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 0, -1); 1849 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 0, -1);
1953 int sbp2 = 1850 int sbp2 =
1954 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 1, -1); 1851 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 1, -1);
1955 int sbp3 = 1852 int sbp3 =
1956 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 5, -1); 1853 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 5, -1);
1957 1854
1958 // Compile the script and get the function. 1855 compiled->Run(context).ToLocalChecked();
1959 break_point_hit_count = 0; 1856
1960 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), "test.html"),
1961 v8::Integer::New(env->GetIsolate(), 0));
1962 v8::Script::Compile(context, script, &origin)
1963 .ToLocalChecked()
1964 ->Run(context)
1965 .ToLocalChecked();
1966 f = v8::Local<v8::Function>::Cast( 1857 f = v8::Local<v8::Function>::Cast(
1967 env->Global() 1858 env->Global()
1968 ->Get(context, v8_str(env->GetIsolate(), "f")) 1859 ->Get(context, v8_str(env->GetIsolate(), "f"))
1969 .ToLocalChecked()); 1860 .ToLocalChecked());
1970 g = v8::Local<v8::Function>::Cast( 1861 g = v8::Local<v8::Function>::Cast(
1971 env->Global() 1862 env->Global()
1972 ->Get(context, v8_str(env->GetIsolate(), "g")) 1863 ->Get(context, v8_str(env->GetIsolate(), "g"))
1973 .ToLocalChecked()); 1864 .ToLocalChecked());
1974 1865
1975 // Check that a break point was hit when the script was run. 1866 // Check that a break point was hit when the script was run.
(...skipping 25 matching lines...) Expand all
2001 // more. 1892 // more.
2002 ClearBreakPointFromJS(env->GetIsolate(), sbp2); 1893 ClearBreakPointFromJS(env->GetIsolate(), sbp2);
2003 ClearBreakPointFromJS(env->GetIsolate(), sbp4); 1894 ClearBreakPointFromJS(env->GetIsolate(), sbp4);
2004 int sbp5 = 1895 int sbp5 =
2005 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 4, -1); 1896 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 4, -1);
2006 break_point_hit_count = 0; 1897 break_point_hit_count = 0;
2007 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1898 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2008 g->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1899 g->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2009 CHECK_EQ(0, break_point_hit_count); 1900 CHECK_EQ(0, break_point_hit_count);
2010 1901
2011 // Reload the script which should hit two break points.
2012 break_point_hit_count = 0;
2013 v8::Script::Compile(context, script, &origin)
2014 .ToLocalChecked()
2015 ->Run(context)
2016 .ToLocalChecked();
2017 CHECK_EQ(2, break_point_hit_count);
2018 CHECK_EQ(0, StrLength(last_function_hit));
2019
2020 // Set a break point in the code after the last function decleration. 1902 // Set a break point in the code after the last function decleration.
2021 int sbp6 = 1903 int sbp6 =
2022 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 12, -1); 1904 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 12, -1);
2023 1905
2024 // Reload the script which should hit three break points. 1906 // Reloading the script should not hit any break points.
2025 break_point_hit_count = 0;
2026 v8::Script::Compile(context, script, &origin)
2027 .ToLocalChecked()
2028 ->Run(context)
2029 .ToLocalChecked();
2030 CHECK_EQ(3, break_point_hit_count);
2031 CHECK_EQ(0, StrLength(last_function_hit));
2032
2033 // Clear the last break points, and reload the script which should not hit any
2034 // break points.
2035 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
2036 ClearBreakPointFromJS(env->GetIsolate(), sbp5);
2037 ClearBreakPointFromJS(env->GetIsolate(), sbp6);
2038 break_point_hit_count = 0; 1907 break_point_hit_count = 0;
2039 v8::Script::Compile(context, script, &origin) 1908 v8::Script::Compile(context, script, &origin)
2040 .ToLocalChecked() 1909 .ToLocalChecked()
2041 ->Run(context) 1910 ->Run(context)
2042 .ToLocalChecked(); 1911 .ToLocalChecked();
2043 CHECK_EQ(0, break_point_hit_count); 1912 CHECK_EQ(0, break_point_hit_count);
2044 1913
1914 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
1915 ClearBreakPointFromJS(env->GetIsolate(), sbp5);
1916 ClearBreakPointFromJS(env->GetIsolate(), sbp6);
1917
2045 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 1918 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2046 CheckDebuggerUnloaded(env->GetIsolate()); 1919 CheckDebuggerUnloaded(env->GetIsolate());
2047 } 1920 }
2048 1921
2049 1922
2050 // Test top level script break points set on lines. 1923 // Test top level script break points set on lines.
2051 TEST(ScriptBreakPointLineTopLevel) { 1924 TEST(ScriptBreakPointLineTopLevel) {
2052 DebugLocalContext env; 1925 DebugLocalContext env;
2053 v8::HandleScope scope(env->GetIsolate()); 1926 v8::HandleScope scope(env->GetIsolate());
2054 env.ExposeDebug(); 1927 env.ExposeDebug();
(...skipping 20 matching lines...) Expand all
2075 1948
2076 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask); 1949 CcTest::CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask);
2077 1950
2078 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); 1951 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
2079 1952
2080 // Call f and check that there was no break points. 1953 // Call f and check that there was no break points.
2081 break_point_hit_count = 0; 1954 break_point_hit_count = 0;
2082 f->Call(context, env->Global(), 0, NULL).ToLocalChecked(); 1955 f->Call(context, env->Global(), 0, NULL).ToLocalChecked();
2083 CHECK_EQ(0, break_point_hit_count); 1956 CHECK_EQ(0, break_point_hit_count);
2084 1957
2085 // Recompile and run script and check that break point was hit. 1958 // Recompile and run script and check that break point was not reapplied.
2086 break_point_hit_count = 0; 1959 break_point_hit_count = 0;
2087 CompileRunWithOrigin(script, "test.html"); 1960 CompileRunWithOrigin(script, "test.html");
2088 CHECK_EQ(1, break_point_hit_count);
2089
2090 // Call f and check that there are still no break points.
2091 break_point_hit_count = 0;
2092 f = v8::Local<v8::Function>::Cast(
2093 env->Global()
2094 ->Get(context, v8_str(env->GetIsolate(), "f"))
2095 .ToLocalChecked());
2096 CHECK_EQ(0, break_point_hit_count); 1961 CHECK_EQ(0, break_point_hit_count);
2097 1962
2098 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 1963 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2099 CheckDebuggerUnloaded(env->GetIsolate()); 1964 CheckDebuggerUnloaded(env->GetIsolate());
2100 } 1965 }
2101 1966
2102 1967
2103 // Test that it is possible to add and remove break points in a top level 1968 // Test that it is possible to add and remove break points in a top level
2104 // function which has no references but has not been collected yet. 1969 // function which has no references but has not been collected yet.
2105 TEST(ScriptBreakPointTopLevelCrash) { 1970 TEST(ScriptBreakPointTopLevelCrash) {
2106 DebugLocalContext env; 1971 DebugLocalContext env;
2107 v8::HandleScope scope(env->GetIsolate()); 1972 v8::HandleScope scope(env->GetIsolate());
2108 env.ExposeDebug(); 1973 env.ExposeDebug();
2109 1974
2110 v8::Debug::SetDebugEventListener(env->GetIsolate(), 1975 v8::Debug::SetDebugEventListener(env->GetIsolate(),
2111 DebugEventBreakPointHitCount); 1976 DebugEventBreakPointHitCount);
2112 1977
2113 v8::Local<v8::String> script_source = v8_str(env->GetIsolate(), 1978 CompileRunWithOrigin(
2114 "function f() {\n" 1979 "function f() {\n"
2115 " return 0;\n" 1980 " return 0;\n"
2116 "}\n" 1981 "}\n",
2117 "f()"); 1982 "test.html");
1983 int sbp1 =
1984 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 1, -1);
1985 break_point_hit_count = 0;
2118 1986
2119 int sbp1 = 1987 CompileRun("f();");
2120 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); 1988
2121 { 1989 CHECK_EQ(1, break_point_hit_count);
2122 v8::HandleScope scope(env->GetIsolate());
2123 break_point_hit_count = 0;
2124 CompileRunWithOrigin(script_source, "test.html");
2125 CHECK_EQ(1, break_point_hit_count);
2126 }
2127 1990
2128 int sbp2 = 1991 int sbp2 =
2129 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1); 1992 SetScriptBreakPointByNameFromJS(env->GetIsolate(), "test.html", 3, -1);
2130 ClearBreakPointFromJS(env->GetIsolate(), sbp1); 1993 ClearBreakPointFromJS(env->GetIsolate(), sbp1);
2131 ClearBreakPointFromJS(env->GetIsolate(), sbp2); 1994 ClearBreakPointFromJS(env->GetIsolate(), sbp2);
2132 1995
2133 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 1996 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
2134 CheckDebuggerUnloaded(env->GetIsolate()); 1997 CheckDebuggerUnloaded(env->GetIsolate());
2135 } 1998 }
2136 1999
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 env.ExposeDebug(); 3494 env.ExposeDebug();
3632 3495
3633 // Register a debug event listener which counts. 3496 // Register a debug event listener which counts.
3634 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter); 3497 v8::Debug::SetDebugEventListener(env->GetIsolate(), DebugEventCounter);
3635 3498
3636 v8::Local<v8::Context> context = env.context(); 3499 v8::Local<v8::Context> context = env.context();
3637 // Create a script that returns a function. 3500 // Create a script that returns a function.
3638 const char* src = "(function (evt) {})"; 3501 const char* src = "(function (evt) {})";
3639 const char* script_name = "StepInHandlerTest"; 3502 const char* script_name = "StepInHandlerTest";
3640 3503
3641 // Set breakpoint in the script.
3642 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1);
3643 break_point_hit_count = 0;
3644
3645 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), script_name), 3504 v8::ScriptOrigin origin(v8_str(env->GetIsolate(), script_name),
3646 v8::Integer::New(env->GetIsolate(), 0)); 3505 v8::Integer::New(env->GetIsolate(), 0));
3647 v8::Local<v8::Script> script = 3506 v8::Local<v8::Script> script =
3648 v8::Script::Compile(context, v8_str(env->GetIsolate(), src), &origin) 3507 v8::Script::Compile(context, v8_str(env->GetIsolate(), src), &origin)
3649 .ToLocalChecked(); 3508 .ToLocalChecked();
3509
3510 // Set breakpoint in the script.
3511 SetScriptBreakPointByNameFromJS(env->GetIsolate(), script_name, 0, -1);
3512 break_point_hit_count = 0;
3513
3650 v8::Local<v8::Value> r = script->Run(context).ToLocalChecked(); 3514 v8::Local<v8::Value> r = script->Run(context).ToLocalChecked();
3651 3515
3652 CHECK(r->IsFunction()); 3516 CHECK(r->IsFunction());
3653 CHECK_EQ(1, break_point_hit_count); 3517 CHECK_EQ(1, break_point_hit_count);
3654 3518
3655 // Get rid of the debug event listener. 3519 // Get rid of the debug event listener.
3656 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 3520 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
3657 CheckDebuggerUnloaded(env->GetIsolate()); 3521 CheckDebuggerUnloaded(env->GetIsolate());
3658 } 3522 }
3659 3523
(...skipping 3134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6794 "function foo() {\n" 6658 "function foo() {\n"
6795 " try { throw new Error(); } catch (e) {}\n" 6659 " try { throw new Error(); } catch (e) {}\n"
6796 "}\n" 6660 "}\n"
6797 "debugger;\n" 6661 "debugger;\n"
6798 "foo();\n" 6662 "foo();\n"
6799 "foo();\n"); 6663 "foo();\n");
6800 6664
6801 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr); 6665 v8::Debug::SetDebugEventListener(env->GetIsolate(), nullptr);
6802 CHECK_EQ(break_point_hit_count, 4); 6666 CHECK_EQ(break_point_hit_count, 4);
6803 } 6667 }
OLDNEW
« no previous file with comments | « src/debug/liveedit.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698