| 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 #ifndef SourceLocation_h | 5 #ifndef SourceLocation_h |
| 6 #define SourceLocation_h | 6 #define SourceLocation_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/CrossThreadCopier.h" | 9 #include "platform/CrossThreadCopier.h" |
| 10 #include "platform/v8_inspector/public/V8StackTrace.h" | 10 #include "platform/v8_inspector/public/V8StackTrace.h" |
| 11 #include "wtf/Forward.h" | 11 #include "wtf/Forward.h" |
| 12 #include "wtf/PassOwnPtr.h" | |
| 13 #include "wtf/text/WTFString.h" | 12 #include "wtf/text/WTFString.h" |
| 13 #include <memory> |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class ExecutionContext; | 17 class ExecutionContext; |
| 18 class TracedValue; | 18 class TracedValue; |
| 19 class V8StackTrace; | 19 class V8StackTrace; |
| 20 | 20 |
| 21 namespace protocol { namespace Runtime { class StackTrace; }} | 21 namespace protocol { namespace Runtime { class StackTrace; }} |
| 22 | 22 |
| 23 class CORE_EXPORT SourceLocation { | 23 class CORE_EXPORT SourceLocation { |
| 24 public: | 24 public: |
| 25 // Zero lineNumber and columnNumber mean unknown. Captures current stack tra
ce. | 25 // Zero lineNumber and columnNumber mean unknown. Captures current stack tra
ce. |
| 26 static PassOwnPtr<SourceLocation> capture(const String& url, unsigned lineNu
mber, unsigned columnNumber); | 26 static std::unique_ptr<SourceLocation> capture(const String& url, unsigned l
ineNumber, unsigned columnNumber); |
| 27 | 27 |
| 28 // Shortcut when location is unknown. Tries to capture call stack or parsing
location if available. | 28 // Shortcut when location is unknown. Tries to capture call stack or parsing
location if available. |
| 29 static PassOwnPtr<SourceLocation> capture(ExecutionContext* = nullptr); | 29 static std::unique_ptr<SourceLocation> capture(ExecutionContext* = nullptr); |
| 30 | 30 |
| 31 static PassOwnPtr<SourceLocation> fromMessage(v8::Isolate*, v8::Local<v8::Me
ssage>, ExecutionContext*); | 31 static std::unique_ptr<SourceLocation> fromMessage(v8::Isolate*, v8::Local<v
8::Message>, ExecutionContext*); |
| 32 | 32 |
| 33 static PassOwnPtr<SourceLocation> fromFunction(v8::Local<v8::Function>); | 33 static std::unique_ptr<SourceLocation> fromFunction(v8::Local<v8::Function>)
; |
| 34 | 34 |
| 35 // Forces full stack trace. | 35 // Forces full stack trace. |
| 36 static PassOwnPtr<SourceLocation> captureWithFullStackTrace(); | 36 static std::unique_ptr<SourceLocation> captureWithFullStackTrace(); |
| 37 | 37 |
| 38 static PassOwnPtr<SourceLocation> create(const String& url, unsigned lineNum
ber, unsigned columnNumber, std::unique_ptr<V8StackTrace>, int scriptId = 0); | 38 static std::unique_ptr<SourceLocation> create(const String& url, unsigned li
neNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace>, int scriptId = 0
); |
| 39 ~SourceLocation(); | 39 ~SourceLocation(); |
| 40 | 40 |
| 41 bool isUnknown() const { return m_url.isNull() && !m_scriptId && !m_lineNumb
er; } | 41 bool isUnknown() const { return m_url.isNull() && !m_scriptId && !m_lineNumb
er; } |
| 42 const String& url() const { return m_url; } | 42 const String& url() const { return m_url; } |
| 43 unsigned lineNumber() const { return m_lineNumber; } | 43 unsigned lineNumber() const { return m_lineNumber; } |
| 44 unsigned columnNumber() const { return m_columnNumber; } | 44 unsigned columnNumber() const { return m_columnNumber; } |
| 45 int scriptId() const { return m_scriptId; } | 45 int scriptId() const { return m_scriptId; } |
| 46 | 46 |
| 47 PassOwnPtr<SourceLocation> clone() const; | 47 std::unique_ptr<SourceLocation> clone() const; |
| 48 PassOwnPtr<SourceLocation> isolatedCopy() const; // Safe to pass between thr
eads. | 48 std::unique_ptr<SourceLocation> isolatedCopy() const; // Safe to pass betwee
n threads. |
| 49 | 49 |
| 50 // No-op when stack trace is unknown. | 50 // No-op when stack trace is unknown. |
| 51 void toTracedValue(TracedValue*, const char* name) const; | 51 void toTracedValue(TracedValue*, const char* name) const; |
| 52 | 52 |
| 53 // Could be null string when stack trace is unknown. | 53 // Could be null string when stack trace is unknown. |
| 54 String toString() const; | 54 String toString() const; |
| 55 | 55 |
| 56 // Could be null when stack trace is unknown. | 56 // Could be null when stack trace is unknown. |
| 57 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject() const; | 57 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject() const; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber
, std::unique_ptr<V8StackTrace>, int scriptId); | 60 SourceLocation(const String& url, unsigned lineNumber, unsigned columnNumber
, std::unique_ptr<V8StackTrace>, int scriptId); |
| 61 static PassOwnPtr<SourceLocation> createFromNonEmptyV8StackTrace(std::unique
_ptr<V8StackTrace>, int scriptId); | 61 static std::unique_ptr<SourceLocation> createFromNonEmptyV8StackTrace(std::u
nique_ptr<V8StackTrace>, int scriptId); |
| 62 | 62 |
| 63 String m_url; | 63 String m_url; |
| 64 unsigned m_lineNumber; | 64 unsigned m_lineNumber; |
| 65 unsigned m_columnNumber; | 65 unsigned m_columnNumber; |
| 66 std::unique_ptr<V8StackTrace> m_stackTrace; | 66 std::unique_ptr<V8StackTrace> m_stackTrace; |
| 67 int m_scriptId; | 67 int m_scriptId; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 template <> | 70 template <> |
| 71 struct CrossThreadCopier<PassOwnPtr<SourceLocation>> { | 71 struct CrossThreadCopier<std::unique_ptr<SourceLocation>> { |
| 72 using Type = PassOwnPtr<SourceLocation>; | 72 using Type = std::unique_ptr<SourceLocation>; |
| 73 static Type copy(PassOwnPtr<SourceLocation> location) | 73 static Type copy(std::unique_ptr<SourceLocation> location) |
| 74 { | 74 { |
| 75 return location ? location->isolatedCopy() : nullptr; | 75 return location ? location->isolatedCopy() : nullptr; |
| 76 } | 76 } |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace blink | 79 } // namespace blink |
| 80 | 80 |
| 81 #endif // SourceLocation_h | 81 #endif // SourceLocation_h |
| OLD | NEW |