| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8StackTraceImpl.h" | 5 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/Platform.h" | 7 #include "platform/inspector_protocol/Platform.h" |
| 8 #include "platform/inspector_protocol/String16.h" | 8 #include "platform/inspector_protocol/String16.h" |
| 9 #include "platform/v8_inspector/V8DebuggerImpl.h" | 9 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 10 #include "platform/v8_inspector/V8StringUtil.h" | 10 #include "platform/v8_inspector/V8StringUtil.h" |
| 11 | 11 |
| 12 #include <v8-debug.h> | 12 #include <v8-debug.h> |
| 13 #include <v8-profiler.h> | 13 #include <v8-profiler.h> |
| 14 #include <v8-version.h> | 14 #include <v8-version.h> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 static const v8::StackTrace::StackTraceOptions stackTraceOptions = static_cast<v
8::StackTrace::StackTraceOptions>( |
| 21 v8::StackTrace::kLineNumber | |
| 22 v8::StackTrace::kColumnOffset | |
| 23 v8::StackTrace::kScriptId | |
| 24 v8::StackTrace::kScriptNameOrSourceURL | |
| 25 v8::StackTrace::kFunctionName); |
| 26 |
| 20 V8StackTraceImpl::Frame toFrame(v8::Local<v8::StackFrame> frame) | 27 V8StackTraceImpl::Frame toFrame(v8::Local<v8::StackFrame> frame) |
| 21 { | 28 { |
| 22 String16 scriptId = String16::number(frame->GetScriptId()); | 29 String16 scriptId = String16::number(frame->GetScriptId()); |
| 23 String16 sourceName; | 30 String16 sourceName; |
| 24 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); | 31 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); |
| 25 if (!sourceNameValue.IsEmpty()) | 32 if (!sourceNameValue.IsEmpty()) |
| 26 sourceName = toProtocolString(sourceNameValue); | 33 sourceName = toProtocolString(sourceNameValue); |
| 27 | 34 |
| 28 String16 functionName; | 35 String16 functionName; |
| 29 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 36 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 .setLineNumber(m_lineNumber) | 89 .setLineNumber(m_lineNumber) |
| 83 .setColumnNumber(m_columnNumber) | 90 .setColumnNumber(m_columnNumber) |
| 84 .build(); | 91 .build(); |
| 85 } | 92 } |
| 86 | 93 |
| 87 V8StackTraceImpl::Frame V8StackTraceImpl::Frame::isolatedCopy() const | 94 V8StackTraceImpl::Frame V8StackTraceImpl::Frame::isolatedCopy() const |
| 88 { | 95 { |
| 89 return Frame(m_functionName.isolatedCopy(), m_scriptId.isolatedCopy(), m_scr
iptName.isolatedCopy(), m_lineNumber, m_columnNumber); | 96 return Frame(m_functionName.isolatedCopy(), m_scriptId.isolatedCopy(), m_scr
iptName.isolatedCopy(), m_lineNumber, m_columnNumber); |
| 90 } | 97 } |
| 91 | 98 |
| 99 // static |
| 100 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(v8::Isolate* is
olate, bool capture) |
| 101 { |
| 102 isolate->SetCaptureStackTraceForUncaughtExceptions(capture, V8StackTraceImpl
::maxCallStackSizeToCapture, stackTraceOptions); |
| 103 } |
| 104 |
| 105 // static |
| 92 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create(V8DebuggerImpl* debug
ger, int contextGroupId, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSi
ze, const String16& description) | 106 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create(V8DebuggerImpl* debug
ger, int contextGroupId, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSi
ze, const String16& description) |
| 93 { | 107 { |
| 94 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 108 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 95 v8::HandleScope scope(isolate); | 109 v8::HandleScope scope(isolate); |
| 96 std::vector<V8StackTraceImpl::Frame> frames; | 110 std::vector<V8StackTraceImpl::Frame> frames; |
| 97 if (!stackTrace.IsEmpty()) | 111 if (!stackTrace.IsEmpty()) |
| 98 toFramesVector(stackTrace, frames, maxStackSize, isolate); | 112 toFramesVector(stackTrace, frames, maxStackSize, isolate); |
| 99 | 113 |
| 100 int maxAsyncCallChainDepth = 1; | 114 int maxAsyncCallChainDepth = 1; |
| 101 V8StackTraceImpl* asyncCallChain = nullptr; | 115 V8StackTraceImpl* asyncCallChain = nullptr; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 stackTrace->setDescription(m_description); | 237 stackTrace->setDescription(m_description); |
| 224 if (m_parent) | 238 if (m_parent) |
| 225 stackTrace->setParent(m_parent->buildInspectorObject()); | 239 stackTrace->setParent(m_parent->buildInspectorObject()); |
| 226 return stackTrace; | 240 return stackTrace; |
| 227 } | 241 } |
| 228 | 242 |
| 229 std::unique_ptr<protocol::Runtime::StackTrace> V8StackTraceImpl::buildInspectorO
bjectForTail(V8DebuggerImpl* debugger) const | 243 std::unique_ptr<protocol::Runtime::StackTrace> V8StackTraceImpl::buildInspectorO
bjectForTail(V8DebuggerImpl* debugger) const |
| 230 { | 244 { |
| 231 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 245 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
| 232 // Next call collapses possible empty stack and ensures maxAsyncCallChainDep
th. | 246 // Next call collapses possible empty stack and ensures maxAsyncCallChainDep
th. |
| 233 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create(debug
ger, m_contextGroupId, v8::Local<v8::StackTrace>(), V8StackTrace::maxCallStackSi
zeToCapture); | 247 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create(debug
ger, m_contextGroupId, v8::Local<v8::StackTrace>(), V8StackTraceImpl::maxCallSta
ckSizeToCapture); |
| 234 if (!fullChain || !fullChain->m_parent) | 248 if (!fullChain || !fullChain->m_parent) |
| 235 return nullptr; | 249 return nullptr; |
| 236 return fullChain->m_parent->buildInspectorObject(); | 250 return fullChain->m_parent->buildInspectorObject(); |
| 237 } | 251 } |
| 238 | 252 |
| 239 String16 V8StackTraceImpl::toString() const | 253 String16 V8StackTraceImpl::toString() const |
| 240 { | 254 { |
| 241 String16Builder stackTrace; | 255 String16Builder stackTrace; |
| 242 for (size_t i = 0; i < m_frames.size(); ++i) { | 256 for (size_t i = 0; i < m_frames.size(); ++i) { |
| 243 const Frame& frame = m_frames[i]; | 257 const Frame& frame = m_frames[i]; |
| 244 stackTrace.append("\n at " + (frame.functionName().length() ? frame.f
unctionName() : "(anonymous function)")); | 258 stackTrace.append("\n at " + (frame.functionName().length() ? frame.f
unctionName() : "(anonymous function)")); |
| 245 stackTrace.append(" ("); | 259 stackTrace.append(" ("); |
| 246 stackTrace.append(frame.sourceURL()); | 260 stackTrace.append(frame.sourceURL()); |
| 247 stackTrace.append(':'); | 261 stackTrace.append(':'); |
| 248 stackTrace.appendNumber(frame.lineNumber()); | 262 stackTrace.appendNumber(frame.lineNumber()); |
| 249 stackTrace.append(':'); | 263 stackTrace.append(':'); |
| 250 stackTrace.appendNumber(frame.columnNumber()); | 264 stackTrace.appendNumber(frame.columnNumber()); |
| 251 stackTrace.append(')'); | 265 stackTrace.append(')'); |
| 252 } | 266 } |
| 253 return stackTrace.toString(); | 267 return stackTrace.toString(); |
| 254 } | 268 } |
| 255 | 269 |
| 256 } // namespace blink | 270 } // namespace blink |
| OLD | NEW |