| 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/v8_inspector/V8DebuggerAgentImpl.h" | 7 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 9 #include "platform/v8_inspector/V8StringUtil.h" | 9 #include "platform/v8_inspector/V8StringUtil.h" |
| 10 #include "wtf/PassOwnPtr.h" | 10 #include "wtf/PassOwnPtr.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 String functionName; | 28 String functionName; |
| 29 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 29 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
| 30 if (!functionNameValue.IsEmpty()) | 30 if (!functionNameValue.IsEmpty()) |
| 31 functionName = toWTFString(functionNameValue); | 31 functionName = toWTFString(functionNameValue); |
| 32 | 32 |
| 33 int sourceLineNumber = frame->GetLineNumber(); | 33 int sourceLineNumber = frame->GetLineNumber(); |
| 34 int sourceColumn = frame->GetColumn(); | 34 int sourceColumn = frame->GetColumn(); |
| 35 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, sourceLin
eNumber, sourceColumn); | 35 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, sourceLin
eNumber, sourceColumn); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void toCallFramesVector(v8::Local<v8::StackTrace> stackTrace, Vector<V8StackTrac
eImpl::Frame>& scriptCallFrames, size_t maxStackSize, v8::Isolate* isolate) | 38 void toCallFramesVector(v8::Local<v8::StackTrace> stackTrace, protocol::Vector<V
8StackTraceImpl::Frame>& scriptCallFrames, size_t maxStackSize, v8::Isolate* iso
late) |
| 39 { | 39 { |
| 40 ASSERT(isolate->InContext()); | 40 ASSERT(isolate->InContext()); |
| 41 int frameCount = stackTrace->GetFrameCount(); | 41 int frameCount = stackTrace->GetFrameCount(); |
| 42 if (frameCount > static_cast<int>(maxStackSize)) | 42 if (frameCount > static_cast<int>(maxStackSize)) |
| 43 frameCount = maxStackSize; | 43 frameCount = maxStackSize; |
| 44 for (int i = 0; i < frameCount; i++) { | 44 for (int i = 0; i < frameCount; i++) { |
| 45 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 45 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
| 46 scriptCallFrames.append(toCallFrame(stackFrame)); | 46 scriptCallFrames.append(toCallFrame(stackFrame)); |
| 47 } | 47 } |
| 48 } | 48 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 .setUrl(m_scriptName) | 81 .setUrl(m_scriptName) |
| 82 .setLineNumber(m_lineNumber) | 82 .setLineNumber(m_lineNumber) |
| 83 .setColumnNumber(m_columnNumber) | 83 .setColumnNumber(m_columnNumber) |
| 84 .build(); | 84 .build(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::create(V8DebuggerAgentImpl* agent
, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, const String& descr
iption) | 87 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::create(V8DebuggerAgentImpl* agent
, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, const String& descr
iption) |
| 88 { | 88 { |
| 89 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 89 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 90 v8::HandleScope scope(isolate); | 90 v8::HandleScope scope(isolate); |
| 91 Vector<V8StackTraceImpl::Frame> scriptCallFrames; | 91 protocol::Vector<V8StackTraceImpl::Frame> scriptCallFrames; |
| 92 if (!stackTrace.IsEmpty()) | 92 if (!stackTrace.IsEmpty()) |
| 93 toCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, isolate); | 93 toCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, isolate); |
| 94 | 94 |
| 95 OwnPtr<V8StackTraceImpl> asyncCallStack; | 95 OwnPtr<V8StackTraceImpl> asyncCallStack; |
| 96 if (agent && agent->trackingAsyncCalls() && maxStackSize > 1) | 96 if (agent && agent->trackingAsyncCalls() && maxStackSize > 1) |
| 97 asyncCallStack = agent->currentAsyncStackTraceForRuntime(); | 97 asyncCallStack = agent->currentAsyncStackTraceForRuntime(); |
| 98 | 98 |
| 99 if (stackTrace.IsEmpty() && !asyncCallStack) | 99 if (stackTrace.IsEmpty() && !asyncCallStack) |
| 100 return nullptr; | 100 return nullptr; |
| 101 | 101 |
| 102 return V8StackTraceImpl::create(description, scriptCallFrames, asyncCallStac
k.release()); | 102 return V8StackTraceImpl::create(description, scriptCallFrames, asyncCallStac
k.release()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::capture(V8DebuggerAgentImpl* agen
t, size_t maxStackSize, const String& description) | 105 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::capture(V8DebuggerAgentImpl* agen
t, size_t maxStackSize, const String& description) |
| 106 { | 106 { |
| 107 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 107 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 108 v8::HandleScope handleScope(isolate); | 108 v8::HandleScope handleScope(isolate); |
| 109 v8::Local<v8::StackTrace> stackTrace; | 109 v8::Local<v8::StackTrace> stackTrace; |
| 110 if (isolate->InContext()) { | 110 if (isolate->InContext()) { |
| 111 isolate->GetCpuProfiler()->CollectSample(); | 111 isolate->GetCpuProfiler()->CollectSample(); |
| 112 stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, st
ackTraceOptions); | 112 stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, st
ackTraceOptions); |
| 113 } | 113 } |
| 114 return V8StackTraceImpl::create(agent, stackTrace, maxStackSize, description
); | 114 return V8StackTraceImpl::create(agent, stackTrace, maxStackSize, description
); |
| 115 } | 115 } |
| 116 | 116 |
| 117 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::create(const String& description,
Vector<Frame>& frames, PassOwnPtr<V8StackTraceImpl> parent) | 117 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::create(const String& description,
protocol::Vector<Frame>& frames, PassOwnPtr<V8StackTraceImpl> parent) |
| 118 { | 118 { |
| 119 return adoptPtr(new V8StackTraceImpl(description, frames, parent)); | 119 return adoptPtr(new V8StackTraceImpl(description, frames, parent)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::clone(V8StackTraceImpl* origin, s
ize_t maxStackSize) | 122 PassOwnPtr<V8StackTraceImpl> V8StackTraceImpl::clone(V8StackTraceImpl* origin, s
ize_t maxStackSize) |
| 123 { | 123 { |
| 124 if (!origin) | 124 if (!origin) |
| 125 return nullptr; | 125 return nullptr; |
| 126 | 126 |
| 127 // TODO(dgozman): move this check to call-site. | 127 // TODO(dgozman): move this check to call-site. |
| 128 if (!origin->m_frames.size()) | 128 if (!origin->m_frames.size()) |
| 129 return V8StackTraceImpl::clone(origin->m_parent.get(), maxStackSize); | 129 return V8StackTraceImpl::clone(origin->m_parent.get(), maxStackSize); |
| 130 | 130 |
| 131 OwnPtr<V8StackTraceImpl> parent; | 131 OwnPtr<V8StackTraceImpl> parent; |
| 132 if (origin->m_parent && maxStackSize) | 132 if (origin->m_parent && maxStackSize) |
| 133 parent = V8StackTraceImpl::clone(origin->m_parent.get(), maxStackSize -
1); | 133 parent = V8StackTraceImpl::clone(origin->m_parent.get(), maxStackSize -
1); |
| 134 | 134 |
| 135 Vector<Frame> frames(origin->m_frames); | 135 protocol::Vector<Frame> frames(origin->m_frames); |
| 136 return adoptPtr(new V8StackTraceImpl(origin->m_description, frames, parent.r
elease())); | 136 return adoptPtr(new V8StackTraceImpl(origin->m_description, frames, parent.r
elease())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 V8StackTraceImpl::V8StackTraceImpl(const String& description, Vector<Frame>& fra
mes, PassOwnPtr<V8StackTraceImpl> parent) | 139 V8StackTraceImpl::V8StackTraceImpl(const String& description, protocol::Vector<F
rame>& frames, PassOwnPtr<V8StackTraceImpl> parent) |
| 140 : m_description(description) | 140 : m_description(description) |
| 141 , m_parent(parent) | 141 , m_parent(parent) |
| 142 { | 142 { |
| 143 m_frames.swap(frames); | 143 m_frames.swap(frames); |
| 144 } | 144 } |
| 145 | 145 |
| 146 V8StackTraceImpl::~V8StackTraceImpl() | 146 V8StackTraceImpl::~V8StackTraceImpl() |
| 147 { | 147 { |
| 148 } | 148 } |
| 149 | 149 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 stackTrace.append(':'); | 203 stackTrace.append(':'); |
| 204 stackTrace.appendNumber(frame.lineNumber()); | 204 stackTrace.appendNumber(frame.lineNumber()); |
| 205 stackTrace.append(':'); | 205 stackTrace.append(':'); |
| 206 stackTrace.appendNumber(frame.columnNumber()); | 206 stackTrace.appendNumber(frame.columnNumber()); |
| 207 stackTrace.append(')'); | 207 stackTrace.append(')'); |
| 208 } | 208 } |
| 209 return stackTrace.toString(); | 209 return stackTrace.toString(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace blink | 212 } // namespace blink |
| OLD | NEW |