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

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

Issue 2578923002: [inspector] async stacks for Promise.then calls... (Closed)
Patch Set: avoid calling functions 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
« no previous file with comments | « src/debug/debug.h ('k') | src/debug/debug.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 void Debug::OnCompileError(Handle<Script> script) { 1772 void Debug::OnCompileError(Handle<Script> script) {
1772 ProcessCompileEvent(v8::CompileError, script); 1773 ProcessCompileEvent(v8::CompileError, script);
1773 } 1774 }
1774 1775
1775 1776
1776 // Handle debugger actions when a new script is compiled. 1777 // Handle debugger actions when a new script is compiled.
1777 void Debug::OnAfterCompile(Handle<Script> script) { 1778 void Debug::OnAfterCompile(Handle<Script> script) {
1778 ProcessCompileEvent(v8::AfterCompile, script); 1779 ProcessCompileEvent(v8::AfterCompile, script);
1779 } 1780 }
1780 1781
1781 void Debug::OnAsyncTaskEvent(PromiseDebugActionType type, int id, 1782 namespace {
1783 struct CollectedCallbackData {
1784 Object** location;
1785 int id;
1786 Debug* debug;
1787 Isolate* isolate;
1788
1789 CollectedCallbackData(Object** location, int id, Debug* debug,
1790 Isolate* isolate)
1791 : location(location), id(id), debug(debug), isolate(isolate) {}
1792 };
1793
1794 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) {
1795 std::unique_ptr<CollectedCallbackData> data(
1796 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()));
1797 if (!data->debug->is_active()) return;
1798 HandleScope scope(data->isolate);
1799 data->debug->OnAsyncTaskEvent(debug::kDebugCancel, data->id,
1800 kDebugPromiseCollected);
1801 }
1802
1803 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) {
1804 CollectedCallbackData* data =
1805 reinterpret_cast<CollectedCallbackData*>(info.GetParameter());
1806 GlobalHandles::Destroy(data->location);
1807 info.SetSecondPassCallback(&SendAsyncTaskEventCancel);
1808 }
1809 } // namespace
1810
1811 int Debug::NextAsyncTaskId(Handle<JSObject> promise) {
1812 LookupIterator it(promise, isolate_->factory()->promise_async_id_symbol());
1813 Maybe<bool> maybe = JSReceiver::HasProperty(&it);
1814 if (maybe.ToChecked()) {
1815 MaybeHandle<Object> result = Object::GetProperty(&it);
1816 return Handle<Smi>::cast(result.ToHandleChecked())->value();
1817 }
1818 Handle<Smi> 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 Handle<Object> global_handle = isolate_->global_handles()->Create(*promise);
1823 // We send EnqueueRecurring async task event when promise is fulfilled or
1824 // rejected, WillHandle and DidHandle for every scheduled microtask for this
1825 // promise.
1826 // We need to send a cancel event when no other microtasks can be
1827 // started for this promise and all current microtasks are finished.
1828 // Since we holding promise when at least one microtask is scheduled (inside
1829 // PromiseReactionJobInfo), we can send cancel event in weak callback.
1830 GlobalHandles::MakeWeak(
1831 global_handle.location(),
1832 new CollectedCallbackData(global_handle.location(), async_id->value(),
1833 this, isolate_),
1834 &ResetPromiseHandle, v8::WeakCallbackType::kParameter);
1835 return async_id->value();
1836 }
1837
1838 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id,
1782 PromiseDebugActionName name) { 1839 PromiseDebugActionName name) {
1783 if (in_debug_scope() || ignore_events()) return; 1840 if (in_debug_scope() || ignore_events()) return;
1784 1841
1785 HandleScope scope(isolate_); 1842 HandleScope scope(isolate_);
1786 DebugScope debug_scope(this); 1843 DebugScope debug_scope(this);
1787 if (debug_scope.failed()) return; 1844 if (debug_scope.failed()) return;
1788 1845
1789 // Create the script collected state object. 1846 // Create the script collected state object.
1790 Handle<Object> event_data; 1847 Handle<Object> event_data;
1791 // Bail out and don't call debugger if exception. 1848 // Bail out and don't call debugger if exception.
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2496 logger_->DebugEvent("Put", message.text()); 2553 logger_->DebugEvent("Put", message.text());
2497 } 2554 }
2498 2555
2499 void LockingCommandMessageQueue::Clear() { 2556 void LockingCommandMessageQueue::Clear() {
2500 base::LockGuard<base::Mutex> lock_guard(&mutex_); 2557 base::LockGuard<base::Mutex> lock_guard(&mutex_);
2501 queue_.Clear(); 2558 queue_.Clear();
2502 } 2559 }
2503 2560
2504 } // namespace internal 2561 } // namespace internal
2505 } // namespace v8 2562 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug.h ('k') | src/debug/debug.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698