Chromium Code Reviews| 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/v8-stack-trace-impl.h" | 5 #include "src/inspector/v8-stack-trace-impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/inspector/v8-debugger.h" | 9 #include "src/inspector/v8-debugger.h" |
| 10 #include "src/inspector/wasm-translation.h" | 10 #include "src/inspector/wasm-translation.h" |
| 11 | 11 |
| 12 namespace v8_inspector { | 12 namespace v8_inspector { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 static const v8::StackTrace::StackTraceOptions stackTraceOptions = | 16 static const v8::StackTrace::StackTraceOptions stackTraceOptions = |
| 17 static_cast<v8::StackTrace::StackTraceOptions>( | 17 static_cast<v8::StackTrace::StackTraceOptions>( |
| 18 v8::StackTrace::kDetailed | | 18 v8::StackTrace::kDetailed | |
| 19 v8::StackTrace::kExposeFramesAcrossSecurityOrigins); | 19 v8::StackTrace::kExposeFramesAcrossSecurityOrigins); |
| 20 | 20 |
| 21 std::vector<V8StackTraceImpl::Frame> toFramesVector( | 21 std::vector<std::shared_ptr<StackFrame>> toFramesVector( |
| 22 V8Debugger* debugger, v8::Local<v8::StackTrace> v8StackTrace, | 22 V8Debugger* debugger, v8::Local<v8::StackTrace> v8StackTrace, |
| 23 int maxStackSize) { | 23 int maxStackSize) { |
| 24 DCHECK(debugger->isolate()->InContext()); | 24 DCHECK(debugger->isolate()->InContext()); |
| 25 int frameCount = std::min(v8StackTrace->GetFrameCount(), maxStackSize); | 25 int frameCount = std::min(v8StackTrace->GetFrameCount(), maxStackSize); |
| 26 std::vector<V8StackTraceImpl::Frame> frames; | 26 std::vector<std::shared_ptr<StackFrame>> frames; |
| 27 for (int i = 0; i < frameCount; ++i) { | 27 for (int i = 0; i < frameCount; ++i) { |
| 28 v8::Local<v8::StackFrame> v8Frame = v8StackTrace->GetFrame(i); | 28 v8::Local<v8::StackFrame> v8Frame = v8StackTrace->GetFrame(i); |
| 29 frames.emplace_back(v8Frame); | 29 int id = v8::debug::GetStackFrameId(v8Frame); |
| 30 std::shared_ptr<StackFrame> frame = debugger->lookupFrame(id); | |
|
dgozman
2017/04/19 20:29:04
Let's put all the logic between lines 29 and 39 in
kozy
2017/04/20 00:06:49
Done.
| |
| 31 if (frame) { | |
| 32 frames.push_back(frame); | |
| 33 continue; | |
| 34 } | |
| 35 frame.reset(new StackFrame(v8Frame)); | |
| 30 // TODO(clemensh): Figure out a way to do this translation only right before | 36 // TODO(clemensh): Figure out a way to do this translation only right before |
| 31 // sending the stack trace over wire. | 37 // sending the stack trace over wire. |
| 32 if (v8Frame->IsWasm()) frames.back().translate(debugger->wasmTranslation()); | 38 if (v8Frame->IsWasm()) frame->translate(debugger->wasmTranslation()); |
| 39 debugger->storeFrame(id, frame); | |
| 40 frames.push_back(frame); | |
| 33 } | 41 } |
| 34 return frames; | 42 return frames; |
| 35 } | 43 } |
| 36 | 44 |
| 37 void calculateAsyncChain(V8Debugger* debugger, int contextGroupId, | 45 void calculateAsyncChain(V8Debugger* debugger, int contextGroupId, |
| 38 std::shared_ptr<AsyncStackTrace>* asyncParent, | 46 std::shared_ptr<AsyncStackTrace>* asyncParent, |
| 39 std::shared_ptr<AsyncStackTrace>* asyncCreation, | 47 std::shared_ptr<AsyncStackTrace>* asyncCreation, |
| 40 int* maxAsyncDepth) { | 48 int* maxAsyncDepth) { |
| 41 *asyncParent = debugger->currentAsyncParent(); | 49 *asyncParent = debugger->currentAsyncParent(); |
| 42 *asyncCreation = debugger->currentAsyncCreation(); | 50 *asyncCreation = debugger->currentAsyncCreation(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 59 // Only the top stack in the chain may be empty and doesn't contain creation | 67 // Only the top stack in the chain may be empty and doesn't contain creation |
| 60 // stack, so ensure that second stack is non-empty (it's the top of appended | 68 // stack, so ensure that second stack is non-empty (it's the top of appended |
| 61 // chain). | 69 // chain). |
| 62 if (*asyncParent && !(*asyncCreation) && !(*asyncParent)->creation().lock() && | 70 if (*asyncParent && !(*asyncCreation) && !(*asyncParent)->creation().lock() && |
| 63 (*asyncParent)->isEmpty()) { | 71 (*asyncParent)->isEmpty()) { |
| 64 *asyncParent = (*asyncParent)->parent().lock(); | 72 *asyncParent = (*asyncParent)->parent().lock(); |
| 65 } | 73 } |
| 66 } | 74 } |
| 67 | 75 |
| 68 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectCommon( | 76 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectCommon( |
| 69 const std::vector<V8StackTraceImpl::Frame>& frames, | 77 const std::vector<std::shared_ptr<StackFrame>>& frames, |
| 70 const std::shared_ptr<AsyncStackTrace>& asyncParent, | 78 const std::shared_ptr<AsyncStackTrace>& asyncParent, |
| 71 const std::shared_ptr<AsyncStackTrace>& asyncCreation, int maxAsyncDepth) { | 79 const std::shared_ptr<AsyncStackTrace>& asyncCreation, int maxAsyncDepth) { |
| 72 std::unique_ptr<protocol::Array<protocol::Runtime::CallFrame>> | 80 std::unique_ptr<protocol::Array<protocol::Runtime::CallFrame>> |
| 73 inspectorFrames = protocol::Array<protocol::Runtime::CallFrame>::create(); | 81 inspectorFrames = protocol::Array<protocol::Runtime::CallFrame>::create(); |
| 74 for (size_t i = 0; i < frames.size(); i++) { | 82 for (size_t i = 0; i < frames.size(); i++) { |
| 75 inspectorFrames->addItem(frames[i].buildInspectorObject()); | 83 inspectorFrames->addItem(frames[i]->buildInspectorObject()); |
| 76 } | 84 } |
| 77 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = | 85 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = |
| 78 protocol::Runtime::StackTrace::create() | 86 protocol::Runtime::StackTrace::create() |
| 79 .setCallFrames(std::move(inspectorFrames)) | 87 .setCallFrames(std::move(inspectorFrames)) |
| 80 .build(); | 88 .build(); |
| 81 if (asyncParent && maxAsyncDepth > 0) { | 89 if (asyncParent && maxAsyncDepth > 0) { |
| 82 stackTrace->setParent(asyncParent->buildInspectorObject(asyncCreation.get(), | 90 stackTrace->setParent(asyncParent->buildInspectorObject(asyncCreation.get(), |
| 83 maxAsyncDepth - 1)); | 91 maxAsyncDepth - 1)); |
| 84 } | 92 } |
| 85 return stackTrace; | 93 return stackTrace; |
| 86 } | 94 } |
| 87 | 95 |
| 88 } // namespace | 96 } // namespace |
| 89 | 97 |
| 90 V8StackTraceImpl::Frame::Frame(v8::Local<v8::StackFrame> v8Frame) | 98 StackFrame::StackFrame(v8::Local<v8::StackFrame> v8Frame) |
| 91 : m_functionName(toProtocolString(v8Frame->GetFunctionName())), | 99 : m_functionName(toProtocolString(v8Frame->GetFunctionName())), |
| 92 m_scriptId(String16::fromInteger(v8Frame->GetScriptId())), | 100 m_scriptId(String16::fromInteger(v8Frame->GetScriptId())), |
| 93 m_sourceURL(toProtocolString(v8Frame->GetScriptNameOrSourceURL())), | 101 m_sourceURL(toProtocolString(v8Frame->GetScriptNameOrSourceURL())), |
| 94 m_lineNumber(v8Frame->GetLineNumber() - 1), | 102 m_lineNumber(v8Frame->GetLineNumber() - 1), |
| 95 m_columnNumber(v8Frame->GetColumn() - 1) { | 103 m_columnNumber(v8Frame->GetColumn() - 1) { |
| 96 DCHECK(m_lineNumber + 1 != v8::Message::kNoLineNumberInfo); | 104 DCHECK(m_lineNumber + 1 != v8::Message::kNoLineNumberInfo); |
| 97 DCHECK(m_columnNumber + 1 != v8::Message::kNoColumnInfo); | 105 DCHECK(m_columnNumber + 1 != v8::Message::kNoColumnInfo); |
| 98 } | 106 } |
| 99 | 107 |
| 100 void V8StackTraceImpl::Frame::translate(WasmTranslation* wasmTranslation) { | 108 void StackFrame::translate(WasmTranslation* wasmTranslation) { |
| 101 wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( | 109 wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( |
| 102 &m_scriptId, &m_lineNumber, &m_columnNumber); | 110 &m_scriptId, &m_lineNumber, &m_columnNumber); |
| 103 } | 111 } |
| 104 | 112 |
| 105 const String16& V8StackTraceImpl::Frame::functionName() const { | 113 const String16& StackFrame::functionName() const { return m_functionName; } |
| 106 return m_functionName; | |
| 107 } | |
| 108 | 114 |
| 109 const String16& V8StackTraceImpl::Frame::scriptId() const { return m_scriptId; } | 115 const String16& StackFrame::scriptId() const { return m_scriptId; } |
| 110 | 116 |
| 111 const String16& V8StackTraceImpl::Frame::sourceURL() const { | 117 const String16& StackFrame::sourceURL() const { return m_sourceURL; } |
| 112 return m_sourceURL; | |
| 113 } | |
| 114 | 118 |
| 115 int V8StackTraceImpl::Frame::lineNumber() const { return m_lineNumber; } | 119 int StackFrame::lineNumber() const { return m_lineNumber; } |
| 116 | 120 |
| 117 int V8StackTraceImpl::Frame::columnNumber() const { return m_columnNumber; } | 121 int StackFrame::columnNumber() const { return m_columnNumber; } |
| 118 | 122 |
| 119 std::unique_ptr<protocol::Runtime::CallFrame> | 123 std::unique_ptr<protocol::Runtime::CallFrame> StackFrame::buildInspectorObject() |
| 120 V8StackTraceImpl::Frame::buildInspectorObject() const { | 124 const { |
| 121 return protocol::Runtime::CallFrame::create() | 125 return protocol::Runtime::CallFrame::create() |
| 122 .setFunctionName(m_functionName) | 126 .setFunctionName(m_functionName) |
| 123 .setScriptId(m_scriptId) | 127 .setScriptId(m_scriptId) |
| 124 .setUrl(m_sourceURL) | 128 .setUrl(m_sourceURL) |
| 125 .setLineNumber(m_lineNumber) | 129 .setLineNumber(m_lineNumber) |
| 126 .setColumnNumber(m_columnNumber) | 130 .setColumnNumber(m_columnNumber) |
| 127 .build(); | 131 .build(); |
| 128 } | 132 } |
| 129 | 133 |
| 130 // static | 134 // static |
| 131 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions( | 135 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions( |
| 132 v8::Isolate* isolate, bool capture) { | 136 v8::Isolate* isolate, bool capture) { |
| 133 isolate->SetCaptureStackTraceForUncaughtExceptions( | 137 isolate->SetCaptureStackTraceForUncaughtExceptions( |
| 134 capture, V8StackTraceImpl::maxCallStackSizeToCapture); | 138 capture, V8StackTraceImpl::maxCallStackSizeToCapture); |
| 135 } | 139 } |
| 136 | 140 |
| 137 // static | 141 // static |
| 138 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 142 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
| 139 V8Debugger* debugger, int contextGroupId, | 143 V8Debugger* debugger, int contextGroupId, |
| 140 v8::Local<v8::StackTrace> v8StackTrace, int maxStackSize) { | 144 v8::Local<v8::StackTrace> v8StackTrace, int maxStackSize) { |
| 141 DCHECK(debugger); | 145 DCHECK(debugger); |
| 142 | 146 |
| 143 v8::Isolate* isolate = debugger->isolate(); | 147 v8::Isolate* isolate = debugger->isolate(); |
| 144 v8::HandleScope scope(isolate); | 148 v8::HandleScope scope(isolate); |
| 145 | 149 |
| 146 std::vector<V8StackTraceImpl::Frame> frames; | 150 std::vector<std::shared_ptr<StackFrame>> frames; |
| 147 if (!v8StackTrace.IsEmpty() && v8StackTrace->GetFrameCount()) { | 151 if (!v8StackTrace.IsEmpty() && v8StackTrace->GetFrameCount()) { |
| 148 frames = toFramesVector(debugger, v8StackTrace, maxStackSize); | 152 frames = toFramesVector(debugger, v8StackTrace, maxStackSize); |
| 149 } | 153 } |
| 150 | 154 |
| 151 int maxAsyncDepth = 0; | 155 int maxAsyncDepth = 0; |
| 152 std::shared_ptr<AsyncStackTrace> asyncParent; | 156 std::shared_ptr<AsyncStackTrace> asyncParent; |
| 153 std::shared_ptr<AsyncStackTrace> asyncCreation; | 157 std::shared_ptr<AsyncStackTrace> asyncCreation; |
| 154 calculateAsyncChain(debugger, contextGroupId, &asyncParent, &asyncCreation, | 158 calculateAsyncChain(debugger, contextGroupId, &asyncParent, &asyncCreation, |
| 155 &maxAsyncDepth); | 159 &maxAsyncDepth); |
| 156 if (frames.empty() && !asyncCreation && !asyncParent) return nullptr; | 160 if (frames.empty() && !asyncCreation && !asyncParent) return nullptr; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 167 v8::Local<v8::StackTrace> v8StackTrace; | 171 v8::Local<v8::StackTrace> v8StackTrace; |
| 168 if (isolate->InContext()) { | 172 if (isolate->InContext()) { |
| 169 v8StackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, | 173 v8StackTrace = v8::StackTrace::CurrentStackTrace(isolate, maxStackSize, |
| 170 stackTraceOptions); | 174 stackTraceOptions); |
| 171 } | 175 } |
| 172 return V8StackTraceImpl::create(debugger, contextGroupId, v8StackTrace, | 176 return V8StackTraceImpl::create(debugger, contextGroupId, v8StackTrace, |
| 173 maxStackSize); | 177 maxStackSize); |
| 174 } | 178 } |
| 175 | 179 |
| 176 V8StackTraceImpl::V8StackTraceImpl( | 180 V8StackTraceImpl::V8StackTraceImpl( |
| 177 const std::vector<Frame> frames, int maxAsyncDepth, | 181 const std::vector<std::shared_ptr<StackFrame>>& frames, int maxAsyncDepth, |
| 178 std::shared_ptr<AsyncStackTrace> asyncParent, | 182 std::shared_ptr<AsyncStackTrace> asyncParent, |
| 179 std::shared_ptr<AsyncStackTrace> asyncCreation) | 183 std::shared_ptr<AsyncStackTrace> asyncCreation) |
| 180 : m_frames(frames), | 184 : m_frames(frames), |
| 181 m_maxAsyncDepth(maxAsyncDepth), | 185 m_maxAsyncDepth(maxAsyncDepth), |
| 182 m_asyncParent(asyncParent), | 186 m_asyncParent(asyncParent), |
| 183 m_asyncCreation(asyncCreation) {} | 187 m_asyncCreation(asyncCreation) {} |
| 184 | 188 |
| 185 V8StackTraceImpl::~V8StackTraceImpl() {} | 189 V8StackTraceImpl::~V8StackTraceImpl() {} |
| 186 | 190 |
| 187 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { | 191 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { |
| 188 return std::unique_ptr<V8StackTrace>( | 192 return std::unique_ptr<V8StackTrace>( |
| 189 new V8StackTraceImpl(m_frames, 0, std::shared_ptr<AsyncStackTrace>(), | 193 new V8StackTraceImpl(m_frames, 0, std::shared_ptr<AsyncStackTrace>(), |
| 190 std::shared_ptr<AsyncStackTrace>())); | 194 std::shared_ptr<AsyncStackTrace>())); |
| 191 } | 195 } |
| 192 | 196 |
| 193 bool V8StackTraceImpl::isEmpty() const { return m_frames.empty(); } | 197 bool V8StackTraceImpl::isEmpty() const { return m_frames.empty(); } |
| 194 | 198 |
| 195 StringView V8StackTraceImpl::topSourceURL() const { | 199 StringView V8StackTraceImpl::topSourceURL() const { |
| 196 return toStringView(m_frames[0].sourceURL()); | 200 return toStringView(m_frames[0]->sourceURL()); |
| 197 } | 201 } |
| 198 | 202 |
| 199 int V8StackTraceImpl::topLineNumber() const { | 203 int V8StackTraceImpl::topLineNumber() const { |
| 200 return m_frames[0].lineNumber() + 1; | 204 return m_frames[0]->lineNumber() + 1; |
| 201 } | 205 } |
| 202 | 206 |
| 203 int V8StackTraceImpl::topColumnNumber() const { | 207 int V8StackTraceImpl::topColumnNumber() const { |
| 204 return m_frames[0].columnNumber() + 1; | 208 return m_frames[0]->columnNumber() + 1; |
| 205 } | 209 } |
| 206 | 210 |
| 207 StringView V8StackTraceImpl::topScriptId() const { | 211 StringView V8StackTraceImpl::topScriptId() const { |
| 208 return toStringView(m_frames[0].scriptId()); | 212 return toStringView(m_frames[0]->scriptId()); |
| 209 } | 213 } |
| 210 | 214 |
| 211 StringView V8StackTraceImpl::topFunctionName() const { | 215 StringView V8StackTraceImpl::topFunctionName() const { |
| 212 return toStringView(m_frames[0].functionName()); | 216 return toStringView(m_frames[0]->functionName()); |
| 213 } | 217 } |
| 214 | 218 |
| 215 std::unique_ptr<protocol::Runtime::StackTrace> | 219 std::unique_ptr<protocol::Runtime::StackTrace> |
| 216 V8StackTraceImpl::buildInspectorObjectImpl() const { | 220 V8StackTraceImpl::buildInspectorObjectImpl() const { |
| 217 return buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), | 221 return buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), |
| 218 m_asyncCreation.lock(), m_maxAsyncDepth); | 222 m_asyncCreation.lock(), m_maxAsyncDepth); |
| 219 } | 223 } |
| 220 | 224 |
| 221 std::unique_ptr<protocol::Runtime::API::StackTrace> | 225 std::unique_ptr<protocol::Runtime::API::StackTrace> |
| 222 V8StackTraceImpl::buildInspectorObject() const { | 226 V8StackTraceImpl::buildInspectorObject() const { |
| 223 return buildInspectorObjectImpl(); | 227 return buildInspectorObjectImpl(); |
| 224 } | 228 } |
| 225 | 229 |
| 226 std::unique_ptr<StringBuffer> V8StackTraceImpl::toString() const { | 230 std::unique_ptr<StringBuffer> V8StackTraceImpl::toString() const { |
| 227 String16Builder stackTrace; | 231 String16Builder stackTrace; |
| 228 for (size_t i = 0; i < m_frames.size(); ++i) { | 232 for (size_t i = 0; i < m_frames.size(); ++i) { |
| 229 const Frame& frame = m_frames[i]; | 233 const StackFrame& frame = *m_frames[i]; |
| 230 stackTrace.append("\n at " + (frame.functionName().length() | 234 stackTrace.append("\n at " + (frame.functionName().length() |
| 231 ? frame.functionName() | 235 ? frame.functionName() |
| 232 : "(anonymous function)")); | 236 : "(anonymous function)")); |
| 233 stackTrace.append(" ("); | 237 stackTrace.append(" ("); |
| 234 stackTrace.append(frame.sourceURL()); | 238 stackTrace.append(frame.sourceURL()); |
| 235 stackTrace.append(':'); | 239 stackTrace.append(':'); |
| 236 stackTrace.append(String16::fromInteger(frame.lineNumber() + 1)); | 240 stackTrace.append(String16::fromInteger(frame.lineNumber() + 1)); |
| 237 stackTrace.append(':'); | 241 stackTrace.append(':'); |
| 238 stackTrace.append(String16::fromInteger(frame.columnNumber() + 1)); | 242 stackTrace.append(String16::fromInteger(frame.columnNumber() + 1)); |
| 239 stackTrace.append(')'); | 243 stackTrace.append(')'); |
| 240 } | 244 } |
| 241 String16 string = stackTrace.toString(); | 245 String16 string = stackTrace.toString(); |
| 242 return StringBufferImpl::adopt(string); | 246 return StringBufferImpl::adopt(string); |
| 243 } | 247 } |
| 244 | 248 |
| 245 // static | 249 // static |
| 246 std::shared_ptr<AsyncStackTrace> AsyncStackTrace::capture( | 250 std::shared_ptr<AsyncStackTrace> AsyncStackTrace::capture( |
| 247 V8Debugger* debugger, int contextGroupId, const String16& description, | 251 V8Debugger* debugger, int contextGroupId, const String16& description, |
| 248 int maxStackSize) { | 252 int maxStackSize) { |
| 249 DCHECK(debugger); | 253 DCHECK(debugger); |
| 250 | 254 |
| 251 v8::Isolate* isolate = debugger->isolate(); | 255 v8::Isolate* isolate = debugger->isolate(); |
| 252 v8::HandleScope handleScope(isolate); | 256 v8::HandleScope handleScope(isolate); |
| 253 | 257 |
| 254 std::vector<V8StackTraceImpl::Frame> frames; | 258 std::vector<std::shared_ptr<StackFrame>> frames; |
| 255 if (isolate->InContext()) { | 259 if (isolate->InContext()) { |
| 256 v8::Local<v8::StackTrace> v8StackTrace = v8::StackTrace::CurrentStackTrace( | 260 v8::Local<v8::StackTrace> v8StackTrace = v8::StackTrace::CurrentStackTrace( |
| 257 isolate, maxStackSize, stackTraceOptions); | 261 isolate, maxStackSize, stackTraceOptions); |
| 258 frames = toFramesVector(debugger, v8StackTrace, maxStackSize); | 262 frames = toFramesVector(debugger, v8StackTrace, maxStackSize); |
| 259 } | 263 } |
| 260 | 264 |
| 261 std::shared_ptr<AsyncStackTrace> asyncParent; | 265 std::shared_ptr<AsyncStackTrace> asyncParent; |
| 262 std::shared_ptr<AsyncStackTrace> asyncCreation; | 266 std::shared_ptr<AsyncStackTrace> asyncCreation; |
| 263 calculateAsyncChain(debugger, contextGroupId, &asyncParent, &asyncCreation, | 267 calculateAsyncChain(debugger, contextGroupId, &asyncParent, &asyncCreation, |
| 264 nullptr); | 268 nullptr); |
| 265 | 269 |
| 266 if (frames.empty() && !asyncCreation && !asyncParent) return nullptr; | 270 if (frames.empty() && !asyncCreation && !asyncParent) return nullptr; |
| 267 | 271 |
| 268 // When async call chain is empty but doesn't contain useful schedule stack | 272 // When async call chain is empty but doesn't contain useful schedule stack |
| 269 // and parent async call chain contains creationg stack but doesn't | 273 // and parent async call chain contains creationg stack but doesn't |
| 270 // synchronous we can merge them together. | 274 // synchronous we can merge them together. |
| 271 // e.g. Promise ThenableJob. | 275 // e.g. Promise ThenableJob. |
| 272 if (asyncParent && frames.empty() && | 276 if (asyncParent && frames.empty() && |
| 273 asyncParent->m_description == description && !asyncCreation) { | 277 asyncParent->m_description == description && !asyncCreation) { |
| 274 return asyncParent; | 278 return asyncParent; |
| 275 } | 279 } |
| 276 | 280 |
| 277 return std::shared_ptr<AsyncStackTrace>(new AsyncStackTrace( | 281 return std::shared_ptr<AsyncStackTrace>(new AsyncStackTrace( |
| 278 contextGroupId, description, frames, asyncParent, asyncCreation)); | 282 contextGroupId, description, frames, asyncParent, asyncCreation)); |
| 279 } | 283 } |
| 280 | 284 |
| 281 AsyncStackTrace::AsyncStackTrace( | 285 AsyncStackTrace::AsyncStackTrace( |
| 282 int contextGroupId, const String16& description, | 286 int contextGroupId, const String16& description, |
| 283 const std::vector<V8StackTraceImpl::Frame>& frames, | 287 const std::vector<std::shared_ptr<StackFrame>>& frames, |
| 284 std::shared_ptr<AsyncStackTrace> asyncParent, | 288 std::shared_ptr<AsyncStackTrace> asyncParent, |
| 285 std::shared_ptr<AsyncStackTrace> asyncCreation) | 289 std::shared_ptr<AsyncStackTrace> asyncCreation) |
| 286 : m_contextGroupId(contextGroupId), | 290 : m_contextGroupId(contextGroupId), |
| 287 m_description(description), | 291 m_description(description), |
| 288 m_frames(frames), | 292 m_frames(frames), |
| 289 m_asyncParent(asyncParent), | 293 m_asyncParent(asyncParent), |
| 290 m_asyncCreation(asyncCreation) {} | 294 m_asyncCreation(asyncCreation) {} |
| 291 | 295 |
| 292 std::unique_ptr<protocol::Runtime::StackTrace> | 296 std::unique_ptr<protocol::Runtime::StackTrace> |
| 293 AsyncStackTrace::buildInspectorObject(AsyncStackTrace* asyncCreation, | 297 AsyncStackTrace::buildInspectorObject(AsyncStackTrace* asyncCreation, |
| 294 int maxAsyncDepth) const { | 298 int maxAsyncDepth) const { |
| 295 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = | 299 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = |
| 296 buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), | 300 buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), |
| 297 m_asyncCreation.lock(), maxAsyncDepth); | 301 m_asyncCreation.lock(), maxAsyncDepth); |
| 298 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); | 302 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); |
| 299 if (asyncCreation && !asyncCreation->isEmpty()) { | 303 if (asyncCreation && !asyncCreation->isEmpty()) { |
| 300 stackTrace->setPromiseCreationFrame( | 304 stackTrace->setPromiseCreationFrame( |
| 301 asyncCreation->m_frames[0].buildInspectorObject()); | 305 asyncCreation->m_frames[0]->buildInspectorObject()); |
| 302 } | 306 } |
| 303 return stackTrace; | 307 return stackTrace; |
| 304 } | 308 } |
| 305 | 309 |
| 306 int AsyncStackTrace::contextGroupId() const { return m_contextGroupId; } | 310 int AsyncStackTrace::contextGroupId() const { return m_contextGroupId; } |
| 307 | 311 |
| 308 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::parent() const { | 312 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::parent() const { |
| 309 return m_asyncParent; | 313 return m_asyncParent; |
| 310 } | 314 } |
| 311 | 315 |
| 312 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::creation() const { | 316 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::creation() const { |
| 313 return m_asyncCreation; | 317 return m_asyncCreation; |
| 314 } | 318 } |
| 315 | 319 |
| 316 bool AsyncStackTrace::isEmpty() const { return m_frames.empty(); } | 320 bool AsyncStackTrace::isEmpty() const { return m_frames.empty(); } |
| 317 | 321 |
| 318 } // namespace v8_inspector | 322 } // namespace v8_inspector |
| OLD | NEW |