OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "extensions/common/stack_frame.h" | 5 #include "extensions/common/stack_frame.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "third_party/re2/src/re2/re2.h" | 10 #include "third_party/re2/src/re2/re2.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 StackFrame::~StackFrame() { | 38 StackFrame::~StackFrame() { |
39 } | 39 } |
40 | 40 |
41 // Create a stack frame from the passed text. The text must follow one of two | 41 // Create a stack frame from the passed text. The text must follow one of two |
42 // formats: | 42 // formats: |
43 // - "function_name (source:line_number:column_number)" | 43 // - "function_name (source:line_number:column_number)" |
44 // - "source:line_number:column_number" | 44 // - "source:line_number:column_number" |
45 // (We have to recognize two formats because V8 will report stack traces in | 45 // (We have to recognize two formats because V8 will report stack traces in |
46 // both ways. If we reconcile this, we can clean this up.) | 46 // both ways. If we reconcile this, we can clean this up.) |
47 // static | 47 // static |
48 scoped_ptr<StackFrame> StackFrame::CreateFromText( | 48 std::unique_ptr<StackFrame> StackFrame::CreateFromText( |
49 const base::string16& frame_text) { | 49 const base::string16& frame_text) { |
50 // We need to use utf8 for re2 matching. | 50 // We need to use utf8 for re2 matching. |
51 std::string text = base::UTF16ToUTF8(frame_text); | 51 std::string text = base::UTF16ToUTF8(frame_text); |
52 | 52 |
53 size_t line = 1; | 53 size_t line = 1; |
54 size_t column = 1; | 54 size_t column = 1; |
55 std::string source; | 55 std::string source; |
56 std::string function; | 56 std::string function; |
57 if (!re2::RE2::FullMatch(text, | 57 if (!re2::RE2::FullMatch(text, |
58 "(.+) \\(([^\\(\\)]+):(\\d+):(\\d+)\\)", | 58 "(.+) \\(([^\\(\\)]+):(\\d+):(\\d+)\\)", |
59 &function, &source, &line, &column) && | 59 &function, &source, &line, &column) && |
60 !re2::RE2::FullMatch(text, | 60 !re2::RE2::FullMatch(text, |
61 "([^\\(\\)]+):(\\d+):(\\d+)", | 61 "([^\\(\\)]+):(\\d+):(\\d+)", |
62 &source, &line, &column)) { | 62 &source, &line, &column)) { |
63 return scoped_ptr<StackFrame>(); | 63 return std::unique_ptr<StackFrame>(); |
64 } | 64 } |
65 | 65 |
66 return scoped_ptr<StackFrame>(new StackFrame(line, | 66 return std::unique_ptr<StackFrame>(new StackFrame( |
67 column, | 67 line, column, base::UTF8ToUTF16(source), base::UTF8ToUTF16(function))); |
68 base::UTF8ToUTF16(source), | |
69 base::UTF8ToUTF16(function))); | |
70 } | 68 } |
71 | 69 |
72 bool StackFrame::operator==(const StackFrame& rhs) const { | 70 bool StackFrame::operator==(const StackFrame& rhs) const { |
73 return line_number == rhs.line_number && | 71 return line_number == rhs.line_number && |
74 column_number == rhs.column_number && | 72 column_number == rhs.column_number && |
75 source == rhs.source && | 73 source == rhs.source && |
76 function == rhs.function; | 74 function == rhs.function; |
77 } | 75 } |
78 | 76 |
79 } // namespace extensions | 77 } // namespace extensions |
OLD | NEW |