[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 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 9 | #include "gin/converter.h" |
10 | |||||
11 | namespace gin { | ||||
12 | |||||
13 | TryCatch::TryCatch() { | ||||
14 | } | ||||
15 | |||||
16 | TryCatch::~TryCatch() { | ||||
17 | } | ||||
18 | |||||
19 | bool TryCatch::HasCaught() { | ||||
20 | return try_catch_.HasCaught(); | ||||
21 | } | ||||
22 | |||||
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 23 | std::string TryCatch::GetStackTrace() { |
[email protected] | bf3dd3c | 2013-12-06 06:55:25 | [diff] [blame] | 24 | if (!HasCaught()) { |
25 | return ""; | ||||
26 | } | ||||
27 | |||||
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 28 | std::stringstream ss; |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame^] | 29 | v8::Local<v8::Message> message = try_catch_.Message(); |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 30 | ss << V8ToString(message->Get()) << std::endl |
31 | << V8ToString(message->GetSourceLine()) << std::endl; | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 32 | |
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame^] | 33 | v8::Local<v8::StackTrace> trace = message->GetStackTrace(); |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 34 | if (trace.IsEmpty()) |
35 | return ss.str(); | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 36 | |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 37 | int len = trace->GetFrameCount(); |
38 | for (int i = 0; i < len; ++i) { | ||||
deepak.s | faaa1b6 | 2015-04-30 07:30:48 | [diff] [blame^] | 39 | v8::Local<v8::StackFrame> frame = trace->GetFrame(i); |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 40 | ss << V8ToString(frame->GetScriptName()) << ":" |
41 | << frame->GetLineNumber() << ":" | ||||
42 | << frame->GetColumn() << ": " | ||||
43 | << V8ToString(frame->GetFunctionName()) | ||||
44 | << std::endl; | ||||
45 | } | ||||
46 | return ss.str(); | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 47 | } |
48 | |||||
49 | } // namespace gin |