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

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

Issue 2578923002: [inspector] async stacks for Promise.then calls... (Closed)
Patch Set: use set_private instead of weak map 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
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // Threading support. 394 // Threading support.
395 void Debug::ThreadInit() { 395 void Debug::ThreadInit() {
396 thread_local_.break_count_ = 0; 396 thread_local_.break_count_ = 0;
397 thread_local_.break_id_ = 0; 397 thread_local_.break_id_ = 0;
398 thread_local_.break_frame_id_ = StackFrame::NO_ID; 398 thread_local_.break_frame_id_ = StackFrame::NO_ID;
399 thread_local_.last_step_action_ = StepNone; 399 thread_local_.last_step_action_ = StepNone;
400 thread_local_.last_statement_position_ = kNoSourcePosition; 400 thread_local_.last_statement_position_ = kNoSourcePosition;
401 thread_local_.last_fp_ = 0; 401 thread_local_.last_fp_ = 0;
402 thread_local_.target_fp_ = 0; 402 thread_local_.target_fp_ = 0;
403 thread_local_.return_value_ = Handle<Object>(); 403 thread_local_.return_value_ = Handle<Object>();
404 thread_local_.async_task_count_ = 0;
404 clear_suspended_generator(); 405 clear_suspended_generator();
405 // TODO(isolates): frames_are_dropped_? 406 // TODO(isolates): frames_are_dropped_?
406 base::NoBarrier_Store(&thread_local_.current_debug_scope_, 407 base::NoBarrier_Store(&thread_local_.current_debug_scope_,
407 static_cast<base::AtomicWord>(0)); 408 static_cast<base::AtomicWord>(0));
408 } 409 }
409 410
410 411
411 char* Debug::ArchiveDebug(char* storage) { 412 char* Debug::ArchiveDebug(char* storage) {
412 // Simply reset state. Don't archive anything. 413 // Simply reset state. Don't archive anything.
413 ThreadInit(); 414 ThreadInit();
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 1650
1650 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script, 1651 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script,
1651 v8::DebugEvent type) { 1652 v8::DebugEvent type) {
1652 // Create the compile event object. 1653 // Create the compile event object.
1653 Handle<Object> script_wrapper = Script::GetWrapper(script); 1654 Handle<Object> script_wrapper = Script::GetWrapper(script);
1654 Handle<Object> argv[] = { script_wrapper, 1655 Handle<Object> argv[] = { script_wrapper,
1655 isolate_->factory()->NewNumberFromInt(type) }; 1656 isolate_->factory()->NewNumberFromInt(type) };
1656 return CallFunction("MakeCompileEvent", arraysize(argv), argv); 1657 return CallFunction("MakeCompileEvent", arraysize(argv), argv);
1657 } 1658 }
1658 1659
1659 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<String> type, 1660 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<Smi> type,
1660 Handle<Object> id, 1661 Handle<Object> id,
1661 Handle<String> name) { 1662 Handle<String> name) {
1662 DCHECK(id->IsNumber()); 1663 DCHECK(id->IsNumber());
1663 // Create the async task event object. 1664 // Create the async task event object.
1664 Handle<Object> argv[] = {type, id, name}; 1665 Handle<Object> argv[] = {type, id, name};
1665 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv); 1666 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv);
1666 } 1667 }
1667 1668
1668 1669
1669 void Debug::OnThrow(Handle<Object> exception) { 1670 void Debug::OnThrow(Handle<Object> exception) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 void Debug::OnCompileError(Handle<Script> script) { 1773 void Debug::OnCompileError(Handle<Script> script) {
1773 ProcessCompileEvent(v8::CompileError, script); 1774 ProcessCompileEvent(v8::CompileError, script);
1774 } 1775 }
1775 1776
1776 1777
1777 // Handle debugger actions when a new script is compiled. 1778 // Handle debugger actions when a new script is compiled.
1778 void Debug::OnAfterCompile(Handle<Script> script) { 1779 void Debug::OnAfterCompile(Handle<Script> script) {
1779 ProcessCompileEvent(v8::AfterCompile, script); 1780 ProcessCompileEvent(v8::AfterCompile, script);
1780 } 1781 }
1781 1782
1782 void Debug::OnAsyncTaskEvent(Handle<String> type, Handle<Object> id, 1783 namespace {
1784 struct CollectedCallbackData {
1785 Object** location;
1786 int id;
1787 Debug* debug;
1788 Isolate* isolate;
1789
1790 CollectedCallbackData(Object** location, int id, Debug* debug,
1791 Isolate* isolate)
1792 : location(location), id(id), debug(debug), isolate(isolate) {}
1793 };
1794
1795 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) {
1796 std::unique_ptr<CollectedCallbackData> data(
1797 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()));
1798 if (!data->debug->is_active()) return;
1799 HandleScope scope(data->isolate);
1800 data->debug->OnAsyncTaskEvent(debug::Cancel,
Yang 2016/12/16 17:10:26 Can you add a comment explaining why we need a wea
kozy 2016/12/16 17:47:15 Done.
1801 handle(Smi::FromInt(data->id), data->isolate),
1802 data->isolate->factory()->collected_string());
1803 }
1804
1805 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) {
1806 CollectedCallbackData* data =
1807 reinterpret_cast<CollectedCallbackData*>(info.GetParameter());
1808 GlobalHandles::Destroy(data->location);
1809 info.SetSecondPassCallback(&SendAsyncTaskEventCancel);
1810 }
1811 } // namespace
1812
1813 Handle<Object> Debug::NextAsyncTaskId(Handle<JSObject> promise) {
gsathya 2016/12/16 15:37:11 Can this be a non JSPromise? If not, you can make
kozy 2016/12/16 16:29:26 I double checked that we always get JSPromise here
1814 LookupIterator it(promise, isolate_->factory()->promise_async_id_symbol());
1815 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
1816 Handle<Smi> async_id;
1817 if (!maybe.ToChecked()) {
1818 async_id =
1819 handle(Smi::FromInt(thread_local_.async_task_count_++), isolate_);
1820 Object::SetProperty(&it, async_id, SLOPPY, Object::MAY_BE_STORE_FROM_KEYED)
1821 .ToChecked();
1822 } else {
1823 MaybeHandle<Object> result = Object::GetProperty(&it);
1824 async_id = Handle<Smi>::cast(result.ToHandleChecked());
1825 }
1826 Handle<Object> global_handle = isolate_->global_handles()->Create(*promise);
1827 GlobalHandles::MakeWeak(
1828 global_handle.location(),
1829 new CollectedCallbackData(global_handle.location(), async_id->value(),
1830 this, isolate_),
1831 &ResetPromiseHandle, v8::WeakCallbackType::kParameter);
1832 return async_id;
1833 }
1834
1835 void Debug::OnAsyncTaskEvent(debug::AsyncTaskEventType type, Handle<Object> id,
1783 Handle<String> name) { 1836 Handle<String> name) {
1784 DCHECK(id->IsNumber()); 1837 DCHECK(id->IsNumber());
1785 if (in_debug_scope() || ignore_events()) return; 1838 if (in_debug_scope() || ignore_events()) return;
1786 1839
1787 HandleScope scope(isolate_); 1840 HandleScope scope(isolate_);
1788 DebugScope debug_scope(this); 1841 DebugScope debug_scope(this);
1789 if (debug_scope.failed()) return; 1842 if (debug_scope.failed()) return;
1790 1843
1791 // Create the script collected state object. 1844 // Create the script collected state object.
1792 Handle<Object> event_data; 1845 Handle<Object> event_data;
1793 // Bail out and don't call debugger if exception. 1846 // Bail out and don't call debugger if exception.
1794 if (!MakeAsyncTaskEvent(type, id, name).ToHandle(&event_data)) return; 1847 Handle<Smi> type_smi(Smi::FromInt(type), isolate_);
1848 if (!MakeAsyncTaskEvent(type_smi, id, name).ToHandle(&event_data)) return;
1795 1849
1796 // Process debug event. 1850 // Process debug event.
1797 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data), 1851 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data),
1798 true); 1852 true);
1799 } 1853 }
1800 1854
1801 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data, 1855 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data,
1802 bool auto_continue) { 1856 bool auto_continue) {
1803 HandleScope scope(isolate_); 1857 HandleScope scope(isolate_);
1804 1858
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 logger_->DebugEvent("Put", message.text()); 2548 logger_->DebugEvent("Put", message.text());
2495 } 2549 }
2496 2550
2497 void LockingCommandMessageQueue::Clear() { 2551 void LockingCommandMessageQueue::Clear() {
2498 base::LockGuard<base::Mutex> lock_guard(&mutex_); 2552 base::LockGuard<base::Mutex> lock_guard(&mutex_);
2499 queue_.Clear(); 2553 queue_.Clear();
2500 } 2554 }
2501 2555
2502 } // namespace internal 2556 } // namespace internal
2503 } // namespace v8 2557 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698