Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: extensions/common/stack_frame.cc

Issue 23007021: Report Javascript Runtime Errors to the Error Console (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_feldman
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/common/stack_frame.h ('k') | extensions/common/stack_frame_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/stack_frame.cc
diff --git a/extensions/common/stack_frame.cc b/extensions/common/stack_frame.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2874963e30ecefa9cff08eee234df9a67bfe86e
--- /dev/null
+++ b/extensions/common/stack_frame.cc
@@ -0,0 +1,80 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/stack_frame.h"
+
+#include <string>
+
+#include "base/strings/utf_string_conversions.h"
+#include "third_party/re2/re2/re2.h"
+
+namespace extensions {
+
+namespace {
+const char kAnonymousFunction[] = "(anonymous function)";
+}
+
+StackFrame::StackFrame() : line_number(1), column_number(1) {
+}
+
+StackFrame::StackFrame(const StackFrame& frame)
+ : line_number(frame.line_number),
+ column_number(frame.column_number),
+ source(frame.source),
+ function(frame.function) {
+}
+
+StackFrame::StackFrame(size_t line_number,
+ size_t column_number,
+ const base::string16& source,
+ const base::string16& function)
+ : line_number(line_number),
+ column_number(column_number),
+ source(source),
+ function(function.empty() ? base::UTF8ToUTF16(kAnonymousFunction)
+ : function) {
+}
+
+StackFrame::~StackFrame() {
+}
+
+// Create a stack frame from the passed text. The text must follow one of two
+// formats:
+// - "function_name (source:line_number:column_number)"
+// - "source:line_number:column_number"
+// (We have to recognize two formats because V8 will report stack traces in
+// both ways. If we reconcile this, we can clean this up.)
+// static
+scoped_ptr<StackFrame> StackFrame::CreateFromText(
+ const base::string16& frame_text) {
+ // We need to use utf8 for re2 matching.
+ std::string text = base::UTF16ToUTF8(frame_text);
+
+ size_t line = 1;
+ size_t column = 1;
+ std::string source;
+ std::string function;
+ if (!re2::RE2::FullMatch(text,
+ "(.+) \\(([^\\(\\)]+):(\\d+):(\\d+)\\)",
+ &function, &source, &line, &column) &&
+ !re2::RE2::FullMatch(text,
+ "([^\\(\\)]+):(\\d+):(\\d+)",
+ &source, &line, &column)) {
+ return scoped_ptr<StackFrame>();
+ }
+
+ return scoped_ptr<StackFrame>(new StackFrame(line,
+ column,
+ base::UTF8ToUTF16(source),
+ base::UTF8ToUTF16(function)));
+}
+
+bool StackFrame::operator==(const StackFrame& rhs) const {
+ return line_number == rhs.line_number &&
+ column_number == rhs.column_number &&
+ source == rhs.source &&
+ function == rhs.function;
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/common/stack_frame.h ('k') | extensions/common/stack_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698