Bug 1338086 - Remove useless else blocks in order to reduce complexity in js/ r?bbouvier draft
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 14 Feb 2017 15:50:56 +0100
changeset 484426 e9bb472aeff706389eb71d1fdce0d5c5f13e9a55
parent 484425 b5756bed7a5ce649f892195ec85692cc48b7cad5
child 484427 d267e420ed59b47c42a7e5eda174bb9911d77600
push id45470
push userbmo:sledru@mozilla.com
push dateWed, 15 Feb 2017 08:57:47 +0000
reviewersbbouvier
bugs1338086
milestone54.0a1
Bug 1338086 - Remove useless else blocks in order to reduce complexity in js/ r?bbouvier MozReview-Commit-ID: Giwp0K1YoBH
js/src/perf/pm_linux.cpp
js/xpconnect/loader/mozJSSubScriptLoader.cpp
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/src/perf/pm_linux.cpp
+++ b/js/src/perf/pm_linux.cpp
@@ -297,14 +297,13 @@ PerfMeasurement::canMeasureSomething()
     memset(&attr, 0, sizeof(attr));
     attr.size = sizeof(attr);
     attr.type = PERF_TYPE_MAX;
 
     int fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
     if (fd >= 0) {
         close(fd);
         return true;
-    } else {
-        return errno != ENOSYS;
     }
+    return errno != ENOSYS;
 }
 
 } // namespace JS
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -150,42 +150,39 @@ PrepareScript(nsIURI* uri,
             return false;
         }
 
         if (!reuseGlobal) {
             if (JS_IsGlobalObject(targetObj)) {
                 return JS::Compile(cx, options, srcBuf, script);
             }
             return JS::CompileForNonSyntacticScope(cx, options, srcBuf, script);
-        } else {
-            AutoObjectVector envChain(cx);
-            if (!JS_IsGlobalObject(targetObj) && !envChain.append(targetObj)) {
-                return false;
-            }
-            return JS::CompileFunction(cx, envChain, options, nullptr, 0, nullptr,
-                                       srcBuf, function);
+        }
+        AutoObjectVector envChain(cx);
+        if (!JS_IsGlobalObject(targetObj) && !envChain.append(targetObj)) {
+            return false;
         }
-    } else {
-        // We only use lazy source when no special encoding is specified because
-        // the lazy source loader doesn't know the encoding.
-        if (!reuseGlobal) {
-            options.setSourceIsLazy(true);
-            if (JS_IsGlobalObject(targetObj)) {
-                return JS::Compile(cx, options, buf, len, script);
-            }
-            return JS::CompileForNonSyntacticScope(cx, options, buf, len, script);
-        } else {
-            AutoObjectVector envChain(cx);
-            if (!JS_IsGlobalObject(targetObj) && !envChain.append(targetObj)) {
-                return false;
-            }
-            return JS::CompileFunction(cx, envChain, options, nullptr, 0, nullptr,
-                                       buf, len, function);
+        return JS::CompileFunction(cx, envChain, options, nullptr, 0, nullptr,
+                                   srcBuf, function);
+    }
+    // We only use lazy source when no special encoding is specified because
+    // the lazy source loader doesn't know the encoding.
+    if (!reuseGlobal) {
+        options.setSourceIsLazy(true);
+        if (JS_IsGlobalObject(targetObj)) {
+            return JS::Compile(cx, options, buf, len, script);
         }
+        return JS::CompileForNonSyntacticScope(cx, options, buf, len, script);
     }
+    AutoObjectVector envChain(cx);
+    if (!JS_IsGlobalObject(targetObj) && !envChain.append(targetObj)) {
+        return false;
+    }
+    return JS::CompileFunction(cx, envChain, options, nullptr, 0, nullptr,
+                               buf, len, function);
 }
 
 bool
 EvalScript(JSContext* cx,
            RootedObject& target_obj,
            MutableHandleValue retval,
            nsIURI* uri,
            bool cache,
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -547,46 +547,47 @@ JSXrayTraits::resolveOwnProperty(JSConte
         // Note that, as far as JS observables go, Arrays are just Objects with
         // a different prototype and a magic (own, non-configurable) |.length| that
         // serves as a non-tight upper bound on |own| indexed properties. So while
         // it's tempting to try to impose some sort of structure on what Arrays
         // "should" look like over Xrays, the underlying object is squishy enough
         // that it makes sense to just treat them like Objects for Xray purposes.
         if (key == JSProto_Object || key == JSProto_Array) {
             return getOwnPropertyFromWrapperIfSafe(cx, wrapper, id, desc);
-        } else if (IsTypedArrayKey(key)) {
+        }
+        if (IsTypedArrayKey(key)) {
             if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
                 // WebExtensions can't use cloneInto(), so we just let them do
                 // the slow thing to maximize compatibility.
                 if (CompartmentPrivate::Get(CurrentGlobalOrNull(cx))->isWebExtensionContentScript) {
                     Rooted<PropertyDescriptor> innerDesc(cx);
                     {
                         JSAutoCompartment ac(cx, target);
                         JS_MarkCrossZoneId(cx, id);
                         if (!JS_GetOwnPropertyDescriptorById(cx, target, id, &innerDesc))
                             return false;
                     }
                     if (innerDesc.isDataDescriptor() && innerDesc.value().isNumber()) {
                         desc.setValue(innerDesc.value());
                         desc.object().set(wrapper);
                     }
                     return true;
-                } else {
-                    JS_ReportErrorASCII(cx, "Accessing TypedArray data over Xrays is slow, and forbidden "
-                                        "in order to encourage performant code. To copy TypedArrays "
-                                        "across origin boundaries, consider using Components.utils.cloneInto().");
-                    return false;
                 }
+                JS_ReportErrorASCII(cx, "Accessing TypedArray data over Xrays is slow, and forbidden "
+                                    "in order to encourage performant code. To copy TypedArrays "
+                                    "across origin boundaries, consider using Components.utils.cloneInto().");
+                return false;
             }
         } else if (key == JSProto_Function) {
             if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_LENGTH)) {
                 FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY,
                                        NumberValue(JS_GetFunctionArity(JS_GetObjectFunction(target))));
                 return true;
-            } else if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) {
+            }
+            if (id == GetJSIDByIndex(cx, XPCJSContext::IDX_NAME)) {
                 RootedString fname(cx, JS_GetFunctionId(JS_GetObjectFunction(target)));
                 if (fname)
                     JS_MarkCrossZoneIdValue(cx, StringValue(fname));
                 FillPropertyDescriptor(desc, wrapper, JSPROP_PERMANENT | JSPROP_READONLY,
                                        fname ? StringValue(fname) : JS_GetEmptyStringValue(cx));
             } else {
                 // Look for various static properties/methods and the
                 // 'prototype' property.
@@ -869,17 +870,18 @@ JSXrayTraits::enumerateNames(JSContext* 
                         return false;
                     if (desc.object())
                         props.infallibleAppend(id);
                 }
             }
             for (size_t i = 0; i < props.length(); ++i)
                 JS_MarkCrossZoneId(cx, props[i]);
             return true;
-        } else if (IsTypedArrayKey(key)) {
+        }
+        if (IsTypedArrayKey(key)) {
             uint32_t length = JS_GetTypedArrayLength(target);
             // TypedArrays enumerate every indexed property in range, but
             // |length| is a getter that lives on the proto, like it should be.
             if (!props.reserve(length))
                 return false;
             for (int32_t i = 0; i <= int32_t(length - 1); ++i)
                 props.infallibleAppend(INT_TO_JSID(i));
         } else if (key == JSProto_Function) {