[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "gin/try_catch.h" | ||||
6 | |||||
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame^] | 7 | #include <sstream> |
8 | |||||
9 | #include "base/logging.h" | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 10 | #include "gin/converter.h" |
11 | |||||
12 | namespace gin { | ||||
13 | |||||
14 | TryCatch::TryCatch() { | ||||
15 | } | ||||
16 | |||||
17 | TryCatch::~TryCatch() { | ||||
18 | } | ||||
19 | |||||
20 | bool TryCatch::HasCaught() { | ||||
21 | return try_catch_.HasCaught(); | ||||
22 | } | ||||
23 | |||||
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame^] | 24 | std::string TryCatch::GetStackTrace() { |
25 | std::stringstream ss; | ||||
26 | v8::Handle<v8::Message> message = try_catch_.Message(); | ||||
27 | ss << V8ToString(message->Get()) << std::endl | ||||
28 | << V8ToString(message->GetSourceLine()) << std::endl; | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 29 | |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame^] | 30 | v8::Handle<v8::StackTrace> trace = message->GetStackTrace(); |
31 | if (trace.IsEmpty()) | ||||
32 | return ss.str(); | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 33 | |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame^] | 34 | int len = trace->GetFrameCount(); |
35 | for (int i = 0; i < len; ++i) { | ||||
36 | v8::Handle<v8::StackFrame> frame = trace->GetFrame(i); | ||||
37 | ss << V8ToString(frame->GetScriptName()) << ":" | ||||
38 | << frame->GetLineNumber() << ":" | ||||
39 | << frame->GetColumn() << ": " | ||||
40 | << V8ToString(frame->GetFunctionName()) | ||||
41 | << std::endl; | ||||
42 | } | ||||
43 | return ss.str(); | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 44 | } |
45 | |||||
46 | } // namespace gin |