Use the function converter from native_mate.
This commit is contained in:
parent
b8d5aa586e
commit
f60d8066f8
12 changed files with 9 additions and 274 deletions
3
atom.gyp
3
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',
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
|
@ -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_
|
|
@ -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_
|
|
@ -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.
|
||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 3d713baa4c33baebfac82b242e8897504592c590
|
||||
Subproject commit 1387d3969eff042a214ffe02b33f4d41372d3d3d
|
Loading…
Reference in a new issue