Chromium Code Reviews| Index: src/inspector/v8-debugger.cc |
| diff --git a/src/inspector/v8-debugger.cc b/src/inspector/v8-debugger.cc |
| index 3a2fc89f0039869b49a3c5cef4f4b92eab0017a6..7d3c8c590c1b9471d4a57054aa0bf436c45c99b3 100644 |
| --- a/src/inspector/v8-debugger.cc |
| +++ b/src/inspector/v8-debugger.cc |
| @@ -194,6 +194,7 @@ void V8Debugger::disable() { |
| m_debuggerScript.Reset(); |
| m_debuggerContext.Reset(); |
| allAsyncTasksCanceled(); |
| + m_taskWithScheduledBreak = nullptr; |
| m_wasmTranslation.Clear(); |
| v8::debug::SetDebugDelegate(m_isolate, nullptr); |
| v8::debug::SetOutOfMemoryCallback(m_isolate, nullptr, nullptr); |
| @@ -625,17 +626,25 @@ bool V8Debugger::IsFunctionBlackboxed(v8::Local<v8::debug::Script> script, |
| end); |
| } |
| -void V8Debugger::PromiseEventOccurred(v8::debug::PromiseDebugActionType type, |
| - int id, int parentId) { |
| - if (!m_maxAsyncCallStackDepth) return; |
| +void V8Debugger::PromiseEventOccurred(v8::Local<v8::Context> context, |
| + v8::debug::PromiseDebugActionType type, |
| + int id, int parentId, bool breakable) { |
|
dgozman
2017/03/01 23:03:57
Do we really need this?
kozy
2017/03/02 00:53:03
Yes, but we could make it better and called create
|
| // 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); |
| + void* parentPtr = |
| + parentId ? reinterpret_cast<void*>(parentId * 2 + 1) : nullptr; |
| + if ((breakable && type == v8::debug::kDebugPromiseCreated && parentPtr) || |
|
dgozman
2017/03/01 23:03:57
Let's move checks inside of stepping method.
kozy
2017/03/02 00:53:03
Done.
|
| + type == v8::debug::kDebugWillHandle || |
| + type == v8::debug::kDebugDidHandle || |
| + type == v8::debug::kDebugPromiseCollected) { |
| + steppingOnPromiseEvent(context, type, ptr); |
| + } |
| + if (!m_maxAsyncCallStackDepth) return; |
| switch (type) { |
| case v8::debug::kDebugPromiseCreated: |
| - asyncTaskCreated( |
| - ptr, parentId ? reinterpret_cast<void*>(parentId * 2 + 1) : nullptr); |
| + asyncTaskCreated(ptr, parentPtr); |
| break; |
| case v8::debug::kDebugEnqueueAsyncFunction: |
| asyncTaskScheduled("async function", ptr, true); |
| @@ -658,6 +667,34 @@ void V8Debugger::PromiseEventOccurred(v8::debug::PromiseDebugActionType type, |
| } |
| } |
| +void V8Debugger::steppingOnPromiseEvent(v8::Local<v8::Context> context, |
|
dgozman
2017/03/01 23:03:57
handleAsyncTaskStepping
kozy
2017/03/02 00:53:03
Done.
|
| + v8::debug::PromiseDebugActionType type, |
| + void* task) { |
| + if (type == v8::debug::kDebugPromiseCollected) { |
| + if (task == m_taskWithScheduledBreak) m_taskWithScheduledBreak = nullptr; |
| + return; |
| + } |
| + DCHECK(!context.IsEmpty()); |
| + v8::Context::Scope contextScope(context); |
| + V8DebuggerAgentImpl* agent = |
| + m_inspector->enabledDebuggerAgentForGroup(currentContextGroupId()); |
| + if (!agent) return; |
| + if (type == v8::debug::kDebugPromiseCreated) { |
| + if (!agent->isStepIntoAsyncScheduled()) return; |
| + m_taskWithScheduledBreak = task; |
| + agent->stepIntoAsyncWasScheduled(); |
|
dgozman
2017/03/01 23:03:57
if (agent->shouldBreakInScheduledAsyncTask())
m_
kozy
2017/03/02 00:53:03
Done.
|
| + return; |
| + } |
| + if (m_taskWithScheduledBreak != task) return; |
| + if (type == v8::debug::kDebugWillHandle) { |
| + agent->schedulePauseOnNextStatement( |
| + protocol::Debugger::Paused::ReasonEnum::Other, nullptr); |
| + } else { |
|
dgozman
2017/03/01 23:03:57
DCHECK(type == didHandle)
kozy
2017/03/02 00:53:03
Done.
|
| + agent->cancelPauseOnNextStatement(); |
| + m_taskWithScheduledBreak = nullptr; |
| + } |
| +} |
| + |
| V8StackTraceImpl* V8Debugger::currentAsyncCallChain() { |
| if (!m_currentStacks.size()) return nullptr; |
| return m_currentStacks.back().get(); |
| @@ -802,11 +839,7 @@ v8::MaybeLocal<v8::Array> V8Debugger::internalProperties( |
| std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace( |
| v8::Local<v8::StackTrace> stackTrace) { |
| - int contextGroupId = |
| - m_isolate->InContext() |
| - ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) |
| - : 0; |
| - return V8StackTraceImpl::create(this, contextGroupId, stackTrace, |
| + return V8StackTraceImpl::create(this, currentContextGroupId(), stackTrace, |
| V8StackTraceImpl::maxCallStackSizeToCapture); |
| } |
| @@ -843,7 +876,7 @@ void V8Debugger::asyncTaskCreated(void* task, void* parentTask) { |
| if (!m_maxAsyncCallStackDepth) return; |
| if (parentTask) m_parentTask[task] = parentTask; |
| v8::HandleScope scope(m_isolate); |
| - // We don't need to pass context group id here because we gets this callback |
| + // We don't need to pass context group id here because we get this callback |
| // from V8 for promise events only. |
| // Passing one as maxStackSize forces no async chain for the new stack and |
| // allows us to not grow exponentially. |
| @@ -865,13 +898,9 @@ void V8Debugger::asyncTaskScheduled(const String16& taskName, void* task, |
| bool recurring) { |
| if (!m_maxAsyncCallStackDepth) return; |
| v8::HandleScope scope(m_isolate); |
| - int contextGroupId = |
| - m_isolate->InContext() |
| - ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) |
| - : 0; |
| std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture( |
| - this, contextGroupId, V8StackTraceImpl::maxCallStackSizeToCapture, |
| - taskName); |
| + this, currentContextGroupId(), |
| + V8StackTraceImpl::maxCallStackSizeToCapture, taskName); |
| if (chain) { |
| m_asyncTaskStacks[task] = std::move(chain); |
| if (recurring) m_recurringTasks.insert(task); |
| @@ -954,8 +983,7 @@ std::unique_ptr<V8StackTraceImpl> V8Debugger::captureStackTrace( |
| if (!m_isolate->InContext()) return nullptr; |
| v8::HandleScope handles(m_isolate); |
| - int contextGroupId = |
| - m_inspector->contextGroupId(m_isolate->GetCurrentContext()); |
| + int contextGroupId = currentContextGroupId(); |
| if (!contextGroupId) return nullptr; |
| size_t stackSize = |
| @@ -966,4 +994,9 @@ std::unique_ptr<V8StackTraceImpl> V8Debugger::captureStackTrace( |
| return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| } |
| +int V8Debugger::currentContextGroupId() { |
| + if (!m_isolate->InContext()) return 0; |
| + return m_inspector->contextGroupId(m_isolate->GetCurrentContext()); |
| +} |
| + |
| } // namespace v8_inspector |