Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: gin/try_catch.cc

Issue 1161053002: Revert of gin: Use V8 Maybe APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maybe-gin-converter
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gin/try_catch.h ('k') | gin/wrappable.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gin/converter.h" 9 #include "gin/converter.h"
10 10
11 namespace {
12
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);
18 }
19
20 } // namespace
21
22 namespace gin { 11 namespace gin {
23 12
24 TryCatch::TryCatch(v8::Isolate* isolate) 13 TryCatch::TryCatch() {
25 : isolate_(isolate), try_catch_(isolate) {
26 } 14 }
27 15
28 TryCatch::~TryCatch() { 16 TryCatch::~TryCatch() {
29 } 17 }
30 18
31 bool TryCatch::HasCaught() { 19 bool TryCatch::HasCaught() {
32 return try_catch_.HasCaught(); 20 return try_catch_.HasCaught();
33 } 21 }
34 22
35 std::string TryCatch::GetStackTrace() { 23 std::string TryCatch::GetStackTrace() {
36 if (!HasCaught()) { 24 if (!HasCaught()) {
37 return ""; 25 return "";
38 } 26 }
39 27
40 std::stringstream ss; 28 std::stringstream ss;
41 v8::Local<v8::Message> message = try_catch_.Message(); 29 v8::Local<v8::Message> message = try_catch_.Message();
42 ss << V8ToString(message->Get()) << std::endl 30 ss << V8ToString(message->Get()) << std::endl
43 << V8ToString(GetSourceLine(isolate_, message)) << std::endl; 31 << V8ToString(message->GetSourceLine()) << std::endl;
44 32
45 v8::Local<v8::StackTrace> trace = message->GetStackTrace(); 33 v8::Local<v8::StackTrace> trace = message->GetStackTrace();
46 if (trace.IsEmpty()) 34 if (trace.IsEmpty())
47 return ss.str(); 35 return ss.str();
48 36
49 int len = trace->GetFrameCount(); 37 int len = trace->GetFrameCount();
50 for (int i = 0; i < len; ++i) { 38 for (int i = 0; i < len; ++i) {
51 v8::Local<v8::StackFrame> frame = trace->GetFrame(i); 39 v8::Local<v8::StackFrame> frame = trace->GetFrame(i);
52 ss << V8ToString(frame->GetScriptName()) << ":" 40 ss << V8ToString(frame->GetScriptName()) << ":"
53 << frame->GetLineNumber() << ":" 41 << frame->GetLineNumber() << ":"
54 << frame->GetColumn() << ": " 42 << frame->GetColumn() << ": "
55 << V8ToString(frame->GetFunctionName()) 43 << V8ToString(frame->GetFunctionName())
56 << std::endl; 44 << std::endl;
57 } 45 }
58 return ss.str(); 46 return ss.str();
59 } 47 }
60 48
61 } // namespace gin 49 } // namespace gin
OLDNEW
« no previous file with comments | « gin/try_catch.h ('k') | gin/wrappable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698