blob: 97e7fe15f832b33af9d5648152c2f4986a0f137b [file] [log] [blame]
[email protected]855ab432013-11-18 17:09:361// 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]2f703422013-11-25 21:26:157#include <sstream>
8
[email protected]855ab432013-11-18 17:09:369#include "gin/converter.h"
10
11namespace gin {
12
13TryCatch::TryCatch() {
14}
15
16TryCatch::~TryCatch() {
17}
18
19bool TryCatch::HasCaught() {
20 return try_catch_.HasCaught();
21}
22
[email protected]2f703422013-11-25 21:26:1523std::string TryCatch::GetStackTrace() {
[email protected]bf3dd3c2013-12-06 06:55:2524 if (!HasCaught()) {
25 return "";
26 }
27
[email protected]2f703422013-11-25 21:26:1528 std::stringstream ss;
deepak.sfaaa1b62015-04-30 07:30:4829 v8::Local<v8::Message> message = try_catch_.Message();
[email protected]2f703422013-11-25 21:26:1530 ss << V8ToString(message->Get()) << std::endl
31 << V8ToString(message->GetSourceLine()) << std::endl;
[email protected]855ab432013-11-18 17:09:3632
deepak.sfaaa1b62015-04-30 07:30:4833 v8::Local<v8::StackTrace> trace = message->GetStackTrace();
[email protected]2f703422013-11-25 21:26:1534 if (trace.IsEmpty())
35 return ss.str();
[email protected]855ab432013-11-18 17:09:3636
[email protected]2f703422013-11-25 21:26:1537 int len = trace->GetFrameCount();
38 for (int i = 0; i < len; ++i) {
deepak.sfaaa1b62015-04-30 07:30:4839 v8::Local<v8::StackFrame> frame = trace->GetFrame(i);
[email protected]2f703422013-11-25 21:26:1540 ss << V8ToString(frame->GetScriptName()) << ":"
41 << frame->GetLineNumber() << ":"
42 << frame->GetColumn() << ": "
43 << V8ToString(frame->GetFunctionName())
44 << std::endl;
45 }
46 return ss.str();
[email protected]855ab432013-11-18 17:09:3647}
48
49} // namespace gin