Chromium Code Reviews| Index: src/inspector/v8-debugger.cc |
| diff --git a/src/inspector/v8-debugger.cc b/src/inspector/v8-debugger.cc |
| index a6b1219bc6ce027f4f51eefb774b9ceb2c5dba46..6ad0d8a70a6bf11e4854c4e275536e203d27bbc2 100644 |
| --- a/src/inspector/v8-debugger.cc |
| +++ b/src/inspector/v8-debugger.cc |
| @@ -30,6 +30,22 @@ inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { |
| return value ? v8::True(isolate) : v8::False(isolate); |
| } |
| +String16 promiseDebugActionName(v8::debug::PromiseDebugActionName action) { |
| + switch (action) { |
| + case v8::debug::kDebugAsyncFunction: |
| + return "async function"; |
| + case v8::debug::kDebugPromiseResolve: |
| + return "Promise.resolve"; |
| + case v8::debug::kDebugPromiseReject: |
| + return "Promise.reject"; |
| + case v8::debug::kDebugPromiseResolveThenableJob: |
| + return "PromiseResolveThenableJob"; |
| + case v8::debug::kDebugPromiseCollected: |
| + return "Promise collected"; |
| + } |
| + return String16(); |
| +} |
| + |
| } // namespace |
| static bool inLiveEditScope = false; |
| @@ -74,6 +90,8 @@ void V8Debugger::enable() { |
| v8::debug::ChangeBreakOnException(m_isolate, v8::debug::NoBreakOnException); |
| m_pauseOnExceptionsState = v8::debug::NoBreakOnException; |
| compileDebuggerScript(); |
| + v8::debug::SetAsyncTaskListener(m_isolate, &V8Debugger::v8AsyncTaskListener, |
|
dgozman
2017/01/13 00:01:48
Move it next to SetDebugEventListener.
kozy
2017/01/13 15:59:13
Done.
|
| + this); |
| } |
| void V8Debugger::disable() { |
| @@ -85,6 +103,7 @@ void V8Debugger::disable() { |
| allAsyncTasksCanceled(); |
| m_wasmTranslation.Clear(); |
| v8::debug::SetDebugEventListener(m_isolate, nullptr); |
| + v8::debug::SetAsyncTaskListener(m_isolate, nullptr, nullptr); |
| } |
| bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); } |
| @@ -533,16 +552,10 @@ void V8Debugger::handleV8DebugEvent( |
| v8::HandleScope scope(m_isolate); |
| v8::DebugEvent event = eventDetails.GetEvent(); |
| - if (event != v8::AsyncTaskEvent && event != v8::Break && |
| - event != v8::Exception && event != v8::AfterCompile && |
| - event != v8::CompileError) |
| + if (event != v8::Break && event != v8::Exception && |
| + event != v8::AfterCompile && event != v8::CompileError) |
| return; |
| - if (event == v8::AsyncTaskEvent) { |
| - handleV8AsyncTaskEvent(eventDetails.GetEventData()); |
| - return; |
| - } |
| - |
| v8::Local<v8::Context> eventContext = eventDetails.GetEventContext(); |
| DCHECK(!eventContext.IsEmpty()); |
| V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( |
| @@ -596,48 +609,28 @@ void V8Debugger::handleV8DebugEvent( |
| } |
| } |
| -void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Object> eventData) { |
| - if (!m_maxAsyncCallStackDepth) return; |
| +void V8Debugger::v8AsyncTaskListener(v8::debug::PromiseDebugActionType type, |
| + int id, |
| + v8::debug::PromiseDebugActionName name, |
| + void* data) { |
| + V8Debugger* debugger = static_cast<V8Debugger*>(data); |
| - // TODO(kozyatinskiy): remove usage of current context as soon as async event |
| - // is migrated to pure C++ API. |
| - v8::debug::PromiseDebugActionType type = |
| - static_cast<v8::debug::PromiseDebugActionType>( |
| - eventData |
| - ->Get(m_isolate->GetCurrentContext(), |
| - toV8StringInternalized(m_isolate, "type_")) |
| - .ToLocalChecked() |
| - ->ToInteger(m_isolate->GetCurrentContext()) |
| - .ToLocalChecked() |
| - ->Value()); |
| - String16 name = toProtocolStringWithTypeCheck( |
| - eventData |
| - ->Get(m_isolate->GetCurrentContext(), |
| - toV8StringInternalized(m_isolate, "name_")) |
| - .ToLocalChecked()); |
| - int id = static_cast<int>(eventData |
| - ->Get(m_isolate->GetCurrentContext(), |
| - toV8StringInternalized(m_isolate, "id_")) |
| - .ToLocalChecked() |
| - ->ToInteger(m_isolate->GetCurrentContext()) |
| - .ToLocalChecked() |
| - ->Value()); |
| // Async task events from Promises are given misaligned pointers to prevent |
| // from overlapping with other Blink task identifiers. There is a single |
| // namespace of such ids, managed by src/js/promise.js. |
| void* ptr = reinterpret_cast<void*>(id * 2 + 1); |
| switch (type) { |
| case v8::debug::kDebugEnqueueRecurring: |
| - asyncTaskScheduled(name, ptr, true); |
| + debugger->asyncTaskScheduled(promiseDebugActionName(name), ptr, true); |
| break; |
| case v8::debug::kDebugCancel: |
| - asyncTaskCanceled(ptr); |
| + debugger->asyncTaskCanceled(ptr); |
| break; |
| case v8::debug::kDebugWillHandle: |
| - asyncTaskStarted(ptr); |
| + debugger->asyncTaskStarted(ptr); |
| break; |
| case v8::debug::kDebugDidHandle: |
| - asyncTaskFinished(ptr); |
| + debugger->asyncTaskFinished(ptr); |
| break; |
| } |
| } |