| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/logging_native_handler.h" | 5 #include "extensions/renderer/logging_native_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void LoggingNativeHandler::ParseArgs( | 65 void LoggingNativeHandler::ParseArgs( |
| 66 const v8::FunctionCallbackInfo<v8::Value>& args, | 66 const v8::FunctionCallbackInfo<v8::Value>& args, |
| 67 bool* check_value, | 67 bool* check_value, |
| 68 std::string* error_message) { | 68 std::string* error_message) { |
| 69 CHECK_LE(args.Length(), 2); | 69 CHECK_LE(args.Length(), 2); |
| 70 *check_value = args[0]->BooleanValue(); | 70 *check_value = args[0]->BooleanValue(); |
| 71 if (args.Length() == 2) { | 71 if (args.Length() == 2) { |
| 72 *error_message = "Error: " + std::string(*v8::String::Utf8Value(args[1])); | 72 *error_message = "Error: " + std::string(*v8::String::Utf8Value(args[1])); |
| 73 } | 73 } |
| 74 | 74 |
| 75 v8::Handle<v8::StackTrace> stack_trace = | 75 v8::Local<v8::StackTrace> stack_trace = |
| 76 v8::StackTrace::CurrentStackTrace(args.GetIsolate(), 10); | 76 v8::StackTrace::CurrentStackTrace(args.GetIsolate(), 10); |
| 77 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { | 77 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { |
| 78 *error_message += "\n <no stack trace>"; | 78 *error_message += "\n <no stack trace>"; |
| 79 } else { | 79 } else { |
| 80 for (size_t i = 0; i < (size_t)stack_trace->GetFrameCount(); ++i) { | 80 for (size_t i = 0; i < (size_t)stack_trace->GetFrameCount(); ++i) { |
| 81 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); | 81 v8::Local<v8::StackFrame> frame = stack_trace->GetFrame(i); |
| 82 CHECK(!frame.IsEmpty()); | 82 CHECK(!frame.IsEmpty()); |
| 83 *error_message += base::StringPrintf( | 83 *error_message += base::StringPrintf( |
| 84 "\n at %s (%s:%d:%d)", | 84 "\n at %s (%s:%d:%d)", |
| 85 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), | 85 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), |
| 86 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), | 86 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), |
| 87 frame->GetLineNumber(), | 87 frame->GetLineNumber(), |
| 88 frame->GetColumn()); | 88 frame->GetColumn()); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 std::string LoggingNativeHandler::ToStringOrDefault( | 93 std::string LoggingNativeHandler::ToStringOrDefault( |
| 94 const v8::Handle<v8::String>& v8_string, | 94 const v8::Local<v8::String>& v8_string, |
| 95 const std::string& dflt) { | 95 const std::string& dflt) { |
| 96 if (v8_string.IsEmpty()) | 96 if (v8_string.IsEmpty()) |
| 97 return dflt; | 97 return dflt; |
| 98 std::string ascii_value = *v8::String::Utf8Value(v8_string); | 98 std::string ascii_value = *v8::String::Utf8Value(v8_string); |
| 99 return ascii_value.empty() ? dflt : ascii_value; | 99 return ascii_value.empty() ? dflt : ascii_value; |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace extensions | 102 } // namespace extensions |
| OLD | NEW |