Chromium Code Reviews| 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 "gin/try_catch.h" | 5 #include "gin/try_catch.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/logging.h" | |
| 10 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 11 | 10 |
| 12 namespace gin { | 11 namespace gin { |
| 13 | 12 |
| 14 TryCatch::TryCatch() { | 13 TryCatch::TryCatch() { |
| 15 } | 14 } |
| 16 | 15 |
| 17 TryCatch::~TryCatch() { | 16 TryCatch::~TryCatch() { |
| 18 } | 17 } |
| 19 | 18 |
| 20 bool TryCatch::HasCaught() { | 19 bool TryCatch::HasCaught() { |
| 21 return try_catch_.HasCaught(); | 20 return try_catch_.HasCaught(); |
| 22 } | 21 } |
| 23 | 22 |
| 24 std::string TryCatch::GetStackTrace() { | 23 std::string TryCatch::GetStackTrace() { |
| 24 if (!HasCaught()) { | |
| 25 return ""; | |
| 26 } | |
| 27 | |
| 25 std::stringstream ss; | 28 std::stringstream ss; |
| 26 v8::Handle<v8::Message> message = try_catch_.Message(); | 29 v8::Handle<v8::Message> message = try_catch_.Message(); |
|
Aaron Boodman
2013/12/04 07:05:29
FYI, this technically doesn't adhere to the styleg
abarth-chromium
2013/12/04 16:27:55
Oh! Sorry. :)
| |
| 27 ss << V8ToString(message->Get()) << std::endl | 30 ss << V8ToString(message->Get()) << std::endl |
| 28 << V8ToString(message->GetSourceLine()) << std::endl; | 31 << V8ToString(message->GetSourceLine()) << std::endl; |
| 29 | 32 |
| 30 v8::Handle<v8::StackTrace> trace = message->GetStackTrace(); | 33 v8::Handle<v8::StackTrace> trace = message->GetStackTrace(); |
| 31 if (trace.IsEmpty()) | 34 if (trace.IsEmpty()) |
| 32 return ss.str(); | 35 return ss.str(); |
| 33 | 36 |
| 34 int len = trace->GetFrameCount(); | 37 int len = trace->GetFrameCount(); |
| 35 for (int i = 0; i < len; ++i) { | 38 for (int i = 0; i < len; ++i) { |
| 36 v8::Handle<v8::StackFrame> frame = trace->GetFrame(i); | 39 v8::Handle<v8::StackFrame> frame = trace->GetFrame(i); |
| 37 ss << V8ToString(frame->GetScriptName()) << ":" | 40 ss << V8ToString(frame->GetScriptName()) << ":" |
| 38 << frame->GetLineNumber() << ":" | 41 << frame->GetLineNumber() << ":" |
| 39 << frame->GetColumn() << ": " | 42 << frame->GetColumn() << ": " |
| 40 << V8ToString(frame->GetFunctionName()) | 43 << V8ToString(frame->GetFunctionName()) |
| 41 << std::endl; | 44 << std::endl; |
| 42 } | 45 } |
| 43 return ss.str(); | 46 return ss.str(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 } // namespace gin | 49 } // namespace gin |
| OLD | NEW |