]> khamidou — GitHub mirrors - electron.git/commitdiff
Remove calls to v8::Isolate::GetCurrent
authorCheng Zhao <zcbenz@gmail.com>
Tue, 23 Jun 2015 09:22:14 +0000 (17:22 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 23 Jun 2015 09:22:14 +0000 (17:22 +0800)
It is generally a bad thing to do since we might have multiple Isolates.

atom/browser/api/atom_api_cookies.cc
atom/browser/api/atom_api_menu.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_window.cc
atom/browser/api/event_emitter.h
vendor/native_mate

index 27abfcc65f58dce8919cfedc919ca7d12041d5d6..0363032df878ee42b6131026c1c59d27d3250daa 100644 (file)
@@ -46,18 +46,17 @@ bool GetCookieListFromStore(
   return true;
 }
 
-void RunGetCookiesCallbackOnUIThread(const std::string& error_message,
+void RunGetCookiesCallbackOnUIThread(v8::Isolate* isolate,
+                                     const std::string& error_message,
                                      const net::CookieList& cookie_list,
                                      const Cookies::CookiesCallback& callback) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
 
   if (!error_message.empty()) {
-    v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
-        error_message.c_str());
+    v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
     callback.Run(error, v8::Null(isolate));
     return;
   }
@@ -65,17 +64,16 @@ void RunGetCookiesCallbackOnUIThread(const std::string& error_message,
 }
 
 void RunRemoveCookiesCallbackOnUIThread(
+    v8::Isolate* isolate,
     const std::string& error_message,
     const Cookies::CookiesCallback& callback) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
 
   if (!error_message.empty()) {
-    v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
-        error_message.c_str());
+    v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
     callback.Run(error, v8::Null(isolate));
     return;
   }
@@ -83,24 +81,23 @@ void RunRemoveCookiesCallbackOnUIThread(
   callback.Run(v8::Null(isolate), v8::Null(isolate));
 }
 
-void RunSetCookiesCallbackOnUIThread(const std::string& error_message,
+void RunSetCookiesCallbackOnUIThread(v8::Isolate* isolate,
+                                     const std::string& error_message,
                                      bool set_success,
                                      const Cookies::CookiesCallback& callback) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::Locker locker(isolate);
   v8::HandleScope handle_scope(isolate);
 
   if (!error_message.empty()) {
-    v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
-        error_message.c_str());
+    v8::Local<v8::Value> error = mate::ConvertToV8(isolate, error_message);
     callback.Run(error, v8::Null(isolate));
     return;
   }
   if (!set_success) {
-    v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,
-        "Failed to set cookies");
+    v8::Local<v8::Value> error = mate::ConvertToV8(
+        isolate, "Failed to set cookies");
     callback.Run(error, v8::Null(isolate));
   }
 
@@ -209,8 +206,8 @@ void Cookies::GetCookiesOnIOThread(scoped_ptr<base::DictionaryValue> filter,
           base::Bind(&Cookies::OnGetCookies, base::Unretained(this),
               Passed(&filter), callback))) {
     BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
-        base::Bind(&RunGetCookiesCallbackOnUIThread, "Url is not valid",
-            net::CookieList(), callback));
+        base::Bind(&RunGetCookiesCallbackOnUIThread, isolate(),
+                   "Url is not valid", net::CookieList(), callback));
   }
 }
 
@@ -223,7 +220,7 @@ void Cookies::OnGetCookies(scoped_ptr<base::DictionaryValue> filter,
       result.push_back(cookie);
   }
   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
-      &RunGetCookiesCallbackOnUIThread, "", result, callback));
+      &RunGetCookiesCallbackOnUIThread, isolate(), "", result, callback));
 }
 
 void Cookies::Remove(const mate::Dictionary& details,
@@ -238,7 +235,7 @@ void Cookies::Remove(const mate::Dictionary& details,
     error_message = "Url is not valid.";
   }
   if (!error_message.empty()) {
-     RunRemoveCookiesCallbackOnUIThread(error_message, callback);
+     RunRemoveCookiesCallbackOnUIThread(isolate(), error_message, callback);
      return;
   }
   content::BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
@@ -256,7 +253,7 @@ void Cookies::RemoveCookiesOnIOThread(const GURL& url, const std::string& name,
 
 void Cookies::OnRemoveCookies(const CookiesCallback& callback) {
   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
-      base::Bind(&RunRemoveCookiesCallbackOnUIThread, "", callback));
+      base::Bind(&RunRemoveCookiesCallbackOnUIThread, isolate(), "", callback));
 }
 
 void Cookies::Set(const base::DictionaryValue& options,
@@ -273,7 +270,7 @@ void Cookies::Set(const base::DictionaryValue& options,
   }
 
   if (!error_message.empty()) {
-    RunSetCookiesCallbackOnUIThread(error_message, false, callback);
+    RunSetCookiesCallbackOnUIThread(isolate(), error_message, false, callback);
     return;
   }
 
@@ -328,7 +325,8 @@ void Cookies::SetCookiesOnIOThread(scoped_ptr<base::DictionaryValue> details,
 void Cookies::OnSetCookies(const CookiesCallback& callback,
                            bool set_success) {
   BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
-      base::Bind(&RunSetCookiesCallbackOnUIThread, "", set_success, callback));
+      base::Bind(&RunSetCookiesCallbackOnUIThread, isolate(), "", set_success,
+                 callback));
 }
 
 mate::ObjectTemplateBuilder Cookies::GetObjectTemplateBuilder(
index c0704a22d052129539e25e0840c6bdd731f12f18..1eb5cb31d1182018135efab135d1bab2ca25bad4 100644 (file)
@@ -55,11 +55,10 @@ bool Menu::IsCommandIdVisible(int command_id) const {
 
 bool Menu::GetAcceleratorForCommandId(int command_id,
                                       ui::Accelerator* accelerator) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
-  v8::HandleScope handle_scope(isolate);
+  v8::Locker locker(isolate());
+  v8::HandleScope handle_scope(isolate());
   v8::Local<v8::Value> val = get_accelerator_.Run(command_id);
-  return mate::ConvertFromV8(isolate, val, accelerator);
+  return mate::ConvertFromV8(isolate(), val, accelerator);
 }
 
 void Menu::ExecuteCommand(int command_id, int event_flags) {
index 0b7a5cfa7c340f8ff84b9b75bd5cf6211add2f03..e298ec790940277905ff74835e86c8b5bda90cfb 100644 (file)
@@ -67,9 +67,8 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
   void GetJobTypeInUI() override {
     DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
+    v8::Locker locker(registry_->isolate());
+    v8::HandleScope handle_scope(registry_->isolate());
 
     // Call the JS handler.
     Protocol::JsProtocolHandler callback =
@@ -85,7 +84,7 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
       return;
     } else if (result->IsObject()) {
       v8::Local<v8::Object> obj = result->ToObject();
-      mate::Dictionary dict(isolate, obj);
+      mate::Dictionary dict(registry_->isolate(), obj);
       std::string name = mate::V8ToString(obj->GetConstructorName());
       if (name == "RequestStringJob") {
         std::string mime_type, charset, data;
index 85b0e3d8a85c6bb5827aed6465b10c16452be699..420878664d22d6dfb5a439ee1c2470ed118643af 100644 (file)
@@ -310,9 +310,8 @@ void WebContents::DidStopLoading() {
 
 void WebContents::DidGetResourceResponseStart(
     const content::ResourceRequestDetails& details) {
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
-  v8::HandleScope handle_scope(isolate);
+  v8::Locker locker(isolate());
+  v8::HandleScope handle_scope(isolate());
   base::DictionaryValue response_headers;
 
   net::HttpResponseHeaders* headers = details.headers.get();
index f19a353afa8c81e19bfa1100f234336220592624..21c6b327e8db60605a1f42829b5b0b28233881fc 100644 (file)
@@ -142,20 +142,18 @@ void Window::OnDevToolsFocus() {
 void Window::OnDevToolsOpened() {
   Emit("devtools-opened");
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
-  v8::HandleScope handle_scope(isolate);
-  auto handle =
-      WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
-  devtools_web_contents_.Reset(isolate, handle.ToV8());
+  v8::Locker locker(isolate());
+  v8::HandleScope handle_scope(isolate());
+  auto handle = WebContents::CreateFrom(isolate(),
+                                        window_->GetDevToolsWebContents());
+  devtools_web_contents_.Reset(isolate(), handle.ToV8());
 }
 
 void Window::OnDevToolsClosed() {
   Emit("devtools-closed");
 
-  v8::Isolate* isolate = v8::Isolate::GetCurrent();
-  v8::Locker locker(isolate);
-  v8::HandleScope handle_scope(isolate);
+  v8::Locker locker(isolate());
+  v8::HandleScope handle_scope(isolate());
   devtools_web_contents_.Reset();
 }
 
index 3809407138a123a86e0a4fad06f050dde000193f..776fd5e2dd52645125814ab8f7f8931a194a74dc 100644 (file)
@@ -39,12 +39,11 @@ class EventEmitter : public Wrappable {
                       content::WebContents* sender,
                       IPC::Message* message,
                       const Args&... args) {
-    v8::Isolate* isolate = v8::Isolate::GetCurrent();
-    v8::Locker locker(isolate);
-    v8::HandleScope handle_scope(isolate);
+    v8::Locker locker(isolate());
+    v8::HandleScope handle_scope(isolate());
 
-    ValueArray converted = { ConvertToV8(isolate, args)... };
-    return CallEmit(isolate, name, sender, message, converted);
+    ValueArray converted = { ConvertToV8(isolate(), args)... };
+    return CallEmit(isolate(), name, sender, message, converted);
   }
 
  private:
index ad207eeabb0185f74c017e70ca3411d522627ff0..cad1fa50a95ca4185c435846e4868d5bd6cc94df 160000 (submodule)
@@ -1 +1 @@
-Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0
+Subproject commit cad1fa50a95ca4185c435846e4868d5bd6cc94df