Converter for base::Callback is not thread safe

This commit is contained in:
Cheng Zhao 2017-03-10 11:01:17 +09:00
parent bb5ad4ac05
commit 69df934710
4 changed files with 10 additions and 20 deletions

View file

@ -141,15 +141,16 @@ void InitAsarSupport(v8::Isolate* isolate,
v8::Local<v8::Value> result = asar_init->Run();
// Initialize asar support.
base::Callback<void(v8::Local<v8::Value>,
v8::Local<v8::Value>,
std::string)> init;
if (mate::ConvertFromV8(isolate, result, &init)) {
if (result->IsFunction()) {
const char* asar_native = reinterpret_cast<const char*>(
static_cast<const unsigned char*>(node::asar_data));
init.Run(process,
require,
std::string(asar_native, sizeof(node::asar_data) - 1));
base::StringPiece asar_data(asar_native, sizeof(node::asar_data) - 1);
v8::Local<v8::Value> args[] = {
process,
require,
mate::ConvertToV8(isolate, asar_data),
};
result.As<v8::Function>()->Call(result, 3, args);
}
}

View file

@ -4,8 +4,6 @@
#include "atom/common/native_mate_converters/callback.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace mate {

View file

@ -10,7 +10,9 @@
#include "atom/common/api/locker.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/function_template.h"
#include "native_mate/scoped_persistent.h"

View file

@ -25,8 +25,6 @@
#include "atom/common/node_includes.h"
using content::BrowserThread;
// Force all builtin modules to be referenced so they can actually run their
// DSO constructors, see http://git.io/DRIqCg.
#define REFERENCE_MODULE(name) \
@ -210,9 +208,6 @@ void NodeBindings::LoadEnvironment(node::Environment* env) {
}
void NodeBindings::PrepareMessageLoop() {
DCHECK(browser_env_ != BROWSER ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
// Add dummy handle for libuv, otherwise libuv would quit when there is
// nothing to do.
uv_async_init(uv_loop_, &dummy_uv_handle_, nullptr);
@ -223,9 +218,6 @@ void NodeBindings::PrepareMessageLoop() {
}
void NodeBindings::RunMessageLoop() {
DCHECK(browser_env_ != BROWSER ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
// The MessageLoop should have been created, remember the one in main thread.
task_runner_ = base::ThreadTaskRunnerHandle::Get();
@ -234,9 +226,6 @@ void NodeBindings::RunMessageLoop() {
}
void NodeBindings::UvRunOnce() {
DCHECK(browser_env_ != BROWSER ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
node::Environment* env = uv_env();
// Use Locker in browser process.