refactor: remove more uses of v8::Isolate::GetCurrent() (#28369)

This commit is contained in:
Shelley Vohr 2021-03-29 10:45:08 +00:00 committed by GitHub
parent ff96fabe5e
commit ae2059eaa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 44 deletions

View file

@ -331,7 +331,8 @@ const void* kElectronApiSessionKey = &kElectronApiSessionKey;
gin::WrapperInfo Session::kWrapperInfo = {gin::kEmbedderNativeGin};
Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
: network_emulation_token_(base::UnguessableToken::Create()),
: isolate_(isolate),
network_emulation_token_(base::UnguessableToken::Create()),
browser_context_(browser_context) {
// Observe DownloadManager to get download notifications.
content::BrowserContext::GetDownloadManager(browser_context)
@ -379,10 +380,9 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
if (item->IsSavePackageDownload())
return;
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
auto handle = DownloadItem::FromOrCreate(isolate, item);
v8::Locker locker(isolate_);
v8::HandleScope handle_scope(isolate_);
auto handle = DownloadItem::FromOrCreate(isolate_, item);
if (item->GetState() == download::DownloadItem::INTERRUPTED)
handle->SetSavePath(item->GetTargetFilePath());
content::WebContents* web_contents =
@ -425,8 +425,7 @@ v8::Local<v8::Promise> Session::ResolveProxy(gin::Arguments* args) {
}
v8::Local<v8::Promise> Session::GetCacheSize() {
auto* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<int64_t> promise(isolate);
gin_helper::Promise<int64_t> promise(isolate_);
auto handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
@ -449,8 +448,7 @@ v8::Local<v8::Promise> Session::GetCacheSize() {
}
v8::Local<v8::Promise> Session::ClearCache() {
auto* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<void> promise(isolate);
gin_helper::Promise<void> promise(isolate_);
auto handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
@ -558,8 +556,7 @@ v8::Local<v8::Promise> Session::SetProxy(gin::Arguments* args) {
}
v8::Local<v8::Promise> Session::ForceReloadProxyConfig() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<void> promise(isolate);
gin_helper::Promise<void> promise(isolate_);
auto handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
@ -675,8 +672,7 @@ v8::Local<v8::Promise> Session::ClearHostResolverCache(gin::Arguments* args) {
}
v8::Local<v8::Promise> Session::ClearAuthCache() {
auto* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<void> promise(isolate);
gin_helper::Promise<void> promise(isolate_);
v8::Local<v8::Promise> handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
@ -763,15 +759,14 @@ void Session::CreateInterruptedDownload(const gin_helper::Dictionary& options) {
options.Get("lastModified", &last_modified);
options.Get("eTag", &etag);
options.Get("startTime", &start_time);
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
if (path.empty() || url_chain.empty() || length == 0) {
isolate->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate, "Must pass non-empty path, urlChain and length.")));
isolate_->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate_, "Must pass non-empty path, urlChain and length.")));
return;
}
if (offset >= length) {
isolate->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate, "Must pass an offset value less than length.")));
isolate_->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate_, "Must pass an offset value less than length.")));
return;
}
auto* download_manager =
@ -797,8 +792,7 @@ std::vector<base::FilePath> Session::GetPreloads() const {
v8::Local<v8::Promise> Session::LoadExtension(
const base::FilePath& extension_path,
gin::Arguments* args) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<const extensions::Extension*> promise(isolate);
gin_helper::Promise<const extensions::Extension*> promise(isolate_);
v8::Local<v8::Promise> handle = promise.GetHandle();
if (!extension_path.IsAbsolute()) {
@ -833,7 +827,7 @@ v8::Local<v8::Promise> Session::LoadExtension(
if (extension) {
if (!error_msg.empty()) {
node::Environment* env =
node::Environment::GetCurrent(v8::Isolate::GetCurrent());
node::Environment::GetCurrent(promise.isolate());
EmitWarning(env, error_msg, "ExtensionLoadWarning");
}
promise.Resolve(extension);
@ -856,11 +850,10 @@ v8::Local<v8::Value> Session::GetExtension(const std::string& extension_id) {
auto* registry = extensions::ExtensionRegistry::Get(browser_context());
const extensions::Extension* extension =
registry->GetInstalledExtension(extension_id);
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
if (extension) {
return gin::ConvertToV8(isolate, extension);
return gin::ConvertToV8(isolate_, extension);
} else {
return v8::Null(isolate);
return v8::Null(isolate_);
}
}
@ -872,7 +865,7 @@ v8::Local<v8::Value> Session::GetAllExtensions() {
if (extension->location() != extensions::Manifest::COMPONENT)
extensions_vector.emplace_back(extension.get());
}
return gin::ConvertToV8(v8::Isolate::GetCurrent(), extensions_vector);
return gin::ConvertToV8(isolate_, extensions_vector);
}
void Session::OnExtensionLoaded(content::BrowserContext* browser_context,
@ -967,8 +960,7 @@ void Session::Preconnect(const gin_helper::Dictionary& options,
}
v8::Local<v8::Promise> Session::CloseAllConnections() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<void> promise(isolate);
gin_helper::Promise<void> promise(isolate_);
auto handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
@ -1018,8 +1010,7 @@ void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,
}
v8::Local<v8::Promise> Session::ListWordsInSpellCheckerDictionary() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<std::set<std::string>> promise(isolate);
gin_helper::Promise<std::set<std::string>> promise(isolate_);
v8::Local<v8::Promise> handle = promise.GetHandle();
SpellcheckService* spellcheck =