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 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 // Since we holding promise when at least one microtask is scheduled (inside | 1852 // Since we holding promise when at least one microtask is scheduled (inside |
1853 // PromiseReactionJobInfo), we can send cancel event in weak callback. | 1853 // PromiseReactionJobInfo), we can send cancel event in weak callback. |
1854 GlobalHandles::MakeWeak( | 1854 GlobalHandles::MakeWeak( |
1855 global_handle.location(), | 1855 global_handle.location(), |
1856 new CollectedCallbackData(global_handle.location(), async_id->value(), | 1856 new CollectedCallbackData(global_handle.location(), async_id->value(), |
1857 this, isolate_), | 1857 this, isolate_), |
1858 &ResetPromiseHandle, v8::WeakCallbackType::kParameter); | 1858 &ResetPromiseHandle, v8::WeakCallbackType::kParameter); |
1859 return async_id->value(); | 1859 return async_id->value(); |
1860 } | 1860 } |
1861 | 1861 |
| 1862 void Debug::SetAsyncTaskListener(debug::AsyncTaskListener listener, |
| 1863 void* data) { |
| 1864 async_task_listener_ = listener; |
| 1865 async_task_listener_data_ = data; |
| 1866 UpdateState(); |
| 1867 } |
| 1868 |
1862 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { | 1869 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) { |
1863 if (in_debug_scope() || ignore_events()) return; | 1870 if (in_debug_scope() || ignore_events()) return; |
1864 | 1871 |
| 1872 if (async_task_listener_) { |
| 1873 async_task_listener_(type, id, async_task_listener_data_); |
| 1874 // There are three types of event listeners: C++ message_handler, |
| 1875 // JavaScript event listener and C++ event listener. |
| 1876 // Currently inspector still uses C++ event listener and installs |
| 1877 // more specific event listeners for part of events. Calling of |
| 1878 // C++ event listener is redundant when more specific event listener |
| 1879 // is presented. Other clients can install JavaScript event listener |
| 1880 // (e.g. some of NodeJS module). |
| 1881 bool non_inspector_listener_exists = |
| 1882 message_handler_ != nullptr || |
| 1883 (event_listener_.is_null() && !event_listener_->IsForeign()); |
| 1884 if (!non_inspector_listener_exists) return; |
| 1885 } |
| 1886 |
1865 HandleScope scope(isolate_); | 1887 HandleScope scope(isolate_); |
1866 DebugScope debug_scope(this); | 1888 DebugScope debug_scope(this); |
1867 if (debug_scope.failed()) return; | 1889 if (debug_scope.failed()) return; |
1868 | 1890 |
1869 // Create the script collected state object. | 1891 // Create the script collected state object. |
1870 Handle<Object> event_data; | 1892 Handle<Object> event_data; |
1871 // Bail out and don't call debugger if exception. | 1893 // Bail out and don't call debugger if exception. |
1872 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), | 1894 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), |
1873 handle(Smi::FromInt(id), isolate_)) | 1895 handle(Smi::FromInt(id), isolate_)) |
1874 .ToHandle(&event_data)) | 1896 .ToHandle(&event_data)) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2137 message_handler_ = handler; | 2159 message_handler_ = handler; |
2138 UpdateState(); | 2160 UpdateState(); |
2139 if (handler == NULL && in_debug_scope()) { | 2161 if (handler == NULL && in_debug_scope()) { |
2140 // Send an empty command to the debugger if in a break to make JavaScript | 2162 // Send an empty command to the debugger if in a break to make JavaScript |
2141 // run again if the debugger is closed. | 2163 // run again if the debugger is closed. |
2142 EnqueueCommandMessage(Vector<const uint16_t>::empty()); | 2164 EnqueueCommandMessage(Vector<const uint16_t>::empty()); |
2143 } | 2165 } |
2144 } | 2166 } |
2145 | 2167 |
2146 void Debug::UpdateState() { | 2168 void Debug::UpdateState() { |
2147 bool is_active = message_handler_ != NULL || !event_listener_.is_null(); | 2169 bool is_active = message_handler_ != nullptr || !event_listener_.is_null() || |
| 2170 async_task_listener_ != nullptr; |
2148 if (is_active || in_debug_scope()) { | 2171 if (is_active || in_debug_scope()) { |
2149 // Note that the debug context could have already been loaded to | 2172 // Note that the debug context could have already been loaded to |
2150 // bootstrap test cases. | 2173 // bootstrap test cases. |
2151 isolate_->compilation_cache()->Disable(); | 2174 isolate_->compilation_cache()->Disable(); |
2152 is_active = Load(); | 2175 is_active = Load(); |
2153 } else if (is_loaded()) { | 2176 } else if (is_loaded()) { |
2154 isolate_->compilation_cache()->Enable(); | 2177 isolate_->compilation_cache()->Enable(); |
2155 Unload(); | 2178 Unload(); |
2156 } | 2179 } |
2157 is_active_ = is_active; | 2180 is_active_ = is_active; |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2625 logger_->DebugEvent("Put", message.text()); | 2648 logger_->DebugEvent("Put", message.text()); |
2626 } | 2649 } |
2627 | 2650 |
2628 void LockingCommandMessageQueue::Clear() { | 2651 void LockingCommandMessageQueue::Clear() { |
2629 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2652 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2630 queue_.Clear(); | 2653 queue_.Clear(); |
2631 } | 2654 } |
2632 | 2655 |
2633 } // namespace internal | 2656 } // namespace internal |
2634 } // namespace v8 | 2657 } // namespace v8 |
OLD | NEW |