refactor: fix modernize-return-braced-init-list warnings (#44857)

* refactor: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]

NB: using the braced-initializer list uncovered an error here:
the float returned by std::floor() can't be implicitly cast to
an int. This is solved by using base::ClampFloor<int>() instead.
std::floor()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-11-26 22:18:00 -06:00 committed by GitHub
parent 7152209fb5
commit cd6e3d720f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 79 additions and 81 deletions

View file

@ -775,7 +775,7 @@ base::OnceClosure App::SelectClientCertificate(
std::move((*shared_identities)[0]),
base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert)));
}
return base::OnceClosure();
return {};
}
void App::OnGpuInfoUpdate() {
@ -943,7 +943,7 @@ std::string App::GetSystemLocale(gin_helper::ErrorThrower thrower) const {
thrower.ThrowError(
"app.getSystemLocale() can only be called "
"after app is ready");
return std::string();
return {};
}
return static_cast<BrowserProcessImpl*>(g_browser_process)->GetSystemLocale();
}

View file

@ -168,7 +168,7 @@ void FilterCookieWithStatuses(
// Parse dictionary property to CanonicalCookie time correctly.
base::Time ParseTimeProperty(const std::optional<double>& value) {
if (!value) // empty time means ignoring the parameter
return base::Time();
return {};
if (*value == 0) // FromSecondsSinceUnixEpoch would convert 0 to empty Time
return base::Time::UnixEpoch();
return base::Time::FromSecondsSinceUnixEpoch(*value);

View file

@ -99,7 +99,7 @@ std::string ReadClientId() {
if (GetClientIdPath(&client_id_path) &&
(!base::ReadFileToStringWithMaxSize(client_id_path, &client_id, 36) ||
client_id.size() != 36))
return std::string();
return {};
return client_id;
}

View file

@ -63,8 +63,7 @@ scoped_refptr<base::SequencedTaskRunner> CreateFileTaskRunner() {
}
base::File OpenFileForWriting(base::FilePath path) {
return base::File(path,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
return {path, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE};
}
void ResolvePromiseWithNetError(gin_helper::Promise<void> promise,
@ -93,7 +92,7 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
gin::Arguments* args) {
if (log_path.empty()) {
args->ThrowTypeError("The first parameter must be a valid string");
return v8::Local<v8::Promise>();
return {};
}
net::NetLogCaptureMode capture_mode = net::NetLogCaptureMode::kDefault;
@ -106,7 +105,7 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
if (!gin::ConvertFromV8(args->isolate(), capture_mode_v8,
&capture_mode)) {
args->ThrowTypeError("Invalid value for captureMode");
return v8::Local<v8::Promise>();
return {};
}
}
v8::Local<v8::Value> max_file_size_v8;
@ -114,14 +113,14 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
if (!gin::ConvertFromV8(args->isolate(), max_file_size_v8,
&max_file_size)) {
args->ThrowTypeError("Invalid value for maxFileSize");
return v8::Local<v8::Promise>();
return {};
}
}
}
if (net_log_exporter_) {
args->ThrowTypeError("There is already a net log running");
return v8::Local<v8::Promise>();
return {};
}
pending_start_promise_ =

View file

@ -53,13 +53,13 @@ v8::Local<v8::Value> EncryptString(v8::Isolate* isolate,
if (!electron::Browser::Get()->is_ready()) {
gin_helper::ErrorThrower(isolate).ThrowError(
"safeStorage cannot be used before app is ready");
return v8::Local<v8::Value>();
return {};
}
gin_helper::ErrorThrower(isolate).ThrowError(
"Error while encrypting the text provided to "
"safeStorage.encryptString. "
"Encryption is not available.");
return v8::Local<v8::Value>();
return {};
}
std::string ciphertext;
@ -69,7 +69,7 @@ v8::Local<v8::Value> EncryptString(v8::Isolate* isolate,
gin_helper::ErrorThrower(isolate).ThrowError(
"Error while encrypting the text provided to "
"safeStorage.encryptString.");
return v8::Local<v8::Value>();
return {};
}
return node::Buffer::Copy(isolate, ciphertext.c_str(), ciphertext.size())

View file

@ -82,7 +82,7 @@ gfx::Point Screen::GetCursorScreenPoint(v8::Isolate* isolate) {
thrower.ThrowError(
"screen.getCursorScreenPoint() cannot be called before a window has "
"been created.");
return gfx::Point();
return {};
}
#endif
return screen_->GetCursorScreenPoint();

View file

@ -67,13 +67,13 @@ gin::Handle<Tray> Tray::New(gin_helper::ErrorThrower thrower,
gin::Arguments* args) {
if (!Browser::Get()->is_ready()) {
thrower.ThrowError("Cannot create Tray before app is ready");
return gin::Handle<Tray>();
return {};
}
#if BUILDFLAG(IS_WIN)
if (!guid.has_value() && args->Length() > 1) {
thrower.ThrowError("Invalid GUID format");
return gin::Handle<Tray>();
return {};
}
#endif
@ -85,7 +85,7 @@ gin::Handle<Tray> Tray::New(gin_helper::ErrorThrower thrower,
if (try_catch.HasCaught()) {
delete tray;
try_catch.ReThrow();
return gin::Handle<Tray>();
return {};
}
auto handle = gin::CreateHandle(args->isolate(), tray);
@ -264,7 +264,7 @@ void Tray::SetTitle(const std::string& title,
std::string Tray::GetTitle() {
if (!CheckAlive())
return std::string();
return {};
#if BUILDFLAG(IS_MAC)
return tray_icon_->GetTitle();
#else
@ -388,7 +388,7 @@ void Tray::SetContextMenu(gin_helper::ErrorThrower thrower,
gfx::Rect Tray::GetBounds() {
if (!CheckAlive())
return gfx::Rect();
return {};
return tray_icon_->GetBounds();
}

View file

@ -282,7 +282,7 @@ void View::SetBounds(const gfx::Rect& bounds) {
gfx::Rect View::GetBounds() {
if (!view_)
return gfx::Rect();
return {};
return view_->bounds();
}

View file

@ -2628,7 +2628,7 @@ std::string WebContents::GetMediaSourceID(
content::WebContents* request_web_contents) {
auto* frame_host = web_contents()->GetPrimaryMainFrame();
if (!frame_host)
return std::string();
return {};
content::DesktopMediaID media_id(
content::DesktopMediaID::TYPE_WEB_CONTENTS,
@ -2638,7 +2638,7 @@ std::string WebContents::GetMediaSourceID(
auto* request_frame_host = request_web_contents->GetPrimaryMainFrame();
if (!request_frame_host)
return std::string();
return {};
std::string id =
content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
@ -2760,7 +2760,7 @@ bool WebContents::IsDevToolsOpened() {
std::u16string WebContents::GetDevToolsTitle() {
if (type_ == Type::kRemote)
return std::u16string();
return {};
DCHECK(inspectable_web_contents_);
return inspectable_web_contents_->GetDevToolsTitle();
@ -3640,7 +3640,7 @@ gfx::Size WebContents::GetSizeForNewRenderView(content::WebContents* wc) {
}
}
return gfx::Size();
return {};
}
void WebContents::SetZoomLevel(double level) {

View file

@ -344,7 +344,7 @@ content::FrameTreeNodeId WebFrameMain::FrameTreeNodeID() const {
std::string WebFrameMain::Name() const {
if (!CheckRenderFrame())
return std::string();
return {};
return render_frame_->GetFrameName();
}
@ -376,7 +376,7 @@ GURL WebFrameMain::URL() const {
std::string WebFrameMain::Origin() const {
if (!CheckRenderFrame())
return std::string();
return {};
return render_frame_->GetLastCommittedOrigin().Serialize();
}