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.
5 #include "gin/try_catch.h"
9 #include "gin/converter.h"
13 v8::Local
<v8::String
> GetSourceLine(v8::Isolate
* isolate
,
14 v8::Local
<v8::Message
> message
) {
15 auto maybe
= message
->GetSourceLine(isolate
->GetCurrentContext());
16 v8::Local
<v8::String
> source_line
;
17 return maybe
.ToLocal(&source_line
) ? source_line
: v8::String::Empty(isolate
);
24 TryCatch::TryCatch(v8::Isolate
* isolate
)
25 : isolate_(isolate
), try_catch_(isolate
) {
28 TryCatch::~TryCatch() {
31 bool TryCatch::HasCaught() {
32 return try_catch_
.HasCaught();
35 std::string
TryCatch::GetStackTrace() {
41 v8::Local
<v8::Message
> message
= try_catch_
.Message();
42 ss
<< V8ToString(message
->Get()) << std::endl
43 << V8ToString(GetSourceLine(isolate_
, message
)) << std::endl
;
45 v8::Local
<v8::StackTrace
> trace
= message
->GetStackTrace();
49 int len
= trace
->GetFrameCount();
50 for (int i
= 0; i
< len
; ++i
) {
51 v8::Local
<v8::StackFrame
> frame
= trace
->GetFrame(i
);
52 ss
<< V8ToString(frame
->GetScriptName()) << ":"
53 << frame
->GetLineNumber() << ":"
54 << frame
->GetColumn() << ": "
55 << V8ToString(frame
->GetFunctionName())