Style policing: else-after-break, bracing, un-nest assignment (initialize decl instead), etc. (r=gal).
authorBrendan Eich <brendan@mozilla.org>
Tue, 28 Sep 2010 03:16:59 -0400
changeset 54745 407db742ce46e42e6e8d6f98d799fae3b7fcfe65
parent 54744 54700fad8cf920142b50cd1a320d819dc01f9cd9
child 54746 20ebb001f3a9ffe830589fcc1e7986f91d982ce1
push id16011
push userrsayre@mozilla.com
push dateWed, 29 Sep 2010 06:01:57 +0000
treeherdermozilla-central@d7e659b4f80c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
milestone2.0b7pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Style policing: else-after-break, bracing, un-nest assignment (initialize decl instead), etc. (r=gal).
js/narcissus/jsexec.js
js/narcissus/jsparse.js
js/src/jsproxy.cpp
--- a/js/narcissus/jsexec.js
+++ b/js/narcissus/jsexec.js
@@ -158,44 +158,44 @@ Narcissus.interpreter = (function() {
     var globalHandler = definitions.makePassthruHandler(narcissusGlobal);
     globalHandler.has = function(name) {
         if (name in narcissusGlobal) { return true; }
         // Hide Narcissus implementation code.
         else if (name === "Narcissus") { return false; }
         else { return (name in hostGlobal); }
     };
     globalHandler.get = function(receiver, name) {
-        if (narcissusGlobal.hasOwnProperty(name)) {
+        if (narcissusGlobal.hasOwnProperty(name))
             return narcissusGlobal[name];
-        }
+
         var globalFun = hostGlobal[name];
         if (definitions.isNativeCode(globalFun)) {
             // Enables native browser functions like 'alert' to work correctly.
             return Proxy.createFunction(
-                    definitions.makePassthruHandler(globalFun),
-                    function() { return globalFun.apply(hostGlobal, arguments); },
-                    function() {
-                        var a = arguments;
-                        switch (a.length) {
-                          case 0:
-                            return new globalFun();
-                          case 1:
-                            return new globalFun(a[0]);
-                          case 2:
-                            return new globalFun(a[0], a[1]);
-                          case 3:
-                            return new globalFun(a[0], a[1], a[2]);
-                          default:
-                            var argStr = "";
-                            for (var i=0; i<a.length; i++) {
-                                argStr += 'a[' + i + '],';
-                            }
-                            return eval('new ' + name + '(' + argStr.slice(0,-1) + ');');
+                definitions.makePassthruHandler(globalFun),
+                function() { return globalFun.apply(hostGlobal, arguments); },
+                function() {
+                    var a = arguments;
+                    switch (a.length) {
+                      case 0:
+                        return new globalFun();
+                      case 1:
+                        return new globalFun(a[0]);
+                      case 2:
+                        return new globalFun(a[0], a[1]);
+                      case 3:
+                        return new globalFun(a[0], a[1], a[2]);
+                      default:
+                        var argStr = "";
+                        for (var i=0; i<a.length; i++) {
+                            argStr += 'a[' + i + '],';
                         }
-                    });
+                        return eval('new ' + name + '(' + argStr.slice(0,-1) + ');');
+                    }
+                });
         }
         else { return globalFun; };
     };
 
     var global = Proxy.create(globalHandler);
 
     // Helper to avoid Object.prototype.hasOwnProperty polluting scope objects.
     function hasDirectProperty(o, p) {
@@ -838,23 +838,23 @@ Narcissus.interpreter = (function() {
             // lvalues, so we safely get the cached value directly.
             var resolved = n.resolve();
 
             if (n.forward && !resolved.intervened &&
                 !(resolved.type == FUNCTION &&
                   resolved.functionForm == parser.DECLARED_FORM)) {
                 v = resolved.v;
                 break;
-            } else {
-                for (s = x.scope; s; s = s.parent) {
-                    if (n.value in s.object)
-                        break;
-                }
-                v = new Reference(s && s.object, n.value, n);
             }
+
+            for (s = x.scope; s; s = s.parent) {
+                if (n.value in s.object)
+                    break;
+            }
+            v = new Reference(s && s.object, n.value, n);
             break;
 
           case NUMBER:
           case STRING:
           case REGEXP:
             v = n.value;
             break;
 
--- a/js/narcissus/jsparse.js
+++ b/js/narcissus/jsparse.js
@@ -1207,21 +1207,17 @@ Narcissus.parser = (function() {
                 // See http://bugzilla.mozilla.org/show_bug.cgi?id=238945.
                 t.match(SEMICOLON);
                 return n;
             }
             break;
 
           case BREAK:
           case CONTINUE:
-            if (tt === BREAK) {
-                b = builder.BREAK;
-            } else {
-                b = builder.CONTINUE;
-            }
+            b = (tt === BREAK) ? builder.BREAK : builder.CONTINUE;
             n = b.build(t);
 
             if (t.peekOnSameLine() === IDENTIFIER) {
                 t.get();
                 b.setLabel(n, t.token.value);
             }
 
             ss = x.stmtStack;
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -216,17 +216,17 @@ bool
 JSProxyHandler::iterate(JSContext *cx, JSObject *proxy, uintN flags, Value *vp)
 {
     JS_ASSERT(OperationInProgress(cx, proxy));
     AutoIdVector props(cx);
     if (!enumerate(cx, proxy, props))
         return false;
     return EnumeratedIdVectorToIterator(cx, proxy, flags, props, vp);
 }
- 
+
 JSString *
 JSProxyHandler::obj_toString(JSContext *cx, JSObject *proxy)
 {
     JS_ASSERT(proxy->isProxy());
 
     return JS_NewStringCopyZ(cx, proxy->isFunctionProxy()
                                  ? "[object Function]"
                                  : "[object Object]");
@@ -319,17 +319,17 @@ static bool
 DerivedTrap(JSContext *cx, JSObject *handler, JSAtom *atom, Value *fvalp)
 {
     JS_ASSERT(atom == ATOM(has) ||
               atom == ATOM(hasOwn) ||
               atom == ATOM(get) ||
               atom == ATOM(set) ||
               atom == ATOM(enumerateOwn) ||
               atom == ATOM(iterate));
-    
+
     return GetTrap(cx, handler, atom, fvalp);
 }
 
 static bool
 Trap(JSContext *cx, JSObject *handler, Value fval, uintN argc, Value* argv, Value *rval)
 {
     JS_CHECK_RECURSION(cx, return false);
 
@@ -1094,18 +1094,18 @@ NonNullObject(JSContext *cx, const Value
 static JSBool
 proxy_create(JSContext *cx, uintN argc, Value *vp)
 {
     if (argc < 1) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "create", "0", "s");
         return false;
     }
-    JSObject *handler;
-    if (!(handler = NonNullObject(cx, vp[2])))
+    JSObject *handler = NonNullObject(cx, vp[2]);
+    if (!handler)
         return false;
     JSObject *proto, *parent = NULL;
     if (argc > 1 && vp[3].isObject()) {
         proto = &vp[3].toObject();
         parent = proto->getParent();
     } else {
         JS_ASSERT(IsFunctionObject(vp[0]));
         proto = NULL;
@@ -1124,18 +1124,18 @@ proxy_create(JSContext *cx, uintN argc, 
 static JSBool
 proxy_createFunction(JSContext *cx, uintN argc, Value *vp)
 {
     if (argc < 2) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "createFunction", "1", "");
         return false;
     }
-    JSObject *handler;
-    if (!(handler = NonNullObject(cx, vp[2])))
+    JSObject *handler = NonNullObject(cx, vp[2]);
+    if (!handler)
         return false;
     JSObject *proto, *parent;
     parent = vp[0].toObject().getParent();
     if (!js_GetClassPrototype(cx, parent, JSProto_Function, &proto))
         return false;
     parent = proto->getParent();
 
     JSObject *call = js_ValueToCallableObject(cx, &vp[3], JSV2F_SEARCH_STACK);
@@ -1163,33 +1163,33 @@ proxy_createFunction(JSContext *cx, uint
 static JSBool
 proxy_isTrapping(JSContext *cx, uintN argc, Value *vp)
 {
     if (argc < 1) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "isTrapping", "0", "s");
         return false;
     }
-    JSObject *obj;
-    if (!(obj = NonNullObject(cx, vp[2])))
+    JSObject *obj = NonNullObject(cx, vp[2]);
+    if (!obj)
         return false;
     vp->setBoolean(obj->isProxy());
     return true;
 }
 
 static JSBool
 proxy_fix(JSContext *cx, uintN argc, Value *vp)
 {
     if (argc < 1) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
                              "fix", "0", "s");
         return false;
     }
-    JSObject *obj;
-    if (!(obj = NonNullObject(cx, vp[2])))
+    JSObject *obj = NonNullObject(cx, vp[2]);
+    if (!obj)
         return false;
     if (obj->isProxy()) {
         JSBool flag;
         if (!FixProxy(cx, obj, &flag))
             return false;
         vp->setBoolean(flag);
     } else {
         vp->setBoolean(true);
@@ -1309,18 +1309,18 @@ FixProxy(JSContext *cx, JSObject *proxy,
         return true;
     }
 
     if (OperationInProgress(cx, proxy)) {
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_PROXY_FIX);
         return false;
     }
 
-    JSObject *props;
-    if (!(props = NonNullObject(cx, tvr.value())))
+    JSObject *props = NonNullObject(cx, tvr.value());
+    if (!props)
         return false;
 
     JSObject *proto = proxy->getProto();
     JSObject *parent = proxy->getParent();
     Class *clasp = proxy->isFunctionProxy() ? &CallableObjectClass : &js_ObjectClass;
 
     /* Make a blank object from the recipe fix provided to us. */
     JSObject *newborn = NewNonFunction<WithProto::Given>(cx, clasp, proto, parent);
@@ -1334,17 +1334,17 @@ FixProxy(JSContext *cx, JSObject *proxy,
     }
 
     {
         AutoPendingProxyOperation pending(cx, proxy);
         if (!js_PopulateObject(cx, newborn, props))
             return false;
     }
 
-    /* Trade spaces between the newborn object and the proxy. */
+    /* Trade contents between the newborn object and the proxy. */
     proxy->swap(newborn);
 
     /* The GC will dispose of the proxy object. */
 
     *bp = true;
     return true;
 }