Bug 1338086 - Remove useless else blocks in order to reduce complexity in dom/base/ r?ehsan
MozReview-Commit-ID: 5sCNbqC4ew3
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -1100,19 +1100,18 @@ nsContentUtils::ParseHTMLInteger(const n
while (iter != end) {
if (*iter >= char16_t('0') && *iter <= char16_t('9')) {
value = (value * 10) + (*iter - char16_t('0')) * sign;
++iter;
if (!value.isValid()) {
result |= eParseHTMLInteger_Error | eParseHTMLInteger_ErrorOverflow;
break;
- } else {
- foundValue = true;
}
+ foundValue = true;
} else if (*iter == char16_t('%')) {
++iter;
result |= eParseHTMLInteger_IsPercent;
break;
} else {
break;
}
}
@@ -4937,32 +4936,30 @@ bool
nsContentUtils::AppendNodeTextContent(nsINode* aNode, bool aDeep,
nsAString& aResult,
const fallible_t& aFallible)
{
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
return static_cast<nsIContent*>(aNode)->AppendTextTo(aResult,
aFallible);
}
- else if (aDeep) {
+ if (aDeep) {
return AppendNodeTextContentsRecurse(aNode, aResult, aFallible);
}
- else {
- for (nsIContent* child = aNode->GetFirstChild();
- child;
- child = child->GetNextSibling()) {
- if (child->IsNodeOfType(nsINode::eTEXT)) {
- bool ok = child->AppendTextTo(aResult, fallible);
- if (!ok) {
- return false;
- }
+
+ for (nsIContent* child = aNode->GetFirstChild();
+ child;
+ child = child->GetNextSibling()) {
+ if (child->IsNodeOfType(nsINode::eTEXT)) {
+ bool ok = child->AppendTextTo(aResult, fallible);
+ if (!ok) {
+ return false;
}
}
}
-
return true;
}
bool
nsContentUtils::HasNonEmptyTextContent(nsINode* aNode,
TextContentDiscoverMode aDiscoverMode)
{
for (nsIContent* child = aNode->GetFirstChild();
@@ -5751,19 +5748,18 @@ nsContentUtils::GetCurrentJSContext()
/* static */
JSContext *
nsContentUtils::GetCurrentJSContextForThread()
{
MOZ_ASSERT(IsInitialized());
if (MOZ_LIKELY(NS_IsMainThread())) {
return GetCurrentJSContext();
- } else {
- return workers::GetCurrentThreadJSContext();
- }
+ }
+ return workers::GetCurrentThreadJSContext();
}
template<typename StringType, typename CharType>
void
_ASCIIToLowerInSitu(StringType& aStr)
{
CharType* iter = aStr.BeginWriting();
CharType* end = aStr.EndWriting();
@@ -8685,19 +8681,21 @@ nsContentUtils::InternalStorageAllowedFo
}
// check the permission manager for any allow or deny permissions
// for cookies for the window.
uint32_t perm;
permissionManager->TestPermissionFromPrincipal(aPrincipal, "cookie", &perm);
if (perm == nsIPermissionManager::DENY_ACTION) {
return StorageAccess::eDeny;
- } else if (perm == nsICookiePermission::ACCESS_SESSION) {
+ }
+ if (perm == nsICookiePermission::ACCESS_SESSION) {
return std::min(access, StorageAccess::eSessionScoped);
- } else if (perm == nsIPermissionManager::ALLOW_ACTION) {
+ }
+ if (perm == nsIPermissionManager::ALLOW_ACTION) {
return access;
}
// Check if we should only allow storage for the session, and record that fact
if (sCookiesLifetimePolicy == nsICookieService::ACCEPT_SESSION) {
// Storage could be StorageAccess::ePrivateBrowsing or StorageAccess::eAllow
// so perform a std::min comparison to make sure we preserve ePrivateBrowsing
// if it has been set.
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3702,20 +3702,18 @@ nsDOMWindowUtils::GetOMTAStyle(nsIDOMEle
}
if (cssValue) {
nsString text;
ErrorResult rv;
cssValue->GetCssText(text, rv);
aResult.Assign(text);
return rv.StealNSResult();
- } else {
- aResult.Truncate();
}
-
+ aResult.Truncate();
return NS_OK;
}
namespace {
class HandlingUserInputHelper final : public nsIJSRAIIHelper
{
public:
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -797,19 +797,18 @@ nsFrameMessageManager::Dump(const nsAStr
}
NS_IMETHODIMP
nsFrameMessageManager::PrivateNoteIntentionalCrash()
{
if (XRE_IsContentProcess()) {
mozilla::NoteIntentionalCrash("tab");
return NS_OK;
- } else {
- return NS_ERROR_NOT_IMPLEMENTED;
}
+ return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFrameMessageManager::GetContent(mozIDOMWindowProxy** aContent)
{
*aContent = nullptr;
return NS_OK;
}
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -6820,23 +6820,22 @@ MakeWidgetFullscreen(nsGlobalWindow* aWi
}
}
// We pass nullptr as the screen to SetWidgetFullscreen
// and FullscreenTransitionTask, as we do not wish to override
// the default screen selection behavior. The screen containing
// most of the widget will be selected.
if (!performTransition) {
return aWindow->SetWidgetFullscreen(aReason, aFullscreen, widget, nullptr);
- } else {
- nsCOMPtr<nsIRunnable> task =
- new FullscreenTransitionTask(duration, aWindow, aFullscreen,
- widget, nullptr, transitionData);
- task->Run();
- return true;
- }
+ }
+ nsCOMPtr<nsIRunnable> task =
+ new FullscreenTransitionTask(duration, aWindow, aFullscreen,
+ widget, nullptr, transitionData);
+ task->Run();
+ return true;
}
nsresult
nsGlobalWindow::SetFullscreenInternal(FullscreenReason aReason,
bool aFullScreen)
{
MOZ_ASSERT(IsOuterWindow());
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript(),
@@ -14545,20 +14544,19 @@ nsGlobalWindow::CreateImageBitmap(const
int32_t aOffset, int32_t aLength,
ImageBitmapFormat aFormat,
const Sequence<ChannelPixelLayout>& aLayout,
ErrorResult& aRv)
{
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
return ImageBitmap::Create(this, aImage, aOffset, aLength, aFormat, aLayout,
aRv);
- } else {
- aRv.Throw(NS_ERROR_TYPE_ERR);
- return nullptr;
- }
+ }
+ aRv.Throw(NS_ERROR_TYPE_ERR);
+ return nullptr;
}
// Helper called by methods that move/resize the window,
// to ensure the presContext (if any) is aware of resolution
// change that may happen in multi-monitor configuration.
void
nsGlobalWindow::CheckForDPIChange()
{
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -1387,21 +1387,21 @@ nsImageLoadingContent::ClearPendingReque
mPendingRequestFlags = 0;
}
bool*
nsImageLoadingContent::GetRegisteredFlagForRequest(imgIRequest* aRequest)
{
if (aRequest == mCurrentRequest) {
return &mCurrentRequestRegistered;
- } else if (aRequest == mPendingRequest) {
+ }
+ if (aRequest == mPendingRequest) {
return &mPendingRequestRegistered;
- } else {
- return nullptr;
}
+ return nullptr;
}
void
nsImageLoadingContent::ResetAnimationIfNeeded()
{
if (mCurrentRequest &&
(mCurrentRequestFlags & REQUEST_NEEDS_ANIMATION_RESET)) {
nsCOMPtr<imgIContainer> container;
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -232,17 +232,18 @@ CheckPluginStopEvent::Run()
LOG(("OBJLC [%p]: CheckPluginStopEvent - No frame, flushing layout", this));
nsIDocument* composedDoc = content->GetComposedDoc();
if (composedDoc) {
composedDoc->FlushPendingNotifications(FlushType::Layout);
if (objLC->mPendingCheckPluginStopEvent != this) {
LOG(("OBJLC [%p]: CheckPluginStopEvent - superseded in layout flush",
this));
return NS_OK;
- } else if (content->GetPrimaryFrame()) {
+ }
+ if (content->GetPrimaryFrame()) {
LOG(("OBJLC [%p]: CheckPluginStopEvent - frame gained in layout flush",
this));
objLC->mPendingCheckPluginStopEvent = nullptr;
return NS_OK;
}
}
// Still no frame, suspend plugin. HasNewFrame will restart us when we
@@ -1028,20 +1029,19 @@ nsObjectLoadingContent::OnStartRequest(n
if (mType == eType_Plugin) {
if (!mInstanceOwner) {
// We drop mChannel when stopping plugins, so something is wrong
NS_NOTREACHED("Opened a channel in plugin mode, but don't have a plugin");
return NS_BINDING_ABORTED;
}
if (MakePluginListener()) {
return mFinalListener->OnStartRequest(aRequest, nullptr);
- } else {
- NS_NOTREACHED("Failed to create PluginStreamListener, aborting channel");
- return NS_BINDING_ABORTED;
}
+ NS_NOTREACHED("Failed to create PluginStreamListener, aborting channel");
+ return NS_BINDING_ABORTED;
}
// Otherwise we should be state loading, and call LoadObject with the channel
if (mType != eType_Loading) {
NS_NOTREACHED("Should be type loading at this point");
return NS_BINDING_ABORTED;
}
NS_ASSERTION(!mChannelLoaded, "mChannelLoaded set already?");
@@ -1064,17 +1064,18 @@ nsObjectLoadingContent::OnStartRequest(n
nsString message = NS_LITERAL_STRING("Blocking ") +
NS_ConvertASCIItoUTF16(uri->GetSpecOrDefault().get()) +
NS_LITERAL_STRING(" since it was found on an internal Firefox blocklist.");
console->LogStringMessage(message.get());
}
Telemetry::Accumulate(Telemetry::PLUGIN_BLOCKED_FOR_STABILITY, 1);
mContentBlockingEnabled = true;
return NS_ERROR_FAILURE;
- } else if (status == NS_ERROR_TRACKING_URI) {
+ }
+ if (status == NS_ERROR_TRACKING_URI) {
mContentBlockingEnabled = true;
return NS_ERROR_FAILURE;
}
if (!success) {
LOG(("OBJLC [%p]: OnStartRequest: Request failed\n", this));
// If the request fails, we still call LoadObject() to handle fallback
// content and notifying of failure. (mChannelLoaded && !mChannel) indicates