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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 async_task_listener_ = listener; | 1859 async_task_listener_ = listener; |
1860 async_task_listener_data_ = data; | 1860 async_task_listener_data_ = data; |
1861 UpdateState(); | 1861 UpdateState(); |
1862 } | 1862 } |
1863 | 1863 |
1864 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { | 1864 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { |
1865 if (in_debug_scope() || ignore_events()) return; | 1865 if (in_debug_scope() || ignore_events()) return; |
1866 | 1866 |
1867 if (async_task_listener_) { | 1867 if (async_task_listener_) { |
1868 async_task_listener_(type, id, async_task_listener_data_); | 1868 async_task_listener_(type, id, async_task_listener_data_); |
1869 // There are three types of event listeners: C++ message_handler, | 1869 if (!non_inspector_listener_exists()) return; |
1870 // JavaScript event listener and C++ event listener. | |
1871 // Currently inspector still uses C++ event listener and installs | |
1872 // more specific event listeners for part of events. Calling of | |
1873 // C++ event listener is redundant when more specific event listener | |
1874 // is presented. Other clients can install JavaScript event listener | |
1875 // (e.g. some of NodeJS module). | |
1876 bool non_inspector_listener_exists = | |
1877 message_handler_ != nullptr || | |
1878 (event_listener_.is_null() && !event_listener_->IsForeign()); | |
1879 if (!non_inspector_listener_exists) return; | |
1880 } | 1870 } |
1881 | 1871 |
1882 HandleScope scope(isolate_); | 1872 HandleScope scope(isolate_); |
1883 DebugScope debug_scope(this); | 1873 DebugScope debug_scope(this); |
1884 if (debug_scope.failed()) return; | 1874 if (debug_scope.failed()) return; |
1885 | 1875 |
1886 // Create the script collected state object. | 1876 // Create the script collected state object. |
1887 Handle<Object> event_data; | 1877 Handle<Object> event_data; |
1888 // Bail out and don't call debugger if exception. | 1878 // Bail out and don't call debugger if exception. |
1889 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), | 1879 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 event_listener_data_ }; | 1938 event_listener_data_ }; |
1949 Handle<JSReceiver> global = isolate_->global_proxy(); | 1939 Handle<JSReceiver> global = isolate_->global_proxy(); |
1950 MaybeHandle<Object> result = | 1940 MaybeHandle<Object> result = |
1951 Execution::Call(isolate_, Handle<JSFunction>::cast(event_listener_), | 1941 Execution::Call(isolate_, Handle<JSFunction>::cast(event_listener_), |
1952 global, arraysize(argv), argv); | 1942 global, arraysize(argv), argv); |
1953 CHECK(!result.is_null()); // Listeners must not throw. | 1943 CHECK(!result.is_null()); // Listeners must not throw. |
1954 } | 1944 } |
1955 in_debug_event_listener_ = previous; | 1945 in_debug_event_listener_ = previous; |
1956 } | 1946 } |
1957 | 1947 |
| 1948 void Debug::SetCompileEventListener(debug::CompileEventListener listener, |
| 1949 void* data) { |
| 1950 compile_event_listener_ = listener; |
| 1951 compile_event_listener_data_ = data; |
| 1952 UpdateState(); |
| 1953 } |
1958 | 1954 |
1959 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { | 1955 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { |
1960 if (ignore_events()) return; | 1956 if (ignore_events()) return; |
1961 if (script->type() != i::Script::TYPE_NORMAL && | 1957 if (script->type() != i::Script::TYPE_NORMAL && |
1962 script->type() != i::Script::TYPE_WASM) { | 1958 script->type() != i::Script::TYPE_WASM) { |
1963 return; | 1959 return; |
1964 } | 1960 } |
1965 SuppressDebug while_processing(this); | 1961 SuppressDebug while_processing(this); |
1966 | |
1967 bool in_nested_debug_scope = in_debug_scope(); | 1962 bool in_nested_debug_scope = in_debug_scope(); |
1968 HandleScope scope(isolate_); | |
1969 DebugScope debug_scope(this); | 1963 DebugScope debug_scope(this); |
1970 if (debug_scope.failed()) return; | 1964 if (debug_scope.failed()) return; |
1971 | 1965 |
| 1966 if (compile_event_listener_) { |
| 1967 compile_event_listener_(ToApiHandle<debug::Script>(script), |
| 1968 event != v8::AfterCompile, |
| 1969 compile_event_listener_data_); |
| 1970 if (!non_inspector_listener_exists()) return; |
| 1971 } |
| 1972 |
| 1973 HandleScope scope(isolate_); |
1972 // Create the compile state object. | 1974 // Create the compile state object. |
1973 Handle<Object> event_data; | 1975 Handle<Object> event_data; |
1974 // Bail out and don't call debugger if exception. | 1976 // Bail out and don't call debugger if exception. |
1975 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; | 1977 if (!MakeCompileEvent(script, event).ToHandle(&event_data)) return; |
1976 | 1978 |
1977 // Don't call NotifyMessageHandler if already in debug scope to avoid running | 1979 // Don't call NotifyMessageHandler if already in debug scope to avoid running |
1978 // nested command loop. | 1980 // nested command loop. |
1979 if (in_nested_debug_scope) { | 1981 if (in_nested_debug_scope) { |
1980 if (event_listener_.is_null()) return; | 1982 if (event_listener_.is_null()) return; |
1981 // Create the execution state. | 1983 // Create the execution state. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 UpdateState(); | 2157 UpdateState(); |
2156 if (handler == NULL && in_debug_scope()) { | 2158 if (handler == NULL && in_debug_scope()) { |
2157 // Send an empty command to the debugger if in a break to make JavaScript | 2159 // Send an empty command to the debugger if in a break to make JavaScript |
2158 // run again if the debugger is closed. | 2160 // run again if the debugger is closed. |
2159 EnqueueCommandMessage(Vector<const uint16_t>::empty()); | 2161 EnqueueCommandMessage(Vector<const uint16_t>::empty()); |
2160 } | 2162 } |
2161 } | 2163 } |
2162 | 2164 |
2163 void Debug::UpdateState() { | 2165 void Debug::UpdateState() { |
2164 bool is_active = message_handler_ != nullptr || !event_listener_.is_null() || | 2166 bool is_active = message_handler_ != nullptr || !event_listener_.is_null() || |
2165 async_task_listener_ != nullptr; | 2167 async_task_listener_ != nullptr || |
| 2168 compile_event_listener_ != nullptr; |
2166 if (is_active || in_debug_scope()) { | 2169 if (is_active || in_debug_scope()) { |
2167 // Note that the debug context could have already been loaded to | 2170 // Note that the debug context could have already been loaded to |
2168 // bootstrap test cases. | 2171 // bootstrap test cases. |
2169 isolate_->compilation_cache()->Disable(); | 2172 isolate_->compilation_cache()->Disable(); |
2170 is_active = Load(); | 2173 is_active = Load(); |
2171 } else if (is_loaded()) { | 2174 } else if (is_loaded()) { |
2172 isolate_->compilation_cache()->Enable(); | 2175 isolate_->compilation_cache()->Enable(); |
2173 Unload(); | 2176 Unload(); |
2174 } | 2177 } |
2175 is_active_ = is_active; | 2178 is_active_ = is_active; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2645 logger_->DebugEvent("Put", message.text()); | 2648 logger_->DebugEvent("Put", message.text()); |
2646 } | 2649 } |
2647 | 2650 |
2648 void LockingCommandMessageQueue::Clear() { | 2651 void LockingCommandMessageQueue::Clear() { |
2649 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2652 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2650 queue_.Clear(); | 2653 queue_.Clear(); |
2651 } | 2654 } |
2652 | 2655 |
2653 } // namespace internal | 2656 } // namespace internal |
2654 } // namespace v8 | 2657 } // namespace v8 |
OLD | NEW |