refactor: fix modernize-return-braced-init-list warnings (32-x-y) (#45608)

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

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

* 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()
This commit is contained in:
Charles Kerr 2025-02-13 16:26:37 -06:00 committed by GitHub
parent 8c454d7736
commit 72ee2622eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 78 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

@ -165,7 +165,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

@ -100,7 +100,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

@ -54,13 +54,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;
@ -70,7 +70,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

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

View file

@ -2573,7 +2573,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,
@ -2583,7 +2583,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(
@ -2705,7 +2705,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();
@ -3570,7 +3570,7 @@ gfx::Size WebContents::GetSizeForNewRenderView(content::WebContents* wc) {
}
}
return gfx::Size();
return {};
}
void WebContents::SetZoomLevel(double level) {

View file

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

View file

@ -63,9 +63,9 @@ std::optional<std::string> GetXdgAppOutput(
&success_code);
if (!ran_ok || success_code != EXIT_SUCCESS)
return std::optional<std::string>();
return {};
return std::make_optional(reply);
return reply;
}
bool SetDefaultWebClient(const std::string& protocol) {

View file

@ -594,7 +594,7 @@ ElectronBrowserClient::GetGeneratedCodeCacheSettings(
// If we pass 0 for size, disk_cache will pick a default size using the
// heuristics based on available disk size. These are implemented in
// disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc.
return content::GeneratedCodeCacheSettings(true, 0, cache_path);
return {true, 0, cache_path};
}
void ElectronBrowserClient::AllowCertificateError(
@ -627,7 +627,7 @@ base::OnceClosure ElectronBrowserClient::SelectClientCertificate(
std::move(client_certs), std::move(delegate));
}
return base::OnceClosure();
return {};
}
bool ElectronBrowserClient::CanCreateWindow(
@ -975,7 +975,7 @@ base::FilePath ElectronBrowserClient::GetDefaultDownloadDirectory() {
base::FilePath download_path;
if (base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_path))
return download_path;
return base::FilePath();
return {};
}
scoped_refptr<network::SharedURLLoaderFactory>

View file

@ -163,7 +163,7 @@ std::u16string MediaStringProvider(media::MessageId id) {
return u"Communications";
#endif
default:
return std::u16string();
return {};
}
}

View file

@ -277,8 +277,7 @@ ElectronPermissionManager::GetPermissionResultForOriginWithoutContext(
const url::Origin& embedding_origin) {
blink::mojom::PermissionStatus status = GetPermissionStatus(
permission, requesting_origin.GetURL(), embedding_origin.GetURL());
return content::PermissionResult(
status, content::PermissionStatusSource::UNSPECIFIED);
return {status, content::PermissionStatusSource::UNSPECIFIED};
}
void ElectronPermissionManager::CheckBluetoothDevicePair(

View file

@ -169,14 +169,14 @@ base::FilePath ElectronExtensionsBrowserClient::GetBundleResourcePath(
*resource_id = 0;
base::FilePath chrome_resources_path;
if (!base::PathService::Get(chrome::DIR_RESOURCES, &chrome_resources_path))
return base::FilePath();
return {};
// Since component extension resources are included in
// component_extension_resources.pak file in |chrome_resources_path|,
// calculate the extension |request_relative_path| against
// |chrome_resources_path|.
if (!chrome_resources_path.IsParent(extension_resources_path))
return base::FilePath();
return {};
base::FilePath request_relative_path =
extensions::file_util::ExtensionURLToRelativeFilePath(request.url);
@ -184,7 +184,7 @@ base::FilePath ElectronExtensionsBrowserClient::GetBundleResourcePath(
->GetComponentExtensionResourceManager()
->IsComponentExtensionResource(extension_resources_path,
request_relative_path, resource_id)) {
return base::FilePath();
return {};
}
DCHECK_NE(0, *resource_id);

View file

@ -40,12 +40,13 @@ gin::IsolateHolder CreateIsolateHolder(v8::Isolate* isolate) {
// Align behavior with V8 Isolate default for Node.js.
// This is necessary for important aspects of Node.js
// including heap and cpu profilers to function properly.
return gin::IsolateHolder(
base::SingleThreadTaskRunner::GetCurrentDefault(),
gin::IsolateHolder::kSingleThread,
gin::IsolateHolder::IsolateType::kUtility, std::move(create_params),
gin::IsolateHolder::IsolateCreationMode::kNormal, nullptr, isolate);
return gin::IsolateHolder{base::SingleThreadTaskRunner::GetCurrentDefault(),
gin::IsolateHolder::kSingleThread,
gin::IsolateHolder::IsolateType::kUtility,
std::move(create_params),
gin::IsolateHolder::IsolateCreationMode::kNormal,
nullptr,
isolate};
}
} // namespace

View file

@ -335,7 +335,7 @@ extensions::SizeConstraints NativeWindow::GetSizeConstraints() const {
if (size_constraints_)
return *size_constraints_;
if (!content_size_constraints_)
return extensions::SizeConstraints();
return {};
// Convert content size constraints to window size constraints.
extensions::SizeConstraints constraints;
if (content_size_constraints_->HasMaximumSize()) {
@ -369,7 +369,7 @@ extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() const {
if (content_size_constraints_)
return *content_size_constraints_;
if (!size_constraints_)
return extensions::SizeConstraints();
return {};
// Convert window size constraints to content size constraints.
// Note that we are not caching the results, because Chromium reccalculates
// window frame size everytime when min/max sizes are passed, and we must

View file

@ -14,6 +14,7 @@
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/input/cursor_manager.h"
@ -116,9 +117,9 @@ ui::MouseEvent UiMouseEventFromWebMouseEvent(blink::WebMouseEvent event) {
ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
blink::WebMouseWheelEvent event) {
return ui::MouseWheelEvent(UiMouseEventFromWebMouseEvent(event),
std::floor(event.delta_x),
std::floor(event.delta_y));
return {UiMouseEventFromWebMouseEvent(event),
base::ClampFloor<int>(event.delta_x),
base::ClampFloor<int>(event.delta_y)};
}
} // namespace

View file

@ -29,7 +29,7 @@ std::string PluginUtils::GetExtensionIdForMimeType(
auto it = map.find(mime_type);
if (it != map.end())
return it->second;
return std::string();
return {};
}
base::flat_map<std::string, std::string>

View file

@ -56,7 +56,7 @@ gfx::Size GetDefaultPrinterDPI(const std::u16string& device_name) {
GtkPrintSettings* print_settings = gtk_print_settings_new();
int dpi = gtk_print_settings_get_resolution(print_settings);
g_object_unref(print_settings);
return gfx::Size(dpi, dpi);
return {dpi, dpi};
#endif
}

View file

@ -246,7 +246,7 @@ gfx::Rect AutofillPopup::popup_bounds_in_view() {
gfx::Point origin(popup_bounds_.origin());
views::View::ConvertPointFromScreen(parent_, &origin);
return gfx::Rect(origin, popup_bounds_.size());
return {origin, popup_bounds_.size()};
}
void AutofillPopup::OnViewBoundsChanged(views::View* view) {
@ -281,9 +281,8 @@ int AutofillPopup::GetDesiredPopupWidth() {
gfx::Rect AutofillPopup::GetRowBounds(int index) {
int top = kPopupBorderThickness + index * kRowHeight;
return gfx::Rect(kPopupBorderThickness, top,
popup_bounds_.width() - 2 * kPopupBorderThickness,
kRowHeight);
return {kPopupBorderThickness, top,
popup_bounds_.width() - 2 * kPopupBorderThickness, kRowHeight};
}
const gfx::FontList& AutofillPopup::GetValueFontListForRow(int index) const {

View file

@ -49,12 +49,12 @@ gfx::Insets ElectronDesktopWindowTreeHostLinux::CalculateInsetsInDIP(
ui::PlatformWindowState window_state) const {
// If we are not showing frame, the insets should be zero.
if (native_window_view_->IsFullscreen()) {
return gfx::Insets();
return {};
}
if (!native_window_view_->has_frame() ||
!native_window_view_->has_client_frame()) {
return gfx::Insets();
return {};
}
auto* view = static_cast<ClientFrameViewLinux*>(

View file

@ -26,7 +26,7 @@ void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
void TrayIcon::CloseContextMenu() {}
gfx::Rect TrayIcon::GetBounds() {
return gfx::Rect();
return {};
}
void TrayIcon::NotifyClicked(const gfx::Rect& bounds,

View file

@ -155,8 +155,8 @@ gfx::Insets ClientFrameViewLinux::GetBorderDecorationInsets() const {
}
gfx::Insets ClientFrameViewLinux::GetInputInsets() const {
return gfx::Insets(
host_supports_client_frame_shadow_ ? -kResizeOutsideBorderSize : 0);
return gfx::Insets{
host_supports_client_frame_shadow_ ? -kResizeOutsideBorderSize : 0};
}
gfx::Rect ClientFrameViewLinux::GetWindowContentBounds() const {
@ -458,7 +458,7 @@ void ClientFrameViewLinux::LayoutButtonsOnSide(
gfx::Rect ClientFrameViewLinux::GetTitlebarBounds() const {
if (frame_->IsFullscreen()) {
return gfx::Rect();
return {};
}
int font_height = gfx::FontList().GetHeight();

View file

@ -339,7 +339,7 @@ bool OpaqueFrameView::IsFrameCondensed() const {
}
gfx::Insets OpaqueFrameView::RestoredFrameBorderInsets() const {
return gfx::Insets();
return {};
}
gfx::Insets OpaqueFrameView::RestoredFrameEdgeInsets() const {

View file

@ -50,8 +50,7 @@ namespace {
// If the device id wasn't specified then this is a screen capture request
// (i.e. chooseDesktopMedia() API wasn't used to generate device id).
return content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
-1 /* kFullDesktopScreenId */);
return {content::DesktopMediaID::TYPE_SCREEN, -1 /* kFullDesktopScreenId */};
}
#if BUILDFLAG(IS_MAC)

View file

@ -231,7 +231,7 @@ gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
args->ThrowError(
"clipboard.readImage is available only after app ready in the main "
"process");
return gfx::Image();
return {};
}
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
@ -272,7 +272,7 @@ void Clipboard::WriteImage(const gfx::Image& image,
#if !BUILDFLAG(IS_MAC)
void Clipboard::WriteFindText(const std::u16string& text) {}
std::u16string Clipboard::ReadFindText() {
return std::u16string();
return {};
}
#endif

View file

@ -320,7 +320,7 @@ gfx::Size NativeImage::GetSize(const std::optional<float> scale_factor) {
float sf = scale_factor.value_or(1.0f);
gfx::ImageSkiaRep image_rep = image_.AsImageSkia().GetRepresentation(sf);
return gfx::Size(image_rep.GetWidth(), image_rep.GetHeight());
return {image_rep.GetWidth(), image_rep.GetHeight()};
}
std::vector<float> NativeImage::GetScaleFactors() {
@ -490,7 +490,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
const gin_helper::Dictionary& options) {
if (!node::Buffer::HasInstance(buffer)) {
thrower.ThrowError("buffer must be a node Buffer");
return gin::Handle<NativeImage>();
return {};
}
int width = 0;
@ -498,12 +498,12 @@ gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
if (!options.Get("width", &width)) {
thrower.ThrowError("width is required");
return gin::Handle<NativeImage>();
return {};
}
if (!options.Get("height", &height)) {
thrower.ThrowError("height is required");
return gin::Handle<NativeImage>();
return {};
}
if (width <= 0 || height <= 0)
@ -514,7 +514,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
if (size_bytes != node::Buffer::Length(buffer)) {
thrower.ThrowError("invalid buffer size");
return gin::Handle<NativeImage>();
return {};
}
SkBitmap bitmap;
@ -536,7 +536,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromBuffer(
gin::Arguments* args) {
if (!node::Buffer::HasInstance(buffer)) {
thrower.ThrowError("buffer must be a node Buffer");
return gin::Handle<NativeImage>();
return {};
}
int width = 0;

View file

@ -56,7 +56,7 @@ class ElectronPermissionMessageProvider
[[nodiscard]] extensions::PermissionIDSet GetAllPermissionIDs(
const extensions::PermissionSet& permissions,
extensions::Manifest::Type extension_type) const override {
return extensions::PermissionIDSet();
return {};
}
};
@ -114,7 +114,7 @@ extensions::URLPatternSet
ElectronExtensionsClient::GetPermittedChromeSchemeHosts(
const extensions::Extension* extension,
const extensions::APIPermissionSet& api_permissions) const {
return extensions::URLPatternSet();
return {};
}
bool ElectronExtensionsClient::IsScriptableURL(const GURL& url,

View file

@ -25,16 +25,15 @@ v8::Local<v8::Object> WrappableBase::GetWrapper() const {
if (!wrapper_.IsEmpty())
return v8::Local<v8::Object>::New(isolate_, wrapper_);
else
return v8::Local<v8::Object>();
return {};
}
v8::MaybeLocal<v8::Object> WrappableBase::GetWrapper(
v8::Isolate* isolate) const {
if (!wrapper_.IsEmpty())
return v8::MaybeLocal<v8::Object>(
v8::Local<v8::Object>::New(isolate, wrapper_));
return {v8::Local<v8::Object>::New(isolate, wrapper_)};
else
return v8::MaybeLocal<v8::Object>();
return {};
}
void WrappableBase::InitWithArgs(gin::Arguments* args) {

View file

@ -23,7 +23,7 @@ v8::MaybeLocal<v8::Value> CompileAndCall(
context, id, parameters, node::Realm::GetCurrent(context));
if (compiled.IsEmpty())
return v8::MaybeLocal<v8::Value>();
return {};
v8::Local<v8::Function> fn = compiled.ToLocalChecked().As<v8::Function>();
v8::MaybeLocal<v8::Value> ret = fn->Call(

View file

@ -592,7 +592,7 @@ class WebFrameRenderer final : public gin::Wrappable<WebFrameRenderer>,
content::RenderFrame* render_frame;
if (!MaybeGetRenderFrame(isolate, "insertCSS", &render_frame))
return std::u16string();
return {};
blink::WebFrame* web_frame = render_frame->GetWebFrame();
if (web_frame->IsWebLocalFrame()) {
@ -602,7 +602,7 @@ class WebFrameRenderer final : public gin::Wrappable<WebFrameRenderer>,
css_origin)
.Utf16();
}
return std::u16string();
return {};
}
void RemoveInsertedCSS(v8::Isolate* isolate, const std::u16string& key) {

View file

@ -34,7 +34,7 @@ blink::WebElement PrintRenderFrameHelperDelegate::GetPdfElement(
return plugin_element;
}
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
return blink::WebElement();
return {};
}
bool PrintRenderFrameHelperDelegate::IsPrintPreviewEnabled() {