| 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/console.h" | 5 #include "extensions/renderer/console.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 | 60 |
| 61 void BindLogMethod(v8::Isolate* isolate, | 61 void BindLogMethod(v8::Isolate* isolate, |
| 62 v8::Local<v8::Object> target, | 62 v8::Local<v8::Object> target, |
| 63 const std::string& name, | 63 const std::string& name, |
| 64 LogMethod log_method) { | 64 LogMethod log_method) { |
| 65 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( | 65 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( |
| 66 isolate, | 66 isolate, |
| 67 &BoundLogMethodCallback, | 67 &BoundLogMethodCallback, |
| 68 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); | 68 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); |
| 69 tmpl->RemovePrototype(); |
| 69 v8::Local<v8::Function> function; | 70 v8::Local<v8::Function> function; |
| 70 if (!tmpl->GetFunction(isolate->GetCurrentContext()).ToLocal(&function)) { | 71 if (!tmpl->GetFunction(isolate->GetCurrentContext()).ToLocal(&function)) { |
| 71 LOG(FATAL) << "Could not create log function \"" << name << "\""; | 72 LOG(FATAL) << "Could not create log function \"" << name << "\""; |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 v8::Local<v8::String> v8_name = ToV8StringUnsafe(isolate, name); | 75 v8::Local<v8::String> v8_name = ToV8StringUnsafe(isolate, name); |
| 75 if (!SetProperty(isolate->GetCurrentContext(), target, v8_name, function)) { | 76 if (!SetProperty(isolate->GetCurrentContext(), target, v8_name, function)) { |
| 76 LOG(WARNING) << "Could not bind log method \"" << name << "\""; | 77 LOG(WARNING) << "Could not bind log method \"" << name << "\""; |
| 77 } | 78 } |
| 78 SetProperty(isolate->GetCurrentContext(), target, v8_name, | 79 SetProperty(isolate->GetCurrentContext(), target, v8_name, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 v8::Local<v8::Object> console_object = v8::Object::New(isolate); | 119 v8::Local<v8::Object> console_object = v8::Object::New(isolate); |
| 119 BindLogMethod(isolate, console_object, "debug", &Debug); | 120 BindLogMethod(isolate, console_object, "debug", &Debug); |
| 120 BindLogMethod(isolate, console_object, "log", &Log); | 121 BindLogMethod(isolate, console_object, "log", &Log); |
| 121 BindLogMethod(isolate, console_object, "warn", &Warn); | 122 BindLogMethod(isolate, console_object, "warn", &Warn); |
| 122 BindLogMethod(isolate, console_object, "error", &Error); | 123 BindLogMethod(isolate, console_object, "error", &Error); |
| 123 return handle_scope.Escape(console_object); | 124 return handle_scope.Escape(console_object); |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace console | 127 } // namespace console |
| 127 } // namespace extensions | 128 } // namespace extensions |
| OLD | NEW |