]> khamidou — GitHub mirrors - electron.git/commitdiff
Use the function converter from native_mate.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 10 Aug 2014 11:14:20 +0000 (19:14 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 10 Aug 2014 11:14:20 +0000 (19:14 +0800)
12 files changed:
atom.gyp
atom/browser/api/atom_api_content_tracing.cc
atom/browser/api/atom_api_dialog.cc
atom/browser/api/atom_api_global_shortcut.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/api/atom_api_window.cc
atom/common/api/atom_bindings.cc
atom/common/browser_v8_locker.cc [deleted file]
atom/common/browser_v8_locker.h [deleted file]
atom/common/native_mate_converters/function_converter.h [deleted file]
atom/common/node_bindings.cc
vendor/native_mate

index 3de8c7b1a9387d96cec861cbf9474675641b9aac..bf8b33655d4e768b42b0ab1867dabee793c4dfe7 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       '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',
       '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',
index b5057a838a33da61f87983a136e4fbd244ed2653..e5894a771ba2eafa37f7f31532a2d367cd44410d 100644 (file)
@@ -5,9 +5,9 @@
 #include <set>
 
 #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"
index 6305b5f2479287a4c5df1ca73b04b8c4d08c431e..6a1a7a4b5763c4dd18959948eaae88fd490dd75e 100644 (file)
@@ -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"
index 827cd01ecb8363b9befeeb6dbe54feaf0bc107ec..f3e46a4d4051c3552f2b419e51fb6f90e6e74382 100644 (file)
@@ -7,8 +7,8 @@
 #include <string>
 
 #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"
index 29ec8507c54232665f22690e3a0545441d420dc9..24e7d32b2867c1926ed43927dd3b90af6031c204 100644 (file)
@@ -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"
 
index 25f2edcb5cb568289e0f8ddf09d2dc43f01ff2fa..cc7f9319ab8d02a78c72e9ad4c0255f924b73c71 100644 (file)
@@ -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"
index 13191b461830d7c6538c76416ba16079b89ce694..0a051b64c98c0514902cd7eaa0163c618417d19f 100644 (file)
@@ -7,10 +7,9 @@
 #include <string>
 
 #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 (file)
index 584dcfd..0000000
+++ /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 (file)
index 01a54bb..0000000
+++ /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<v8::Locker> 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 (file)
index b10f4c5..0000000
+++ /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<RefCountedPersistent<v8::Function> > SafeV8Function;
-
-// Helper to convert type to V8 with storage type (const T& to T).
-template<typename T>
-v8::Handle<v8::Value> ConvertToV8(v8::Isolate* isolate, T a) {
-  return Converter<typename base::internal::CallbackParamTraits<T>::StorageType>
-      ::ToV8(isolate, a);
-}
-
-// This set of templates invokes a V8::Function by converting the C++ types.
-template<typename Sig>
-struct V8FunctionInvoker;
-
-template<typename R>
-struct V8FunctionInvoker<R()> {
-  static R Go(v8::Isolate* isolate, SafeV8Function function) {
-    R ret;
-    atom::BrowserV8Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
-    v8::Handle<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> val(holder->Call(holder, 0, NULL));
-    Converter<R>::FromV8(isolate, val, &ret);
-    return ret;
-  }
-};
-
-template<>
-struct V8FunctionInvoker<void()> {
-  static void Go(v8::Isolate* isolate, SafeV8Function function) {
-    atom::BrowserV8Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
-    v8::Handle<v8::Function> holder = function->NewHandle();
-    holder->Call(holder, 0, NULL);
-  }
-};
-
-template<typename R, typename P1>
-struct V8FunctionInvoker<R(P1)> {
-  static R Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) {
-    R ret;
-    atom::BrowserV8Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
-    v8::Handle<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-    };
-    v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args));
-    Converter<R>::FromV8(isolate, val, &ret);
-    return ret;
-  }
-};
-
-template<typename P1>
-struct V8FunctionInvoker<void(P1)> {
-  static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1) {
-    atom::BrowserV8Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
-    v8::Handle<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-    };
-    holder->Call(holder, arraysize(args), args);
-  }
-};
-
-template<typename R, typename P1, typename P2>
-struct V8FunctionInvoker<R(P1, P2)> {
-  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<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-    };
-    v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args));
-    Converter<R>::FromV8(isolate, val, &ret);
-    return ret;
-  }
-};
-
-template<typename P1, typename P2>
-struct V8FunctionInvoker<void(P1, P2)> {
-  static void Go(v8::Isolate* isolate, SafeV8Function function, P1 a1, P2 a2) {
-    atom::BrowserV8Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
-    v8::Handle<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-    };
-    holder->Call(holder, arraysize(args), args);
-  }
-};
-
-template<typename R, typename P1, typename P2, typename P3>
-struct V8FunctionInvoker<R(P1, P2, P3)> {
-  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<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-        ConvertToV8(isolate, a3),
-    };
-    v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args));
-    Converter<R>::FromV8(isolate, val, &ret);
-    return ret;
-  }
-};
-
-template<typename P1, typename P2, typename P3>
-struct V8FunctionInvoker<void(P1, P2, P3)> {
-  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<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-        ConvertToV8(isolate, a3),
-    };
-    holder->Call(holder, arraysize(args), args);
-  }
-};
-
-template<typename R, typename P1, typename P2, typename P3, typename P4>
-struct V8FunctionInvoker<R(P1, P2, P3, P4)> {
-  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<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-        ConvertToV8(isolate, a3),
-        ConvertToV8(isolate, a4),
-    };
-    v8::Handle<v8::Value> val(holder->Call(holder, arraysize(args), args));
-    Converter<R>::FromV8(isolate, val, &ret);
-    return ret;
-  }
-};
-
-template<typename P1, typename P2, typename P3, typename P4>
-struct V8FunctionInvoker<void(P1, P2, P3, P4)> {
-  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<v8::Function> holder = function->NewHandle();
-    v8::Handle<v8::Value> args[] = {
-        ConvertToV8(isolate, a1),
-        ConvertToV8(isolate, a2),
-        ConvertToV8(isolate, a3),
-        ConvertToV8(isolate, a4),
-    };
-    holder->Call(holder, arraysize(args), args);
-  }
-};
-
-}  // namespace internal
-
-template<typename Sig>
-struct Converter<base::Callback<Sig> > {
-  static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
-                                    const base::Callback<Sig>& val) {
-    return CreateFunctionTemplate(isolate, val)->GetFunction();
-  }
-  static bool FromV8(v8::Isolate* isolate,
-                     v8::Handle<v8::Value> val,
-                     base::Callback<Sig>* out) {
-    if (!val->IsFunction())
-      return false;
-
-    internal::SafeV8Function function(
-        new RefCountedPersistent<v8::Function>(val));
-    *out = base::Bind(&internal::V8FunctionInvoker<Sig>::Go, isolate, function);
-    return true;
-  }
-};
-
-}  // namespace mate
-
-#endif  // ATOM_COMMON_NATIVE_MATE_CONVERTERS_FUNCTION_CONVERTER_H_
index c757e1a574a0b99ab12a8e579f05e1ab2b3c195c..a4dec37f3bd56fbdd39d792420b462087d84094c 100644 (file)
@@ -7,13 +7,13 @@
 #include <string>
 #include <vector>
 
-#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.
index 3d713baa4c33baebfac82b242e8897504592c590..1387d3969eff042a214ffe02b33f4d41372d3d3d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3d713baa4c33baebfac82b242e8897504592c590
+Subproject commit 1387d3969eff042a214ffe02b33f4d41372d3d3d