fix: remove catch-all HandleScope (#22531)
This commit is contained in:
parent
4bca5205bb
commit
19314d3caf
21 changed files with 131 additions and 75 deletions
|
@ -788,8 +788,11 @@ void App::RenderProcessReady(content::RenderProcessHost* host) {
|
|||
// `RenderProcessPreferences`, so this is at least more explicit...
|
||||
content::WebContents* web_contents =
|
||||
ElectronBrowserClient::Get()->GetWebContentsFromProcessID(host->GetID());
|
||||
if (web_contents)
|
||||
WebContents::FromOrCreate(v8::Isolate::GetCurrent(), web_contents);
|
||||
if (web_contents) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
WebContents::FromOrCreate(isolate, web_contents);
|
||||
}
|
||||
}
|
||||
|
||||
void App::RenderProcessDisconnected(base::ProcessId host_pid) {
|
||||
|
|
|
@ -314,6 +314,7 @@ v8::Local<v8::Promise> Cookies::FlushStore() {
|
|||
}
|
||||
|
||||
void Cookies::OnCookieChanged(const net::CookieChangeInfo& change) {
|
||||
v8::HandleScope scope(isolate());
|
||||
Emit("changed", gin::ConvertToV8(isolate(), change.cookie),
|
||||
gin::ConvertToV8(isolate(), change.cause),
|
||||
gin::ConvertToV8(isolate(),
|
||||
|
|
|
@ -214,6 +214,7 @@ void Menu::OnMenuWillClose() {
|
|||
}
|
||||
|
||||
void Menu::OnMenuWillShow() {
|
||||
v8::HandleScope scope(isolate());
|
||||
g_menus[weak_map_id()] = v8::Global<v8::Object>(isolate(), GetWrapper());
|
||||
Emit("menu-will-show");
|
||||
}
|
||||
|
|
|
@ -85,8 +85,10 @@ ServiceWorkerContext::~ServiceWorkerContext() {
|
|||
void ServiceWorkerContext::OnReportConsoleMessage(
|
||||
int64_t version_id,
|
||||
const content::ConsoleMessage& message) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
Emit("console-message",
|
||||
gin::DataObjectBuilder(v8::Isolate::GetCurrent())
|
||||
gin::DataObjectBuilder(isolate)
|
||||
.Set("versionId", version_id)
|
||||
.Set("source", MessageSourceToString(message.source))
|
||||
.Set("level", static_cast<int32_t>(message.message_level))
|
||||
|
|
|
@ -433,6 +433,7 @@ void SimpleURLLoaderWrapper::OnRetry(base::OnceClosure start_retry) {}
|
|||
void SimpleURLLoaderWrapper::OnResponseStarted(
|
||||
const GURL& final_url,
|
||||
const network::mojom::URLResponseHead& response_head) {
|
||||
v8::HandleScope scope(isolate());
|
||||
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate());
|
||||
dict.Set("statusCode", response_head.headers->response_code());
|
||||
dict.Set("statusMessage", response_head.headers->GetStatusText());
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include "gin/data_object_builder.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "shell/common/gin_converters/blink_converter.h"
|
||||
#include "shell/common/gin_converters/std_converter.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
|
@ -15,7 +17,16 @@ gin::WrapperInfo Event::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|||
|
||||
Event::Event() {}
|
||||
|
||||
Event::~Event() = default;
|
||||
Event::~Event() {
|
||||
if (callback_) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto message = gin::DataObjectBuilder(isolate)
|
||||
.Set("error", "reply was never sent")
|
||||
.Build();
|
||||
SendReply(isolate, message);
|
||||
}
|
||||
}
|
||||
|
||||
void Event::SetCallback(InvokeCallback callback) {
|
||||
DCHECK(!callback_);
|
||||
|
|
|
@ -28,10 +28,11 @@ void AutofillDriver::ShowAutofillPopup(
|
|||
const gfx::RectF& bounds,
|
||||
const std::vector<base::string16>& values,
|
||||
const std::vector<base::string16>& labels) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto* web_contents =
|
||||
api::WebContents::From(
|
||||
v8::Isolate::GetCurrent(),
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host_))
|
||||
api::WebContents::From(isolate, content::WebContents::FromRenderFrameHost(
|
||||
render_frame_host_))
|
||||
.get();
|
||||
if (!web_contents || !web_contents->owner_window())
|
||||
return;
|
||||
|
|
|
@ -1300,6 +1300,7 @@ bool ElectronBrowserClient::WillInterceptWebSocket(
|
|||
return false;
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto* browser_context = frame->GetProcess()->GetBrowserContext();
|
||||
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
|
||||
|
||||
|
@ -1320,6 +1321,7 @@ void ElectronBrowserClient::CreateWebSocket(
|
|||
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
|
||||
handshake_client) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto* browser_context = frame->GetProcess()->GetBrowserContext();
|
||||
auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
|
||||
DCHECK(web_request.get());
|
||||
|
@ -1345,6 +1347,7 @@ bool ElectronBrowserClient::WillCreateURLLoaderFactory(
|
|||
bool* disable_secure_dns,
|
||||
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
api::Protocol* protocol =
|
||||
api::Protocol::FromWrappedClass(isolate, browser_context);
|
||||
DCHECK(protocol);
|
||||
|
|
|
@ -293,6 +293,8 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
|
|||
// avoid conflicts we only initialize our V8 environment after that.
|
||||
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());
|
||||
|
||||
v8::HandleScope scope(js_env_->isolate());
|
||||
|
||||
node_bindings_->Initialize();
|
||||
// Create the global environment.
|
||||
node::Environment* env = node_bindings_->CreateEnvironment(
|
||||
|
|
|
@ -28,8 +28,9 @@ ElectronNavigationThrottle::WillRedirectRequest() {
|
|||
return PROCEED;
|
||||
}
|
||||
|
||||
auto api_contents =
|
||||
electron::api::WebContents::From(v8::Isolate::GetCurrent(), contents);
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
auto api_contents = electron::api::WebContents::From(isolate, contents);
|
||||
if (api_contents.IsEmpty()) {
|
||||
// No need to emit any event if the WebContents is not available in JS.
|
||||
return PROCEED;
|
||||
|
|
|
@ -29,13 +29,21 @@ JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop)
|
|||
gin::IsolateHolder::IsolateType::kUtility,
|
||||
gin::IsolateHolder::IsolateCreationMode::kNormal,
|
||||
isolate_),
|
||||
isolate_scope_(isolate_),
|
||||
locker_(isolate_),
|
||||
handle_scope_(isolate_),
|
||||
context_(isolate_, node::NewContext(isolate_)),
|
||||
context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {}
|
||||
locker_(isolate_) {
|
||||
isolate_->Enter();
|
||||
v8::HandleScope scope(isolate_);
|
||||
auto context = node::NewContext(isolate_);
|
||||
context_ = v8::Global<v8::Context>(isolate_, context);
|
||||
context->Enter();
|
||||
}
|
||||
|
||||
JavascriptEnvironment::~JavascriptEnvironment() = default;
|
||||
JavascriptEnvironment::~JavascriptEnvironment() {
|
||||
{
|
||||
v8::HandleScope scope(isolate_);
|
||||
context_.Get(isolate_)->Exit();
|
||||
}
|
||||
isolate_->Exit();
|
||||
}
|
||||
|
||||
v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
|
||||
auto* cmd = base::CommandLine::ForCurrentProcess();
|
||||
|
|
|
@ -41,11 +41,8 @@ class JavascriptEnvironment {
|
|||
|
||||
v8::Isolate* isolate_;
|
||||
gin::IsolateHolder isolate_holder_;
|
||||
v8::Isolate::Scope isolate_scope_;
|
||||
v8::Locker locker_;
|
||||
v8::HandleScope handle_scope_;
|
||||
v8::Global<v8::Context> context_;
|
||||
v8::Context::Scope context_scope_;
|
||||
|
||||
std::unique_ptr<MicrotasksRunner> microtasks_runner_;
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ void LoginHandler::EmitEvent(
|
|||
scoped_refptr<net::HttpResponseHeaders> response_headers,
|
||||
bool first_auth_attempt) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
auto api_web_contents = api::WebContents::From(isolate, web_contents());
|
||||
if (api_web_contents.IsEmpty()) {
|
||||
|
@ -58,8 +59,6 @@ void LoginHandler::EmitEvent(
|
|||
return;
|
||||
}
|
||||
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
auto details = gin::Dictionary::CreateEmpty(isolate);
|
||||
details.Set("url", url);
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ void NodeStreamLoader::ReadMore() {
|
|||
}
|
||||
is_reading_ = true;
|
||||
auto weak = weak_factory_.GetWeakPtr();
|
||||
v8::HandleScope scope(isolate_);
|
||||
// buffer = emitter.read()
|
||||
v8::MaybeLocal<v8::Value> ret = node::MakeCallback(
|
||||
isolate_, emitter_.Get(isolate_), "read", 0, nullptr, {0, 0});
|
||||
|
|
|
@ -302,6 +302,7 @@ void OpenDialogCompletion(int chosen,
|
|||
NSOpenPanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
v8::HandleScope scope(promise.isolate());
|
||||
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||
dict.Set("canceled", true);
|
||||
|
@ -379,6 +380,7 @@ void SaveDialogCompletion(int chosen,
|
|||
NSSavePanel* dialog,
|
||||
bool security_scoped_bookmarks,
|
||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||
v8::HandleScope scope(promise.isolate());
|
||||
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
|
||||
if (chosen == NSFileHandlingPanelCancelButton) {
|
||||
dict.Set("canceled", true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue