OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/inspector/V8StackTraceImpl.h" | 5 #include "src/inspector/V8StackTraceImpl.h" |
6 | 6 |
7 #include "src/inspector/StringUtil.h" | 7 #include "src/inspector/StringUtil.h" |
8 #include "src/inspector/V8Debugger.h" | 8 #include "src/inspector/V8Debugger.h" |
9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
10 | 10 |
11 #include "include/v8-debug.h" | 11 #include "include/v8-debug.h" |
12 #include "include/v8-profiler.h" | 12 #include "include/v8-profiler.h" |
13 #include "include/v8-version.h" | 13 #include "include/v8-version.h" |
14 | 14 |
| 15 #include <limits> |
| 16 |
15 namespace v8_inspector { | 17 namespace v8_inspector { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 static const v8::StackTrace::StackTraceOptions stackTraceOptions = | 21 static const v8::StackTrace::StackTraceOptions stackTraceOptions = |
20 static_cast<v8::StackTrace::StackTraceOptions>( | 22 static_cast<v8::StackTrace::StackTraceOptions>( |
21 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | | 23 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | |
22 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | | 24 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | |
23 v8::StackTrace::kFunctionName); | 25 v8::StackTrace::kFunctionName); |
24 | 26 |
(...skipping 13 matching lines...) Expand all Loading... |
38 int sourceColumn = frame->GetColumn(); | 40 int sourceColumn = frame->GetColumn(); |
39 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, | 41 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, |
40 sourceLineNumber, sourceColumn); | 42 sourceLineNumber, sourceColumn); |
41 } | 43 } |
42 | 44 |
43 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, | 45 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, |
44 std::vector<V8StackTraceImpl::Frame>& frames, | 46 std::vector<V8StackTraceImpl::Frame>& frames, |
45 size_t maxStackSize, v8::Isolate* isolate) { | 47 size_t maxStackSize, v8::Isolate* isolate) { |
46 DCHECK(isolate->InContext()); | 48 DCHECK(isolate->InContext()); |
47 int frameCount = stackTrace->GetFrameCount(); | 49 int frameCount = stackTrace->GetFrameCount(); |
48 if (frameCount > static_cast<int>(maxStackSize)) frameCount = maxStackSize; | 50 if (frameCount > static_cast<int>(maxStackSize)) |
| 51 frameCount = static_cast<int>(maxStackSize); |
49 for (int i = 0; i < frameCount; i++) { | 52 for (int i = 0; i < frameCount; i++) { |
50 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 53 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
51 frames.push_back(toFrame(stackFrame)); | 54 frames.push_back(toFrame(stackFrame)); |
52 } | 55 } |
53 } | 56 } |
54 | 57 |
55 } // namespace | 58 } // namespace |
56 | 59 |
57 V8StackTraceImpl::Frame::Frame() | 60 V8StackTraceImpl::Frame::Frame() |
58 : m_functionName("undefined"), | 61 : m_functionName("undefined"), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 155 } |
153 | 156 |
154 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( | 157 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( |
155 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, | 158 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, |
156 const String16& description) { | 159 const String16& description) { |
157 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 160 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
158 v8::HandleScope handleScope(isolate); | 161 v8::HandleScope handleScope(isolate); |
159 v8::Local<v8::StackTrace> stackTrace; | 162 v8::Local<v8::StackTrace> stackTrace; |
160 if (isolate->InContext()) { | 163 if (isolate->InContext()) { |
161 isolate->GetCpuProfiler()->CollectSample(); | 164 isolate->GetCpuProfiler()->CollectSample(); |
162 stackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, | 165 DCHECK(maxStackSize <= std::numeric_limits<int>::max()); |
163 stackTraceOptions); | 166 stackTrace = v8::StackTrace::CurrentStackTrace( |
| 167 isolate, static_cast<int>(maxStackSize), stackTraceOptions); |
164 } | 168 } |
165 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, | 169 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, |
166 maxStackSize, description); | 170 maxStackSize, description); |
167 } | 171 } |
168 | 172 |
169 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { | 173 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { |
170 std::vector<Frame> framesCopy(m_frames); | 174 std::vector<Frame> framesCopy(m_frames); |
171 return wrapUnique( | 175 return wrapUnique( |
172 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, | 176 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, |
173 m_parent ? m_parent->cloneImpl() : nullptr)); | 177 m_parent ? m_parent->cloneImpl() : nullptr)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 268 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
265 stackTrace.append(':'); | 269 stackTrace.append(':'); |
266 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 270 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
267 stackTrace.append(')'); | 271 stackTrace.append(')'); |
268 } | 272 } |
269 String16 string = stackTrace.toString(); | 273 String16 string = stackTrace.toString(); |
270 return StringBufferImpl::adopt(string); | 274 return StringBufferImpl::adopt(string); |
271 } | 275 } |
272 | 276 |
273 } // namespace v8_inspector | 277 } // namespace v8_inspector |
OLD | NEW |