diff --git a/atom/browser/api/atom_api_cookies.cc b/atom/browser/api/atom_api_cookies.cc index 27abfcc65f58..0363032df878 100644 --- a/atom/browser/api/atom_api_cookies.cc +++ b/atom/browser/api/atom_api_cookies.cc @@ -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 error = v8::String::NewFromUtf8(isolate, - error_message.c_str()); + v8::Local 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 error = v8::String::NewFromUtf8(isolate, - error_message.c_str()); + v8::Local 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 error = v8::String::NewFromUtf8(isolate, - error_message.c_str()); + v8::Local error = mate::ConvertToV8(isolate, error_message); callback.Run(error, v8::Null(isolate)); return; } if (!set_success) { - v8::Local error = v8::String::NewFromUtf8(isolate, - "Failed to set cookies"); + v8::Local error = mate::ConvertToV8( + isolate, "Failed to set cookies"); callback.Run(error, v8::Null(isolate)); } @@ -209,8 +206,8 @@ void Cookies::GetCookiesOnIOThread(scoped_ptr 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 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 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( diff --git a/atom/browser/api/atom_api_menu.cc b/atom/browser/api/atom_api_menu.cc index c0704a22d052..1eb5cb31d118 100644 --- a/atom/browser/api/atom_api_menu.cc +++ b/atom/browser/api/atom_api_menu.cc @@ -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 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) { diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 0b7a5cfa7c34..e298ec790940 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -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 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; diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 85b0e3d8a85c..420878664d22 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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(); diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index f19a353afa8c..21c6b327e8db 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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(); } diff --git a/atom/browser/api/event_emitter.h b/atom/browser/api/event_emitter.h index 3809407138a1..776fd5e2dd52 100644 --- a/atom/browser/api/event_emitter.h +++ b/atom/browser/api/event_emitter.h @@ -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: diff --git a/vendor/native_mate b/vendor/native_mate index ad207eeabb01..cad1fa50a95c 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0 +Subproject commit cad1fa50a95ca4185c435846e4868d5bd6cc94df