From f60d8066f8e5061286afbdf0de86bfc3b667f6ab Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 10 Aug 2014 19:14:20 +0800 Subject: [PATCH] Use the function converter from native_mate. --- atom.gyp | 3 - atom/browser/api/atom_api_content_tracing.cc | 2 +- atom/browser/api/atom_api_dialog.cc | 3 +- atom/browser/api/atom_api_global_shortcut.cc | 2 +- atom/browser/api/atom_api_protocol.cc | 2 +- atom/browser/api/atom_api_window.cc | 4 +- atom/common/api/atom_bindings.cc | 3 +- atom/common/browser_v8_locker.cc | 21 -- atom/common/browser_v8_locker.h | 28 --- .../function_converter.h | 209 ------------------ atom/common/node_bindings.cc | 4 +- vendor/native_mate | 2 +- 12 files changed, 9 insertions(+), 274 deletions(-) delete mode 100644 atom/common/browser_v8_locker.cc delete mode 100644 atom/common/browser_v8_locker.h delete mode 100644 atom/common/native_mate_converters/function_converter.h diff --git a/atom.gyp b/atom.gyp index 3de8c7b1a938..bf8b33655d4e 100644 --- a/atom.gyp +++ b/atom.gyp @@ -175,8 +175,6 @@ 'atom/common/api/atom_bindings.h', 'atom/common/api/object_life_monitor.cc', 'atom/common/api/object_life_monitor.h', - 'atom/common/browser_v8_locker.cc', - 'atom/common/browser_v8_locker.h', 'atom/common/crash_reporter/crash_reporter.cc', 'atom/common/crash_reporter/crash_reporter.h', 'atom/common/crash_reporter/crash_reporter_linux.cc', @@ -197,7 +195,6 @@ 'atom/common/native_mate_converters/accelerator_converter.cc', 'atom/common/native_mate_converters/accelerator_converter.h', 'atom/common/native_mate_converters/file_path_converter.h', - 'atom/common/native_mate_converters/function_converter.h', 'atom/common/native_mate_converters/gurl_converter.h', 'atom/common/native_mate_converters/image_converter.cc', 'atom/common/native_mate_converters/image_converter.h', diff --git a/atom/browser/api/atom_api_content_tracing.cc b/atom/browser/api/atom_api_content_tracing.cc index b5057a838a33..e5894a771ba2 100644 --- a/atom/browser/api/atom_api_content_tracing.cc +++ b/atom/browser/api/atom_api_content_tracing.cc @@ -5,9 +5,9 @@ #include #include "atom/common/native_mate_converters/file_path_converter.h" -#include "atom/common/native_mate_converters/function_converter.h" #include "base/bind.h" #include "content/public/browser/tracing_controller.h" +#include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "atom/common/node_includes.h" diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 6305b5f24792..6a1a7a4b5763 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -11,8 +11,7 @@ #include "atom/browser/ui/file_dialog.h" #include "atom/browser/ui/message_box.h" #include "atom/common/native_mate_converters/file_path_converter.h" -#include "atom/common/native_mate_converters/function_converter.h" -#include "base/bind.h" +#include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "atom/common/node_includes.h" diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index 827cd01ecb83..f3e46a4d4051 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -7,8 +7,8 @@ #include #include "atom/common/native_mate_converters/accelerator_converter.h" -#include "atom/common/native_mate_converters/function_converter.h" #include "base/stl_util.h" +#include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "atom/common/node_includes.h" diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 29ec8507c542..24e7d32b2867 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -10,8 +10,8 @@ #include "atom/browser/net/atom_url_request_context_getter.h" #include "atom/browser/net/atom_url_request_job_factory.h" #include "atom/common/native_mate_converters/file_path_converter.h" -#include "atom/common/native_mate_converters/function_converter.h" #include "content/public/browser/browser_thread.h" +#include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "net/url_request/url_request_context.h" diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 25f2edcb5cb5..cc7f9319ab8d 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -6,10 +6,8 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/native_window.h" -#include "atom/common/native_mate_converters/function_converter.h" -#include "base/bind.h" -#include "base/callback.h" #include "content/public/browser/render_process_host.h" +#include "native_mate/callback.h" #include "native_mate/constructor.h" #include "native_mate/dictionary.h" #include "ui/gfx/point.h" diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index 13191b461830..0a051b64c98c 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -7,10 +7,9 @@ #include #include "atom/common/atom_version.h" -#include "atom/common/native_mate_converters/function_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" -#include "base/callback.h" #include "base/logging.h" +#include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "atom/common/node_includes.h" diff --git a/atom/common/browser_v8_locker.cc b/atom/common/browser_v8_locker.cc deleted file mode 100644 index 584dcfded80a..000000000000 --- a/atom/common/browser_v8_locker.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/common/browser_v8_locker.h" - -namespace node { -extern bool g_standalone_mode; -} - -namespace atom { - -BrowserV8Locker::BrowserV8Locker(v8::Isolate* isolate) { - if (node::g_standalone_mode) - locker_.reset(new v8::Locker(isolate)); -} - -BrowserV8Locker::~BrowserV8Locker() { -} - -} // namespace atom diff --git a/atom/common/browser_v8_locker.h b/atom/common/browser_v8_locker.h deleted file mode 100644 index 01a54bbbd220..000000000000 --- a/atom/common/browser_v8_locker.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_BROWSER_V8_LOCKER_H_ -#define ATOM_COMMON_BROWSER_V8_LOCKER_H_ - -#include "base/memory/scoped_ptr.h" -#include "v8/include/v8.h" - -namespace atom { - -// Like v8::Locker, but only do lock when in browser process. -class BrowserV8Locker { - public: - explicit BrowserV8Locker(v8::Isolate* isolate); - ~BrowserV8Locker(); - - private: - void* operator new(size_t size); - void operator delete(void*, size_t); - - scoped_ptr locker_; -}; - -} // namespace atom - -#endif // ATOM_COMMON_BROWSER_V8_LOCKER_H_ diff --git a/atom/common/native_mate_converters/function_converter.h b/atom/common/native_mate_converters/function_converter.h deleted file mode 100644 index b10f4c5d8df4..000000000000 --- a/atom/common/native_mate_converters/function_converter.h +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_FUNCTION_CONVERTER_H_ -#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_FUNCTION_CONVERTER_H_ - -#include "atom/common/browser_v8_locker.h" -#include "base/bind.h" -#include "base/callback.h" -#include "native_mate/constructor.h" -#include "native_mate/scoped_persistent.h" - -namespace mate { - -namespace internal { - -typedef scoped_refptr > SafeV8Function; - -// Helper to convert type to V8 with storage type (const T& to T). -template -v8::Handle ConvertToV8(v8::Isolate* isolate, T a) { - return Converter::StorageType> - ::ToV8(isolate, a); -} - -// This set of templates invokes a V8::Function by converting the C++ types. -template -struct V8FunctionInvoker; - -template -struct V8FunctionInvoker { - static R Go(v8::Isolate* isolate, SafeV8Function function) { - R ret; - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle val(holder->Call(holder, 0, NULL)); - Converter::FromV8(isolate, val, &ret); - return ret; - } -}; - -template<> -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, SafeV8Function function) { - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - holder->Call(holder, 0, NULL); - } -}; - -template -struct V8FunctionInvoker { - static R Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) { - R ret; - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - }; - v8::Handle val(holder->Call(holder, arraysize(args), args)); - Converter::FromV8(isolate, val, &ret); - return ret; - } -}; - -template -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) { - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - }; - holder->Call(holder, arraysize(args), args); - } -}; - -template -struct V8FunctionInvoker { - static R Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2) { - R ret; - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - }; - v8::Handle val(holder->Call(holder, arraysize(args), args)); - Converter::FromV8(isolate, val, &ret); - return ret; - } -}; - -template -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2) { - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - }; - holder->Call(holder, arraysize(args), args); - } -}; - -template -struct V8FunctionInvoker { - static R Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2, - P3 a3) { - R ret; - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - ConvertToV8(isolate, a3), - }; - v8::Handle val(holder->Call(holder, arraysize(args), args)); - Converter::FromV8(isolate, val, &ret); - return ret; - } -}; - -template -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2, - P3 a3) { - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - ConvertToV8(isolate, a3), - }; - holder->Call(holder, arraysize(args), args); - } -}; - -template -struct V8FunctionInvoker { - static R Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2, - P3 a3, P4 a4) { - R ret; - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - ConvertToV8(isolate, a3), - ConvertToV8(isolate, a4), - }; - v8::Handle val(holder->Call(holder, arraysize(args), args)); - Converter::FromV8(isolate, val, &ret); - return ret; - } -}; - -template -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2, - P3 a3, P4 a4) { - atom::BrowserV8Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - v8::Handle holder = function->NewHandle(); - v8::Handle args[] = { - ConvertToV8(isolate, a1), - ConvertToV8(isolate, a2), - ConvertToV8(isolate, a3), - ConvertToV8(isolate, a4), - }; - holder->Call(holder, arraysize(args), args); - } -}; - -} // namespace internal - -template -struct Converter > { - static v8::Handle ToV8(v8::Isolate* isolate, - const base::Callback& val) { - return CreateFunctionTemplate(isolate, val)->GetFunction(); - } - static bool FromV8(v8::Isolate* isolate, - v8::Handle val, - base::Callback* out) { - if (!val->IsFunction()) - return false; - - internal::SafeV8Function function( - new RefCountedPersistent(val)); - *out = base::Bind(&internal::V8FunctionInvoker::Go, isolate, function); - return true; - } -}; - -} // namespace mate - -#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_FUNCTION_CONVERTER_H_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index c757e1a574a0..a4dec37f3bd5 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -7,13 +7,13 @@ #include #include -#include "atom/common/browser_v8_locker.h" #include "base/command_line.h" #include "base/base_paths.h" #include "base/files/file_path.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "content/public/browser/browser_thread.h" +#include "native_mate/locker.h" #if defined(OS_WIN) #include "base/strings/utf_string_conversions.h" @@ -246,7 +246,7 @@ void NodeBindings::UvRunOnce() { node::Environment* env = uv_env() ? uv_env() : global_env; // Use Locker in browser process. - BrowserV8Locker locker(env->isolate()); + mate::Locker locker(env->isolate()); v8::HandleScope handle_scope(env->isolate()); // Enter node context while dealing with uv events. diff --git a/vendor/native_mate b/vendor/native_mate index 3d713baa4c33..1387d3969eff 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit 3d713baa4c33baebfac82b242e8897504592c590 +Subproject commit 1387d3969eff042a214ffe02b33f4d41372d3d3d