 Chromium Code Reviews
 Chromium Code Reviews Issue 1316213005:
  Extract common debugger code for processing compile events  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1316213005:
  Extract common debugger code for processing compile events  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" | 
| 6 | 6 | 
| 7 #include "src/api.h" | 7 #include "src/api.h" | 
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" | 
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" | 
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" | 
| (...skipping 1795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1806 exception, uncaught, promise).ToHandle(&event_data)) { | 1806 exception, uncaught, promise).ToHandle(&event_data)) { | 
| 1807 return; | 1807 return; | 
| 1808 } | 1808 } | 
| 1809 | 1809 | 
| 1810 // Process debug event. | 1810 // Process debug event. | 
| 1811 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 1811 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 
| 1812 // Return to continue execution from where the exception was thrown. | 1812 // Return to continue execution from where the exception was thrown. | 
| 1813 } | 1813 } | 
| 1814 | 1814 | 
| 1815 | 1815 | 
| 1816 void Debug::OnCompileError(Handle<Script> script) { | |
| 1817 if (ignore_events()) return; | |
| 1818 SuppressDebug while_processing(this); | |
| 1819 | |
| 1820 if (in_debug_scope()) { | |
| 1821 ProcessCompileEventInDebugScope(v8::CompileError, script); | |
| 1822 return; | |
| 1823 } | |
| 1824 | |
| 1825 HandleScope scope(isolate_); | |
| 1826 DebugScope debug_scope(this); | |
| 1827 if (debug_scope.failed()) return; | |
| 1828 | |
| 1829 // Create the compile state object. | |
| 1830 Handle<Object> event_data; | |
| 1831 // Bail out and don't call debugger if exception. | |
| 1832 if (!MakeCompileEvent(script, v8::CompileError).ToHandle(&event_data)) return; | |
| 1833 | |
| 1834 // Process debug event. | |
| 1835 ProcessDebugEvent(v8::CompileError, Handle<JSObject>::cast(event_data), true); | |
| 1836 } | |
| 1837 | |
| 1838 | |
| 1839 void Debug::OnDebugBreak(Handle<Object> break_points_hit, | 1816 void Debug::OnDebugBreak(Handle<Object> break_points_hit, | 
| 1840 bool auto_continue) { | 1817 bool auto_continue) { | 
| 1841 // The caller provided for DebugScope. | 1818 // The caller provided for DebugScope. | 
| 1842 AssertDebugContext(); | 1819 AssertDebugContext(); | 
| 1843 // Bail out if there is no listener for this event | 1820 // Bail out if there is no listener for this event | 
| 1844 if (ignore_events()) return; | 1821 if (ignore_events()) return; | 
| 1845 | 1822 | 
| 1846 HandleScope scope(isolate_); | 1823 HandleScope scope(isolate_); | 
| 1847 // Create the event data object. | 1824 // Create the event data object. | 
| 1848 Handle<Object> event_data; | 1825 Handle<Object> event_data; | 
| 1849 // Bail out and don't call debugger if exception. | 1826 // Bail out and don't call debugger if exception. | 
| 1850 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; | 1827 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; | 
| 1851 | 1828 | 
| 1852 // Process debug event. | 1829 // Process debug event. | 
| 1853 ProcessDebugEvent(v8::Break, | 1830 ProcessDebugEvent(v8::Break, | 
| 1854 Handle<JSObject>::cast(event_data), | 1831 Handle<JSObject>::cast(event_data), | 
| 1855 auto_continue); | 1832 auto_continue); | 
| 1856 } | 1833 } | 
| 1857 | 1834 | 
| 1858 | 1835 | 
| 1836 void Debug::OnCompileError(Handle<Script> script) { | |
| 1837 ProcessCompileEvent(v8::CompileError, script); | |
| 1838 } | |
| 1839 | |
| 1840 | |
| 1859 void Debug::OnBeforeCompile(Handle<Script> script) { | 1841 void Debug::OnBeforeCompile(Handle<Script> script) { | 
| 1860 if (in_debug_scope() || ignore_events()) return; | 1842 ProcessCompileEvent(v8::BeforeCompile, script); | 
| 1861 SuppressDebug while_processing(this); | |
| 1862 | |
| 1863 HandleScope scope(isolate_); | |
| 1864 DebugScope debug_scope(this); | |
| 1865 if (debug_scope.failed()) return; | |
| 1866 | |
| 1867 // Create the event data object. | |
| 1868 Handle<Object> event_data; | |
| 1869 // Bail out and don't call debugger if exception. | |
| 1870 if (!MakeCompileEvent(script, v8::BeforeCompile).ToHandle(&event_data)) | |
| 1871 return; | |
| 1872 | |
| 1873 // Process debug event. | |
| 1874 ProcessDebugEvent(v8::BeforeCompile, | |
| 1875 Handle<JSObject>::cast(event_data), | |
| 1876 true); | |
| 1877 } | 1843 } | 
| 1878 | 1844 | 
| 1879 | 1845 | 
| 1880 // Handle debugger actions when a new script is compiled. | 1846 // Handle debugger actions when a new script is compiled. | 
| 1881 void Debug::OnAfterCompile(Handle<Script> script) { | 1847 void Debug::OnAfterCompile(Handle<Script> script) { | 
| 1882 if (ignore_events()) return; | 1848 ProcessCompileEvent(v8::AfterCompile, script); | 
| 1883 SuppressDebug while_processing(this); | |
| 1884 | |
| 1885 if (in_debug_scope()) { | |
| 1886 ProcessCompileEventInDebugScope(v8::AfterCompile, script); | |
| 1887 return; | |
| 1888 } | |
| 1889 | |
| 1890 HandleScope scope(isolate_); | |
| 1891 DebugScope debug_scope(this); | |
| 1892 if (debug_scope.failed()) return; | |
| 1893 | |
| 1894 // If debugging there might be script break points registered for this | |
| 1895 // script. Make sure that these break points are set. | |
| 1896 Handle<Object> argv[] = {Script::GetWrapper(script)}; | |
| 1897 if (CallFunction("UpdateScriptBreakPoints", arraysize(argv), argv) | |
| 1898 .is_null()) { | |
| 1899 return; | |
| 1900 } | |
| 1901 | |
| 1902 // Create the compile state object. | |
| 1903 Handle<Object> event_data; | |
| 1904 // Bail out and don't call debugger if exception. | |
| 1905 if (!MakeCompileEvent(script, v8::AfterCompile).ToHandle(&event_data)) return; | |
| 1906 | |
| 1907 // Process debug event. | |
| 1908 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true); | |
| 1909 } | 1849 } | 
| 1910 | 1850 | 
| 1911 | 1851 | 
| 1912 void Debug::OnPromiseEvent(Handle<JSObject> data) { | 1852 void Debug::OnPromiseEvent(Handle<JSObject> data) { | 
| 1913 if (in_debug_scope() || ignore_events()) return; | 1853 if (in_debug_scope() || ignore_events()) return; | 
| 1914 | 1854 | 
| 1915 HandleScope scope(isolate_); | 1855 HandleScope scope(isolate_); | 
| 1916 DebugScope debug_scope(this); | 1856 DebugScope debug_scope(this); | 
| 1917 if (debug_scope.failed()) return; | 1857 if (debug_scope.failed()) return; | 
| 1918 | 1858 | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2002 event_data, | 1942 event_data, | 
| 2003 event_listener_data_ }; | 1943 event_listener_data_ }; | 
| 2004 Handle<JSReceiver> global(isolate_->global_proxy()); | 1944 Handle<JSReceiver> global(isolate_->global_proxy()); | 
| 2005 Execution::TryCall(Handle<JSFunction>::cast(event_listener_), | 1945 Execution::TryCall(Handle<JSFunction>::cast(event_listener_), | 
| 2006 global, arraysize(argv), argv); | 1946 global, arraysize(argv), argv); | 
| 2007 } | 1947 } | 
| 2008 in_debug_event_listener_ = previous; | 1948 in_debug_event_listener_ = previous; | 
| 2009 } | 1949 } | 
| 2010 | 1950 | 
| 2011 | 1951 | 
| 2012 void Debug::ProcessCompileEventInDebugScope(v8::DebugEvent event, | 1952 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { | 
| 2013 Handle<Script> script) { | 1953 if (ignore_events()) return; | 
| 2014 if (event_listener_.is_null()) return; | 1954 SuppressDebug while_processing(this); | 
| 2015 | 1955 | 
| 1956 bool in_nested_debug_scope = in_debug_scope(); | |
| 1957 HandleScope scope(isolate_); | |
| 2016 DebugScope debug_scope(this); | 1958 DebugScope debug_scope(this); | 
| 2017 if (debug_scope.failed()) return; | 1959 if (debug_scope.failed()) return; | 
| 2018 | 1960 | 
| 1961 if (event == v8::AfterCompile) { | |
| 1962 // If debugging there might be script break points registered for this | |
| 1963 // script. Make sure that these break points are set. | |
| 1964 Handle<Object> argv[] = {Script::GetWrapper(script)}; | |
| 1965 if (CallFunction("UpdateScriptBreakPoints", arraysize(argv), argv) | |
| 1966 .is_null()) { | |
| 1967 return; | |
| 1968 } | |
| 1969 } | |
| 1970 | |
| 1971 // Create the compile state object. | |
| 2019 Handle<Object> event_data; | 1972 Handle<Object> event_data; | 
| 2020 // Bail out and don't call debugger if exception. | 1973 // Bail out and don't call debugger if exception. | 
| 2021 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; | 1974 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; | 
| 2022 | 1975 | 
| 2023 // Create the execution state. | 1976 // Don't call NotifyMessageHandler if already in debug scope to avoid running | 
| 2024 Handle<Object> exec_state; | 1977 // nested command loop. | 
| 2025 // Bail out and don't call debugger if exception. | 1978 if (in_nested_debug_scope) { | 
| 
yurys
2015/08/31 22:35:45
It is unfortunate that we cannot simply call Proce
 | |
| 2026 if (!MakeExecutionState().ToHandle(&exec_state)) return; | 1979 if (event_listener_.is_null()) return; | 
| 1980 // Create the execution state. | |
| 1981 Handle<Object> exec_state; | |
| 1982 // Bail out and don't call debugger if exception. | |
| 1983 if (!MakeExecutionState().ToHandle(&exec_state)) return; | |
| 2027 | 1984 | 
| 2028 CallEventCallback(event, exec_state, event_data, NULL); | 1985 CallEventCallback(event, exec_state, event_data, NULL); | 
| 1986 } else { | |
| 1987 // Process debug event. | |
| 1988 ProcessDebugEvent(event, Handle<JSObject>::cast(event_data), true); | |
| 1989 } | |
| 2029 } | 1990 } | 
| 2030 | 1991 | 
| 2031 | 1992 | 
| 2032 Handle<Context> Debug::GetDebugContext() { | 1993 Handle<Context> Debug::GetDebugContext() { | 
| 2033 if (!is_loaded()) return Handle<Context>(); | 1994 if (!is_loaded()) return Handle<Context>(); | 
| 2034 DebugScope debug_scope(this); | 1995 DebugScope debug_scope(this); | 
| 2035 if (debug_scope.failed()) return Handle<Context>(); | 1996 if (debug_scope.failed()) return Handle<Context>(); | 
| 2036 // The global handle may be destroyed soon after. Return it reboxed. | 1997 // The global handle may be destroyed soon after. Return it reboxed. | 
| 2037 return handle(*debug_context(), isolate_); | 1998 return handle(*debug_context(), isolate_); | 
| 2038 } | 1999 } | 
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2618 } | 2579 } | 
| 2619 | 2580 | 
| 2620 | 2581 | 
| 2621 void LockingCommandMessageQueue::Clear() { | 2582 void LockingCommandMessageQueue::Clear() { | 
| 2622 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2583 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 
| 2623 queue_.Clear(); | 2584 queue_.Clear(); | 
| 2624 } | 2585 } | 
| 2625 | 2586 | 
| 2626 } // namespace internal | 2587 } // namespace internal | 
| 2627 } // namespace v8 | 2588 } // namespace v8 | 
| OLD | NEW |