From 0740b2f66bc4a15a7633dc1242e1f9f6ac3a4cf9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 12 Oct 2016 09:33:28 -0700 Subject: [PATCH] Reuse Log method --- atom/app/node_main.cc | 13 ++++--------- atom/common/api/atom_bindings.cc | 9 +++++---- atom/common/api/atom_bindings.h | 2 ++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index be75404ffa5a..5eceb9d73364 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -4,11 +4,10 @@ #include "atom/app/node_main.h" -#include - #include "atom/app/uv_task_runner.h" #include "atom/browser/javascript_environment.h" #include "atom/browser/node_debugger.h" +#include "atom/common/api/atom_bindings.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "base/command_line.h" #include "base/feature_list.h" @@ -22,10 +21,6 @@ namespace atom { -void Log(const base::string16& message) { - std::cout << message << std::flush; -} - int NodeMain(int argc, char *argv[]) { base::CommandLine::Init(argc, argv); @@ -59,10 +54,10 @@ int NodeMain(int argc, char *argv[]) { if (node_debugger.IsRunning()) env->AssignToContext(v8::Debug::GetDebugContext()); - node::LoadEnvironment(env); + mate::Dictionary process(gin_env.isolate(), env->process_object()); + process.SetMethod("log", &AtomBindings::Log); - mate::Dictionary dict(gin_env.isolate(), env->process_object()); - dict.SetMethod("log", &Log); + node::LoadEnvironment(env); bool more; do { diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index 311e7e987183..27b3352f37de 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -79,10 +79,6 @@ void FatalErrorCallback(const char* location, const char* message) { Crash(); } -void Log(const base::string16& message) { - std::cout << message << std::flush; -} - } // namespace @@ -157,4 +153,9 @@ void AtomBindings::OnCallNextTick(uv_async_t* handle) { self->pending_next_ticks_.clear(); } +// static +void AtomBindings::Log(const base::string16& message) { + std::cout << message << std::flush; +} + } // namespace atom diff --git a/atom/common/api/atom_bindings.h b/atom/common/api/atom_bindings.h index 39f3b53a227d..2e4c4a937b37 100644 --- a/atom/common/api/atom_bindings.h +++ b/atom/common/api/atom_bindings.h @@ -27,6 +27,8 @@ class AtomBindings { // load native code from Electron instead. void BindTo(v8::Isolate* isolate, v8::Local process); + static void Log(const base::string16& message); + private: void ActivateUVLoop(v8::Isolate* isolate);