diff --git a/include/v8-inspector.h b/include/v8-inspector.h index c88b307ef8..d43c2ead0b 100644 --- a/include/v8-inspector.h +++ b/include/v8-inspector.h @@ -32,19 +32,19 @@ namespace Debugger { namespace API { class SearchMatch; } -} +} // namespace Debugger namespace Runtime { namespace API { class RemoteObject; class StackTrace; class StackTraceId; -} -} +} // namespace API +} // namespace Runtime namespace Schema { namespace API { class Domain; } -} +} // namespace Schema } // namespace protocol class V8_EXPORT StringView { @@ -134,6 +134,13 @@ class V8_EXPORT V8DebuggerId { int64_t m_second = 0; }; +struct V8_EXPORT V8StackFrame { + StringView sourceURL; + StringView functionName; + int lineNumber; + int columnNumber; +}; + class V8_EXPORT V8StackTrace { public: virtual StringView firstNonEmptySourceURL() const = 0; @@ -151,6 +158,8 @@ class V8_EXPORT V8StackTrace { // Safe to pass between threads, drops async chain. virtual std::unique_ptr clone() = 0; + + virtual std::vector frames() const = 0; }; class V8_EXPORT V8InspectorSession { diff --git a/src/inspector/v8-stack-trace-impl.cc b/src/inspector/v8-stack-trace-impl.cc index c46de4465d..0b3c0839d3 100644 --- a/src/inspector/v8-stack-trace-impl.cc +++ b/src/inspector/v8-stack-trace-impl.cc @@ -1,4 +1,5 @@ // Copyright 2016 the V8 project authors. All rights reserved. +// // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +11,8 @@ #include "src/inspector/v8-stack-trace-impl.h" #include +#include +#include #include "../../third_party/inspector_protocol/crdtp/json.h" #include "src/debug/debug-interface.h" @@ -313,6 +316,21 @@ StringView V8StackTraceImpl::topFunctionName() const { return toStringView(m_frames[0]->functionName()); } +std::vector V8StackTraceImpl::frames() const { + std::vector ret; + ret.reserve(m_frames.size()); + + for (const auto& frame : m_frames) { + if (frame) { + ret.emplace_back(V8StackFrame{ + toStringView(frame->sourceURL()), toStringView(frame->functionName()), + frame->lineNumber() + 1, frame->columnNumber() + 1}); + } + } + + return ret; +} + std::unique_ptr V8StackTraceImpl::buildInspectorObjectImpl(V8Debugger* debugger) const { return buildInspectorObjectImpl(debugger, m_maxAsyncDepth); diff --git a/src/inspector/v8-stack-trace-impl.h b/src/inspector/v8-stack-trace-impl.h index 221700a195..bf793b0b51 100644 --- a/src/inspector/v8-stack-trace-impl.h +++ b/src/inspector/v8-stack-trace-impl.h @@ -84,6 +84,8 @@ class V8StackTraceImpl : public V8StackTrace { bool isEqualIgnoringTopFrame(V8StackTraceImpl* stackTrace) const; + std::vector frames() const override; + private: V8StackTraceImpl(std::vector> frames, int maxAsyncDepth,