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

Side by Side Diff: src/debug/debug.cc

Issue 2623313005: [inspector] introduced debug::SetAsyncTaskListener (Closed)
Patch Set: fixed compilation Created 3 years, 11 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
OLDNEW
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 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 1675
1676 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script, 1676 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script,
1677 v8::DebugEvent type) { 1677 v8::DebugEvent type) {
1678 // Create the compile event object. 1678 // Create the compile event object.
1679 Handle<Object> script_wrapper = Script::GetWrapper(script); 1679 Handle<Object> script_wrapper = Script::GetWrapper(script);
1680 Handle<Object> argv[] = { script_wrapper, 1680 Handle<Object> argv[] = { script_wrapper,
1681 isolate_->factory()->NewNumberFromInt(type) }; 1681 isolate_->factory()->NewNumberFromInt(type) };
1682 return CallFunction("MakeCompileEvent", arraysize(argv), argv); 1682 return CallFunction("MakeCompileEvent", arraysize(argv), argv);
1683 } 1683 }
1684 1684
1685 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<Smi> type, Handle<Smi> id, 1685 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<Smi> type,
1686 Handle<Smi> name) { 1686 Handle<Smi> id) {
1687 DCHECK(id->IsNumber()); 1687 DCHECK(id->IsNumber());
1688 // Create the async task event object. 1688 // Create the async task event object.
1689 Handle<Object> argv[] = {type, id, name}; 1689 Handle<Object> argv[] = {type, id};
1690 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv); 1690 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv);
1691 } 1691 }
1692 1692
1693 1693
1694 void Debug::OnThrow(Handle<Object> exception) { 1694 void Debug::OnThrow(Handle<Object> exception) {
1695 if (in_debug_scope() || ignore_events()) return; 1695 if (in_debug_scope() || ignore_events()) return;
1696 PrepareStepOnThrow(); 1696 PrepareStepOnThrow();
1697 // Temporarily clear any scheduled_exception to allow evaluating 1697 // Temporarily clear any scheduled_exception to allow evaluating
1698 // JavaScript from the debug event handler. 1698 // JavaScript from the debug event handler.
1699 HandleScope scope(isolate_); 1699 HandleScope scope(isolate_);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 CollectedCallbackData(Object** location, int id, Debug* debug, 1814 CollectedCallbackData(Object** location, int id, Debug* debug,
1815 Isolate* isolate) 1815 Isolate* isolate)
1816 : location(location), id(id), debug(debug), isolate(isolate) {} 1816 : location(location), id(id), debug(debug), isolate(isolate) {}
1817 }; 1817 };
1818 1818
1819 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) { 1819 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) {
1820 std::unique_ptr<CollectedCallbackData> data( 1820 std::unique_ptr<CollectedCallbackData> data(
1821 reinterpret_cast<CollectedCallbackData*>(info.GetParameter())); 1821 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()));
1822 if (!data->debug->is_active()) return; 1822 if (!data->debug->is_active()) return;
1823 HandleScope scope(data->isolate); 1823 HandleScope scope(data->isolate);
1824 data->debug->OnAsyncTaskEvent(debug::kDebugCancel, data->id, 1824 data->debug->OnAsyncTaskEvent(debug::kDebugPromiseCollected, data->id);
1825 kDebugPromiseCollected);
1826 } 1825 }
1827 1826
1828 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) { 1827 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) {
1829 CollectedCallbackData* data = 1828 CollectedCallbackData* data =
1830 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()); 1829 reinterpret_cast<CollectedCallbackData*>(info.GetParameter());
1831 GlobalHandles::Destroy(data->location); 1830 GlobalHandles::Destroy(data->location);
1832 info.SetSecondPassCallback(&SendAsyncTaskEventCancel); 1831 info.SetSecondPassCallback(&SendAsyncTaskEventCancel);
1833 } 1832 }
1834 } // namespace 1833 } // namespace
1835 1834
(...skipping 17 matching lines...) Expand all
1853 // 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
1854 // PromiseReactionJobInfo), we can send cancel event in weak callback. 1853 // PromiseReactionJobInfo), we can send cancel event in weak callback.
1855 GlobalHandles::MakeWeak( 1854 GlobalHandles::MakeWeak(
1856 global_handle.location(), 1855 global_handle.location(),
1857 new CollectedCallbackData(global_handle.location(), async_id->value(), 1856 new CollectedCallbackData(global_handle.location(), async_id->value(),
1858 this, isolate_), 1857 this, isolate_),
1859 &ResetPromiseHandle, v8::WeakCallbackType::kParameter); 1858 &ResetPromiseHandle, v8::WeakCallbackType::kParameter);
1860 return async_id->value(); 1859 return async_id->value();
1861 } 1860 }
1862 1861
1863 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id, 1862 void Debug::SetAsyncTaskListener(debug::AsyncTaskListener listener,
1864 PromiseDebugActionName name) { 1863 void* data) {
1864 async_task_listener_ = listener;
1865 async_task_listener_data_ = data;
1866 UpdateState();
1867 }
1868
1869 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id) {
1865 if (in_debug_scope() || ignore_events()) return; 1870 if (in_debug_scope() || ignore_events()) return;
1866 1871
1872 if (async_task_listener_) {
1873 async_task_listener_(type, id, async_task_listener_data_);
1874 bool only_foreign_listener_present =
jgruber 2017/01/13 16:38:38 Not sure this was what dgozman@ intended in his pr
kozy 2017/01/13 17:05:08 added comment and renamed variable.
1875 message_handler_ == nullptr &&
1876 (event_listener_.is_null() || event_listener_->IsForeign());
1877 if (only_foreign_listener_present) return;
1878 }
1879
1867 HandleScope scope(isolate_); 1880 HandleScope scope(isolate_);
1868 DebugScope debug_scope(this); 1881 DebugScope debug_scope(this);
1869 if (debug_scope.failed()) return; 1882 if (debug_scope.failed()) return;
1870 1883
1871 // Create the script collected state object. 1884 // Create the script collected state object.
1872 Handle<Object> event_data; 1885 Handle<Object> event_data;
1873 // Bail out and don't call debugger if exception. 1886 // Bail out and don't call debugger if exception.
1874 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_), 1887 if (!MakeAsyncTaskEvent(handle(Smi::FromInt(type), isolate_),
1875 handle(Smi::FromInt(id), isolate_), 1888 handle(Smi::FromInt(id), isolate_))
1876 handle(Smi::FromInt(name), isolate_))
1877 .ToHandle(&event_data)) 1889 .ToHandle(&event_data))
1878 return; 1890 return;
1879 1891
1880 // Process debug event. 1892 // Process debug event.
1881 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data), 1893 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data),
1882 true); 1894 true);
1883 } 1895 }
1884 1896
1885 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data, 1897 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data,
1886 bool auto_continue) { 1898 bool auto_continue) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 message_handler_ = handler; 2152 message_handler_ = handler;
2141 UpdateState(); 2153 UpdateState();
2142 if (handler == NULL && in_debug_scope()) { 2154 if (handler == NULL && in_debug_scope()) {
2143 // Send an empty command to the debugger if in a break to make JavaScript 2155 // Send an empty command to the debugger if in a break to make JavaScript
2144 // run again if the debugger is closed. 2156 // run again if the debugger is closed.
2145 EnqueueCommandMessage(Vector<const uint16_t>::empty()); 2157 EnqueueCommandMessage(Vector<const uint16_t>::empty());
2146 } 2158 }
2147 } 2159 }
2148 2160
2149 void Debug::UpdateState() { 2161 void Debug::UpdateState() {
2150 bool is_active = message_handler_ != NULL || !event_listener_.is_null(); 2162 bool is_active = message_handler_ != NULL || !event_listener_.is_null() ||
jgruber 2017/01/13 16:38:38 Nit: You could replace the other NULL here while y
kozy 2017/01/13 17:05:08 Done.
2163 async_task_listener_ != nullptr;
2151 if (is_active || in_debug_scope()) { 2164 if (is_active || in_debug_scope()) {
2152 // Note that the debug context could have already been loaded to 2165 // Note that the debug context could have already been loaded to
2153 // bootstrap test cases. 2166 // bootstrap test cases.
2154 isolate_->compilation_cache()->Disable(); 2167 isolate_->compilation_cache()->Disable();
2155 is_active = Load(); 2168 is_active = Load();
2156 } else if (is_loaded()) { 2169 } else if (is_loaded()) {
2157 isolate_->compilation_cache()->Enable(); 2170 isolate_->compilation_cache()->Enable();
2158 Unload(); 2171 Unload();
2159 } 2172 }
2160 is_active_ = is_active; 2173 is_active_ = is_active;
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 logger_->DebugEvent("Put", message.text()); 2641 logger_->DebugEvent("Put", message.text());
2629 } 2642 }
2630 2643
2631 void LockingCommandMessageQueue::Clear() { 2644 void LockingCommandMessageQueue::Clear() {
2632 base::LockGuard<base::Mutex> lock_guard(&mutex_); 2645 base::LockGuard<base::Mutex> lock_guard(&mutex_);
2633 queue_.Clear(); 2646 queue_.Clear();
2634 } 2647 }
2635 2648
2636 } // namespace internal 2649 } // namespace internal
2637 } // namespace v8 2650 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698