Use WebScopedRunV8Script in converted C++ functions

This commit is contained in:
Cheng Zhao 2015-08-07 19:34:00 +08:00
Родитель 5c18d89453
Коммит 1bb0dde360
12 изменённых файлов: 85 добавлений и 25 удалений

Просмотреть файл

@ -13,7 +13,7 @@
#include "atom/browser/native_window.h"
#include "atom/browser/web_view_guest_delegate.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/event_emitter_caller.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/gfx_converter.h"

Просмотреть файл

@ -7,7 +7,7 @@
#include <vector>
#include "atom/common/event_emitter_caller.h"
#include "atom/common/api/event_emitter_caller.h"
#include "native_mate/wrappable.h"
namespace content {

Просмотреть файл

@ -2,8 +2,9 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/event_emitter_caller.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/api/locker.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
@ -13,22 +14,13 @@ namespace mate {
namespace internal {
namespace {
// Returns whether current process is browser process, currently we detect it
// by checking whether current has used V8 Lock, but it might be a bad idea.
inline bool IsBrowserProcess() {
return v8::Locker::IsActive();
}
} // namespace
v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
v8::Local<v8::Object> obj,
ValueVector* args) {
// Perform microtask checkpoint after running JavaScript.
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
IsBrowserProcess() ? nullptr : new blink::WebScopedRunV8Script(isolate));
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
// Use node::MakeCallback to call the callback, and it will also run pending
// tasks in Node.js.
return node::MakeCallback(

Просмотреть файл

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#define ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#ifndef ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
#define ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
#include <vector>
@ -50,4 +50,4 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
} // namespace mate
#endif // ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#endif // ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_

17
atom/common/api/locker.cc Normal file
Просмотреть файл

@ -0,0 +1,17 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#include "atom/common/api/locker.h"
namespace mate {
Locker::Locker(v8::Isolate* isolate) {
if (IsBrowserProcess())
locker_.reset(new v8::Locker(isolate));
}
Locker::~Locker() {
}
} // namespace mate

34
atom/common/api/locker.h Normal file
Просмотреть файл

@ -0,0 +1,34 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE.chromium file.
#ifndef ATOM_COMMON_API_LOCKER_H_
#define ATOM_COMMON_API_LOCKER_H_
#include "base/memory/scoped_ptr.h"
#include "v8/include/v8.h"
namespace mate {
// Only lock when lockers are used in current thread.
class Locker {
public:
explicit Locker(v8::Isolate* isolate);
~Locker();
// Returns whether current process is browser process, currently we detect it
// by checking whether current has used V8 Lock, but it might be a bad idea.
static inline bool IsBrowserProcess() { return v8::Locker::IsActive(); }
private:
void* operator new(size_t size);
void operator delete(void*, size_t);
scoped_ptr<v8::Locker> locker_;
DISALLOW_COPY_AND_ASSIGN(Locker);
};
} // namespace mate
#endif // ATOM_COMMON_API_LOCKER_H_

Просмотреть файл

@ -2,13 +2,17 @@
// 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_CALLBACK_H_
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_H_
#include <vector>
#include "atom/common/api/locker.h"
#include "base/bind.h"
#include "base/callback.h"
#include "native_mate/function_template.h"
#include "native_mate/locker.h"
#include "native_mate/scoped_persistent.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
namespace mate {
@ -25,6 +29,9 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
ArgTypes... raw) {
Locker locker(isolate);
v8::EscapableHandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
@ -40,6 +47,9 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
@ -54,6 +64,9 @@ struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
@ -87,3 +100,5 @@ struct Converter<base::Callback<Sig> > {
};
} // namespace mate
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_H_

Просмотреть файл

@ -7,8 +7,9 @@
#include <string>
#include <vector>
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/api/locker.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/event_emitter_caller.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/command_line.h"
#include "base/base_paths.h"
@ -17,7 +18,6 @@
#include "base/path_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_paths.h"
#include "native_mate/locker.h"
#include "native_mate/dictionary.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"

Просмотреть файл

@ -11,7 +11,7 @@
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/event_emitter_caller.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h"
#include "atom/renderer/atom_renderer_client.h"

Просмотреть файл

@ -238,6 +238,10 @@
'atom/common/api/atom_api_v8_util.cc',
'atom/common/api/atom_bindings.cc',
'atom/common/api/atom_bindings.h',
'atom/common/api/event_emitter_caller.cc',
'atom/common/api/event_emitter_caller.h',
'atom/common/api/locker.cc',
'atom/common/api/locker.h',
'atom/common/api/object_life_monitor.cc',
'atom/common/api/object_life_monitor.h',
'atom/common/asar/archive.cc',
@ -266,8 +270,6 @@
'atom/common/crash_reporter/win/crash_service_main.h',
'atom/common/draggable_region.cc',
'atom/common/draggable_region.h',
'atom/common/event_emitter_caller.cc',
'atom/common/event_emitter_caller.h',
'atom/common/google_api_key.h',
'atom/common/id_weak_map.cc',
'atom/common/id_weak_map.h',

Просмотреть файл

@ -7,7 +7,7 @@ import sys
BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \
'http://gh-contractor-zcbenz.s3.amazonaws.com/libchromiumcontent'
'http://github-janky-artifacts.s3.amazonaws.com/libchromiumcontent'
LIBCHROMIUMCONTENT_COMMIT = 'dd51a41b42246b0b5159bfad5e327c8cf10bc585'
PLATFORM = {

2
vendor/native_mate поставляемый

@ -1 +1 @@
Subproject commit ebcf4c022467a43a5379446e1c031ffd10438b9c
Subproject commit 67d9eaa215e8727d86dc7b1f7a10be8699848f1f