LCOV - code coverage report
Current view: top level - src/inspector - v8-stack-trace-impl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2017-10-20 Functions: 2 2 100.0 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_INSPECTOR_V8STACKTRACEIMPL_H_
       6             : #define V8_INSPECTOR_V8STACKTRACEIMPL_H_
       7             : 
       8             : #include <memory>
       9             : #include <vector>
      10             : 
      11             : #include "include/v8-inspector.h"
      12             : #include "include/v8.h"
      13             : #include "src/base/macros.h"
      14             : #include "src/inspector/protocol/Runtime.h"
      15             : #include "src/inspector/string-16.h"
      16             : 
      17             : namespace v8_inspector {
      18             : 
      19             : class AsyncStackTrace;
      20             : class V8Debugger;
      21             : class WasmTranslation;
      22             : 
      23             : class StackFrame {
      24             :  public:
      25             :   explicit StackFrame(v8::Local<v8::StackFrame> frame);
      26       65634 :   ~StackFrame() = default;
      27             : 
      28             :   void translate(WasmTranslation* wasmTranslation);
      29             : 
      30             :   const String16& functionName() const;
      31             :   const String16& scriptId() const;
      32             :   const String16& sourceURL() const;
      33             :   int lineNumber() const;    // 0-based.
      34             :   int columnNumber() const;  // 0-based.
      35             :   std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject() const;
      36             :   bool isEqual(StackFrame* frame) const;
      37             : 
      38             :  private:
      39             :   String16 m_functionName;
      40             :   String16 m_scriptId;
      41             :   String16 m_sourceURL;
      42             :   int m_lineNumber;    // 0-based.
      43             :   int m_columnNumber;  // 0-based.
      44             : };
      45             : 
      46             : class V8StackTraceImpl : public V8StackTrace {
      47             :  public:
      48             :   static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*,
      49             :                                                         bool capture);
      50             :   static const int maxCallStackSizeToCapture = 200;
      51             :   static std::unique_ptr<V8StackTraceImpl> create(V8Debugger*,
      52             :                                                   int contextGroupId,
      53             :                                                   v8::Local<v8::StackTrace>,
      54             :                                                   int maxStackSize);
      55             :   static std::unique_ptr<V8StackTraceImpl> capture(V8Debugger*,
      56             :                                                    int contextGroupId,
      57             :                                                    int maxStackSize);
      58             : 
      59             :   ~V8StackTraceImpl() override;
      60             :   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl()
      61             :       const;
      62             : 
      63             :   // V8StackTrace implementation.
      64             :   // This method drops the async stack trace.
      65             :   std::unique_ptr<V8StackTrace> clone() override;
      66             :   bool isEmpty() const override;
      67             :   StringView topSourceURL() const override;
      68             :   int topLineNumber() const override;    // 1-based.
      69             :   int topColumnNumber() const override;  // 1-based.
      70             :   StringView topScriptId() const override;
      71             :   StringView topFunctionName() const override;
      72             :   std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject()
      73             :       const override;
      74             :   std::unique_ptr<StringBuffer> toString() const override;
      75             : 
      76             :   bool isEqualIgnoringTopFrame(V8StackTraceImpl* stackTrace) const;
      77             : 
      78             :  private:
      79             :   V8StackTraceImpl(std::vector<std::shared_ptr<StackFrame>> frames,
      80             :                    int maxAsyncDepth,
      81             :                    std::shared_ptr<AsyncStackTrace> asyncParent,
      82             :                    std::shared_ptr<AsyncStackTrace> asyncCreation);
      83             : 
      84             :   class StackFrameIterator {
      85             :    public:
      86             :     explicit StackFrameIterator(const V8StackTraceImpl* stackTrace);
      87             : 
      88             :     void next();
      89             :     StackFrame* frame();
      90             :     bool done();
      91             : 
      92             :    private:
      93             :     std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentIt;
      94             :     std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentEnd;
      95             :     AsyncStackTrace* m_parent;
      96             :   };
      97             : 
      98             :   std::vector<std::shared_ptr<StackFrame>> m_frames;
      99             :   int m_maxAsyncDepth;
     100             :   std::weak_ptr<AsyncStackTrace> m_asyncParent;
     101             :   std::weak_ptr<AsyncStackTrace> m_asyncCreation;
     102             : 
     103             :   DISALLOW_COPY_AND_ASSIGN(V8StackTraceImpl);
     104             : };
     105             : 
     106      119841 : class AsyncStackTrace {
     107             :  public:
     108             :   static std::shared_ptr<AsyncStackTrace> capture(V8Debugger*,
     109             :                                                   int contextGroupId,
     110             :                                                   const String16& description,
     111             :                                                   int maxStackSize);
     112             : 
     113             :   std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject(
     114             :       AsyncStackTrace* asyncCreation, int maxAsyncDepth) const;
     115             : 
     116             :   int contextGroupId() const;
     117             :   const String16& description() const;
     118             :   std::weak_ptr<AsyncStackTrace> parent() const;
     119             :   std::weak_ptr<AsyncStackTrace> creation() const;
     120             :   bool isEmpty() const;
     121             : 
     122             :   void setDescription(const String16& description) {
     123             :     // TODO(kozyatinskiy): implement it without hack.
     124        2010 :     m_description = description;
     125             :   }
     126             :   const std::vector<std::shared_ptr<StackFrame>>& frames() const {
     127             :     return m_frames;
     128             :   }
     129             : 
     130             :  private:
     131             :   AsyncStackTrace(int contextGroupId, const String16& description,
     132             :                   std::vector<std::shared_ptr<StackFrame>> frames,
     133             :                   std::shared_ptr<AsyncStackTrace> asyncParent,
     134             :                   std::shared_ptr<AsyncStackTrace> asyncCreation);
     135             : 
     136             :   int m_contextGroupId;
     137             :   String16 m_description;
     138             : 
     139             :   std::vector<std::shared_ptr<StackFrame>> m_frames;
     140             :   std::weak_ptr<AsyncStackTrace> m_asyncParent;
     141             :   std::weak_ptr<AsyncStackTrace> m_asyncCreation;
     142             : 
     143             :   DISALLOW_COPY_AND_ASSIGN(AsyncStackTrace);
     144             : };
     145             : 
     146             : }  // namespace v8_inspector
     147             : 
     148             : #endif  // V8_INSPECTOR_V8STACKTRACEIMPL_H_

Generated by: LCOV version 1.10