Use WebScopedRunV8Script in converted C++ functions
authorCheng Zhao <zcbenz@gmail.com>
Fri, 7 Aug 2015 11:34:00 +0000 (19:34 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 7 Aug 2015 11:37:17 +0000 (19:37 +0800)
12 files changed:
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/event_emitter.h
atom/common/api/event_emitter_caller.cc [moved from atom/common/event_emitter_caller.cc with 69% similarity]
atom/common/api/event_emitter_caller.h [moved from atom/common/event_emitter_caller.h with 92% similarity]
atom/common/api/locker.cc [new file with mode: 0644]
atom/common/api/locker.h [new file with mode: 0644]
atom/common/native_mate_converters/callback.h
atom/common/node_bindings.cc
atom/renderer/atom_render_view_observer.cc
filenames.gypi
script/lib/config.py
vendor/native_mate

index 6adcf53..63707f8 100644 (file)
@@ -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"
index 178c61d..4fb953b 100644 (file)
@@ -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 {
similarity index 69%
rename from atom/common/event_emitter_caller.cc
rename to atom/common/api/event_emitter_caller.cc
index 68c4821..6b0a07a 100644 (file)
@@ -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(
similarity index 92%
rename from atom/common/event_emitter_caller.h
rename to atom/common/api/event_emitter_caller.h
index e8ad50a..a2567da 100644 (file)
@@ -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_
diff --git a/atom/common/api/locker.cc b/atom/common/api/locker.cc
new file mode 100644 (file)
index 0000000..fe0b234
--- /dev/null
@@ -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
diff --git a/atom/common/api/locker.h b/atom/common/api/locker.h
new file mode 100644 (file)
index 0000000..201217f
--- /dev/null
@@ -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_
index e7dc6af..6e51cda 100644 (file)
@@ -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_
index b329589..304b6a7 100644 (file)
@@ -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"
 
index 6864813..1f199ea 100644 (file)
@@ -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"
index 977eb16..b062c6e 100644 (file)
       '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',
       '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',
index 144ec87..1298651 100644 (file)
@@ -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 = {
index ebcf4c0..67d9eaa 160000 (submodule)
@@ -1 +1 @@
-Subproject commit ebcf4c022467a43a5379446e1c031ffd10438b9c
+Subproject commit 67d9eaa215e8727d86dc7b1f7a10be8699848f1f