Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / renderer / logging_native_handler.cc
blob86fbc9c9fbe4d1cb62f4910b2f195b06b5c20c7d
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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/strings/stringprintf.h"
7 #include "extensions/renderer/logging_native_handler.h"
8 #include "extensions/renderer/script_context.h"
10 namespace extensions {
12 LoggingNativeHandler::LoggingNativeHandler(ScriptContext* context)
13 : ObjectBackedNativeHandler(context) {
14 RouteFunction(
15 "DCHECK",
16 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this)));
17 RouteFunction(
18 "CHECK",
19 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this)));
20 RouteFunction(
21 "DCHECK_IS_ON",
22 base::Bind(&LoggingNativeHandler::DcheckIsOn, base::Unretained(this)));
23 RouteFunction("LOG",
24 base::Bind(&LoggingNativeHandler::Log, base::Unretained(this)));
25 RouteFunction(
26 "WARNING",
27 base::Bind(&LoggingNativeHandler::Warning, base::Unretained(this)));
30 LoggingNativeHandler::~LoggingNativeHandler() {}
32 void LoggingNativeHandler::Check(
33 const v8::FunctionCallbackInfo<v8::Value>& args) {
34 bool check_value;
35 std::string error_message;
36 ParseArgs(args, &check_value, &error_message);
37 CHECK(check_value) << error_message;
40 void LoggingNativeHandler::Dcheck(
41 const v8::FunctionCallbackInfo<v8::Value>& args) {
42 bool check_value;
43 std::string error_message;
44 ParseArgs(args, &check_value, &error_message);
45 DCHECK(check_value) << error_message;
48 void LoggingNativeHandler::DcheckIsOn(
49 const v8::FunctionCallbackInfo<v8::Value>& args) {
50 args.GetReturnValue().Set(DCHECK_IS_ON());
53 void LoggingNativeHandler::Log(
54 const v8::FunctionCallbackInfo<v8::Value>& args) {
55 CHECK_EQ(1, args.Length());
56 LOG(INFO) << *v8::String::Utf8Value(args[0]);
59 void LoggingNativeHandler::Warning(
60 const v8::FunctionCallbackInfo<v8::Value>& args) {
61 CHECK_EQ(1, args.Length());
62 LOG(WARNING) << *v8::String::Utf8Value(args[0]);
65 void LoggingNativeHandler::ParseArgs(
66 const v8::FunctionCallbackInfo<v8::Value>& args,
67 bool* check_value,
68 std::string* error_message) {
69 CHECK_LE(args.Length(), 2);
70 *check_value = args[0]->BooleanValue();
71 if (args.Length() == 2) {
72 *error_message = "Error: " + std::string(*v8::String::Utf8Value(args[1]));
75 *error_message += "\n" + context()->GetStackTraceAsString();
78 } // namespace extensions