Skip to content

Commit

Permalink
chore: stop using v8::Locker everywhere (#34078)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed May 5, 2022
1 parent a2a8e49 commit d8a7219
Show file tree
Hide file tree
Showing 23 changed files with 0 additions and 43 deletions.
4 changes: 0 additions & 4 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -802,7 +802,6 @@ bool App::CanCreateWindow(
bool opener_suppressed,
bool* no_javascript_access) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(opener);
Expand All @@ -828,7 +827,6 @@ void App::AllowCertificateError(
base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
auto adapted_callback = base::AdaptCallbackForRepeating(std::move(callback));
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
bool prevent_default = Emit(
"certificate-error", WebContents::FromOrCreate(isolate, web_contents),
Expand Down Expand Up @@ -1086,7 +1084,6 @@ std::string App::GetLocaleCountryCode() {
void App::OnFirstInstanceAck(
const base::span<const uint8_t>* first_instance_data) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
base::Value data_to_send;
if (first_instance_data) {
Expand Down Expand Up @@ -1120,7 +1117,6 @@ void App::OnSecondInstance(
const std::vector<uint8_t> additional_data,
const ProcessSingleton::NotificationAckCallback& ack_callback) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Value> data_value =
DeserializeV8Value(isolate, std::move(additional_data));
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_auto_updater.cc
Expand Up @@ -32,7 +32,6 @@ AutoUpdater::~AutoUpdater() {

void AutoUpdater::OnError(const std::string& message) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> wrapper;
if (GetWrapper(isolate).ToLocal(&wrapper)) {
Expand All @@ -49,7 +48,6 @@ void AutoUpdater::OnError(const std::string& message,
const int code,
const std::string& domain) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> wrapper;
if (GetWrapper(isolate).ToLocal(&wrapper)) {
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_base_window.cc
Expand Up @@ -209,7 +209,6 @@ void BaseWindow::OnWindowWillResize(const gfx::Rect& new_bounds,
const gfx::ResizeEdge& edge,
bool* prevent_default) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary info = gin::Dictionary::CreateEmpty(isolate);
info.Set("edge", edge);
Expand Down Expand Up @@ -309,7 +308,6 @@ void BaseWindow::OnSystemContextMenu(int x, int y, bool* prevent_default) {
void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
if (IsWindowMessageHooked(message)) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
messages_callback_map_[message].Run(
ToBuffer(isolate, static_cast<void*>(&w_param), sizeof(WPARAM)),
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_browser_window.cc
Expand Up @@ -349,7 +349,6 @@ void BrowserWindow::UpdateWindowControlsOverlay(

void BrowserWindow::CloseImmediately() {
// Close all child windows before closing current window.
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
gin::Handle<BrowserWindow> child;
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_data_pipe_holder.cc
Expand Up @@ -107,7 +107,6 @@ class DataPipeReader {
//
// Note that the lifetime of the native buffer belongs to us, and we will
// free memory when JS buffer gets garbage collected.
v8::Locker locker(promise_.isolate());
v8::HandleScope handle_scope(promise_.isolate());
v8::Local<v8::Value> buffer =
node::Buffer::New(promise_.isolate(), &buffer_.front(), buffer_.size(),
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_debugger.cc
Expand Up @@ -43,8 +43,6 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
DCHECK(agent_host == agent_host_);

v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();

v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);

base::StringPiece message_str(reinterpret_cast<const char*>(message.data()),
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/electron_api_desktop_capturer.cc
Expand Up @@ -155,7 +155,6 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
if (!webrtc::DxgiDuplicatorController::Instance()->GetDeviceNames(
&device_names)) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
gin_helper::CallMethod(this, "_onerror", "Failed to get sources.");

Expand Down Expand Up @@ -191,7 +190,6 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {

if (!capture_window_ && !capture_screen_) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
gin_helper::CallMethod(this, "_onfinished", captured_sources_);

Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_menu.cc
Expand Up @@ -146,7 +146,6 @@ void Menu::OnMenuWillShow(ui::SimpleMenuModel* source) {
base::OnceClosure Menu::BindSelfToClosure(base::OnceClosure callback) {
// return ((callback, ref) => { callback() }).bind(null, callback, this)
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Object> self;
if (GetWrapper(isolate).ToLocal(&self)) {
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_session.cc
Expand Up @@ -372,7 +372,6 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
if (item->IsSavePackageDownload())
return;

v8::Locker locker(isolate_);
v8::HandleScope handle_scope(isolate_);
auto handle = DownloadItem::FromOrCreate(isolate_, item);
if (item->GetState() == download::DownloadItem::INTERRUPTED)
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_tray.cc
Expand Up @@ -389,7 +389,6 @@ gfx::Rect Tray::GetBounds() {
bool Tray::CheckAlive() {
if (!tray_icon_) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
gin_helper::ErrorThrower(isolate).ThrowError("Tray is destroyed");
return false;
Expand Down
6 changes: 0 additions & 6 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1041,7 +1041,6 @@ void WebContents::WebContentsCreatedWithFullParams(
tracker->body = params.body;

v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);

gin_helper::Dictionary dict;
Expand Down Expand Up @@ -1073,7 +1072,6 @@ bool WebContents::IsWebContentsCreationOverridden(
void WebContents::SetNextChildWebPreferences(
const gin_helper::Dictionary preferences) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
// Store these prefs for when Chrome calls WebContentsCreatedWithFullParams
// with the new child contents.
Expand Down Expand Up @@ -1105,7 +1103,6 @@ void WebContents::AddNewContents(

v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();

v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
auto api_web_contents =
CreateAndTake(isolate, std::move(new_contents), Type::kBrowserWindow);
Expand Down Expand Up @@ -1392,7 +1389,6 @@ void WebContents::FindReply(content::WebContents* web_contents,
return;

v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary result = gin::Dictionary::CreateEmpty(isolate);
result.Set("requestId", request_id);
Expand Down Expand Up @@ -1991,7 +1987,6 @@ void WebContents::DevToolsFocused() {

void WebContents::DevToolsOpened() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
DCHECK(inspectable_web_contents_);
DCHECK(inspectable_web_contents_->GetDevToolsWebContents());
Expand All @@ -2015,7 +2010,6 @@ void WebContents::DevToolsOpened() {

void WebContents::DevToolsClosed() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
devtools_web_contents_.Reset();

Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_web_frame_main.cc
Expand Up @@ -108,7 +108,6 @@ void WebFrameMain::UpdateRenderFrameHost(content::RenderFrameHost* rfh) {
bool WebFrameMain::CheckRenderFrame() const {
if (render_frame_disposed_) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
gin_helper::ErrorThrower(isolate).ThrowError(
"Render frame was disposed before WebFrameMain could be accessed");
Expand Down
1 change: 0 additions & 1 deletion shell/browser/event_emitter_mixin.h
Expand Up @@ -29,7 +29,6 @@ class EventEmitterMixin {
template <typename... Args>
bool Emit(base::StringPiece name, Args&&... args) {
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> wrapper;
if (!static_cast<T*>(this)->GetWrapper(isolate).ToLocal(&wrapper))
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/javascript_environment.cc
Expand Up @@ -171,7 +171,6 @@ JavascriptEnvironment::~JavascriptEnvironment() {
platform_->DrainTasks(isolate_);

{
v8::Locker locker(isolate_);
v8::HandleScope scope(isolate_);
context_.Get(isolate_)->Exit();
}
Expand Down Expand Up @@ -370,7 +369,6 @@ void JavascriptEnvironment::OnMessageLoopCreated() {
void JavascriptEnvironment::OnMessageLoopDestroying() {
DCHECK(microtasks_runner_);
{
v8::Locker locker(isolate_);
v8::HandleScope scope(isolate_);
gin_helper::CleanedUpAtExit::DoCleanup();
}
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/net/node_stream_loader.cc
Expand Up @@ -30,7 +30,6 @@ NodeStreamLoader::NodeStreamLoader(
}

NodeStreamLoader::~NodeStreamLoader() {
v8::Locker locker(isolate_);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);

Expand Down Expand Up @@ -154,7 +153,6 @@ void NodeStreamLoader::DidWrite(MojoResult result) {
}

void NodeStreamLoader::On(const char* event, EventCallback callback) {
v8::Locker locker(isolate_);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);

Expand Down
2 changes: 0 additions & 2 deletions shell/browser/printing/print_preview_message_handler.cc
Expand Up @@ -24,7 +24,6 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "shell/common/gin_helper/locker.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"

#include "shell/common/node_includes.h"
Expand Down Expand Up @@ -250,7 +249,6 @@ void PrintPreviewMessageHandler::ResolvePromise(
gin_helper::Promise<v8::Local<v8::Value>> promise = GetPromise(request_id);

v8::Isolate* isolate = promise.isolate();
gin_helper::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(
v8::Local<v8::Context>::New(isolate, promise.GetContext()));
Expand Down
1 change: 0 additions & 1 deletion shell/browser/ui/file_dialog_mac.mm
Expand Up @@ -307,7 +307,6 @@ void ResolvePromiseInNextTick(gin_helper::Promise<v8::Local<v8::Value>> promise,
[](gin_helper::Promise<v8::Local<v8::Value>> promise,
v8::Global<v8::Value> global) {
v8::Isolate* isolate = promise.isolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Value> value = global.Get(isolate);
promise.Resolve(value);
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/ui/file_dialog_win.cc
Expand Up @@ -221,7 +221,6 @@ void ShowOpenDialog(const DialogSettings& settings,
gin_helper::Promise<gin_helper::Dictionary> promise) {
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
bool success, std::vector<base::FilePath> result) {
v8::Locker locker(promise.isolate());
v8::HandleScope handle_scope(promise.isolate());
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
dict.Set("canceled", !success);
Expand Down Expand Up @@ -271,7 +270,6 @@ void ShowSaveDialog(const DialogSettings& settings,
gin_helper::Promise<gin_helper::Dictionary> promise) {
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
bool success, base::FilePath result) {
v8::Locker locker(promise.isolate());
v8::HandleScope handle_scope(promise.isolate());
gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate());
dict.Set("canceled", !success);
Expand Down
1 change: 0 additions & 1 deletion shell/common/api/electron_bindings.cc
Expand Up @@ -250,7 +250,6 @@ void ElectronBindings::DidReceiveMemoryDump(
bool success,
std::unique_ptr<memory_instrumentation::GlobalMemoryDump> global_dump) {
v8::Isolate* isolate = promise.isolate();
gin_helper::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
gin_helper::MicrotasksScope microtasks_scope(isolate, true);
v8::Context::Scope context_scope(
Expand Down
1 change: 0 additions & 1 deletion shell/common/gin_helper/event_emitter.h
Expand Up @@ -61,7 +61,6 @@ class EventEmitter : public gin_helper::Wrappable<T> {
// this.emit(name, new Event(), args...);
template <typename... Args>
bool Emit(base::StringPiece name, Args&&... args) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Object> wrapper = GetWrapper();
if (wrapper.IsEmpty())
Expand Down
1 change: 0 additions & 1 deletion shell/common/gin_helper/pinnable.h
Expand Up @@ -14,7 +14,6 @@ class Pinnable {
protected:
// Prevent the object from being garbage collected until Unpin() is called.
void Pin(v8::Isolate* isolate) {
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Value> wrapper;
if (static_cast<T*>(this)->GetWrapper(isolate).ToLocal(&wrapper)) {
Expand Down
4 changes: 0 additions & 4 deletions shell/common/gin_helper/promise.cc
Expand Up @@ -24,7 +24,6 @@ PromiseBase::~PromiseBase() = default;
PromiseBase& PromiseBase::operator=(PromiseBase&&) = default;

v8::Maybe<bool> PromiseBase::Reject() {
gin_helper::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
gin_helper::MicrotasksScope microtasks_scope(isolate());
v8::Context::Scope context_scope(GetContext());
Expand All @@ -33,7 +32,6 @@ v8::Maybe<bool> PromiseBase::Reject() {
}

v8::Maybe<bool> PromiseBase::Reject(v8::Local<v8::Value> except) {
gin_helper::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
gin_helper::MicrotasksScope microtasks_scope(isolate());
v8::Context::Scope context_scope(GetContext());
Expand All @@ -42,7 +40,6 @@ v8::Maybe<bool> PromiseBase::Reject(v8::Local<v8::Value> except) {
}

v8::Maybe<bool> PromiseBase::RejectWithErrorMessage(base::StringPiece message) {
gin_helper::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
gin_helper::MicrotasksScope microtasks_scope(isolate());
v8::Context::Scope context_scope(GetContext());
Expand Down Expand Up @@ -85,7 +82,6 @@ v8::Local<v8::Promise> Promise<void>::ResolvedPromise(v8::Isolate* isolate) {
}

v8::Maybe<bool> Promise<void>::Resolve() {
gin_helper::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
gin_helper::MicrotasksScope microtasks_scope(isolate());
v8::Context::Scope context_scope(GetContext());
Expand Down
2 changes: 0 additions & 2 deletions shell/common/node_bindings.cc
Expand Up @@ -628,8 +628,6 @@ void NodeBindings::UvRunOnce() {
if (!env)
return;

// Use Locker in browser process.
gin_helper::Locker locker(env->isolate());
v8::HandleScope handle_scope(env->isolate());

// Enter node context while dealing with uv events.
Expand Down

0 comments on commit d8a7219

Please sign in to comment.