Ticket #3961: xhr-rpc-reduction.patch

File xhr-rpc-reduction.patch, 11.3 kB (added by peller, 14 months ago)

another ~200 bytes. Throw if json filtered comment fails.

  • Users/peller/workspace/trunk2/dojo/rpc/RpcService.js

     
    2222                                        throw new Error("Unable to load SMD from " + args); 
    2323                                }); 
    2424 
    25                         }else if(args["smdStr"]){ 
     25                        }else if(args.smdStr){ 
    2626                                this.processSmd(dojo.eval("("+args.smdStr+")")); 
    2727                        }else{ 
    2828                                // otherwise we assume it's an arguments object with the following 
     
    3232                                //      - smdStr 
    3333                                //      - smdObj 
    3434 
    35                                 if(args["serviceUrl"]){ 
     35                                if(args.serviceUrl){ 
    3636                                        this.serviceUrl = args.serviceUrl; 
    3737                                } 
    3838 
    39                                 if(args["timeout"]){ 
    40                                         this.timeout = args.timeout; 
    41                                 }else{ 
    42                                         this.timeout=3000; 
    43                                 } 
     39                                this.timeout = args.timeout || 3000; 
    4440 
    45                                 if(typeof args["strictArgChecks"] != "undefined"){ 
     41                                if("strictArgChecks" in args){ 
    4642                                        this.strictArgChecks = args.strictArgChecks; 
    4743                                } 
    4844 
  • Users/peller/workspace/trunk2/dojo/rpc/JsonService.js

     
    4242                        //summary: 
    4343                        //              parse the result envelope and pass the results back to to 
    4444                        //              the callback function 
    45                         if(obj==null){ return; } 
    46                         if(obj["Result"]!=null){  
    47                                 return obj["Result"];  
    48                         }else if(obj["result"]!=null){  
    49                                 return obj["result"];  
    50                         }else if(obj["ResultSet"]){ 
    51                                 return obj["ResultSet"]; 
    52                         }else{ 
    53                                 return obj; 
    54                         } 
     45                        if(!obj){ return; } 
     46                        return obj.Result || obj.result || obj.ResultSet || obj; 
    5547                } 
    5648        } 
    5749); 
  • Users/peller/workspace/trunk2/dojo/_base/html.js

     
    2828                //              dojo.doc.  Can be used to retreive 
    2929                //              node references from other documents. 
    3030                if(dojo.isString(id)){ 
    31                         var _d = (doc||dojo.doc); 
     31                        var _d = doc || dojo.doc; 
    3232                        var te = _d.getElementById(id); 
    3333                        // attributes.id.value is better than just id in case the  
    3434                        // user has a name=id inside a form 
    35                         if((te) && (te.attributes.id.value == id)){ 
     35                        if(te && te.attributes.id.value == id){ 
    3636                                return te; 
    3737                        }else{ 
    3838                                var eles = _d.all[id]; 
     
    4040                                if(!eles.length){ return eles; } 
    4141                                // if more than 1, choose first with the correct id 
    4242                                var i=0; 
    43                                 while(te=eles[i++]){ 
     43                                while((te=eles[i++])){ 
    4444                                        if(te.attributes.id.value == id){ return te; } 
    4545                                } 
    4646                        } 
     
    6363                //              dojo.doc.  Can be used to retreive 
    6464                //              node references from other documents. 
    6565                if(dojo.isString(id)){ 
    66                         return (doc||dojo.doc).getElementById(id); 
     66                        return (doc || dojo.doc).getElementById(id); 
    6767                }else{ 
    6868                        return id; // DomNode 
    6969                } 
     
    120120                // summary: enable or disable selection on a node 
    121121                node = dojo.byId(node); 
    122122                if(dojo.isMozilla){ 
    123                         node.style.MozUserSelect = (selectable) ? "" : "none"; 
     123                        node.style.MozUserSelect = selectable ? "" : "none"; 
    124124                }else if(dojo.isKhtml){ 
    125                         node.style.KhtmlUserSelect = (selectable) ? "auto" : "none"; 
     125                        node.style.KhtmlUserSelect = selectable ? "auto" : "none"; 
    126126                }else if(dojo.isIE){ 
    127                         node.unselectable = (selectable) ? "" : "on"; 
     127                        node.unselectable = selectable ? "" : "on"; 
    128128                        dojo.query("*", node).forEach(function(descendant){ 
    129                                 descendant.unselectable = (selectable) ? "" : "on"; 
     129                                descendant.unselectable = selectable ? "" : "on"; 
    130130                        }); 
    131131                } 
    132132                //FIXME: else?  Opera? 
     
    167167                //              "first" and "last" indicate positions as children of refNode. 
    168168 
    169169                // FIXME: need to write tests for this!!!! 
    170                 if((!node)||(!refNode)||(typeof position == "undefined")){  
     170                if(!node || !refNode || position === undefined){  
    171171                        return false;   //      boolean  
    172172                } 
    173173                node = dojo.byId(node); 
    174174                refNode = dojo.byId(refNode); 
    175175                if(typeof position == "number"){ 
    176176                        var cn = refNode.childNodes; 
    177                         if(((position == 0)&&(cn.length == 0)) || 
    178                                 (cn.length == position)){ 
     177                        if((position == 0 && cn.length == 0) || 
     178                                cn.length == position){ 
    179179                                refNode.appendChild(node); return true; 
    180180                        } 
    181181                        if(position == 0){ 
     
    272272                                s = dv.getComputedStyle(node, null); 
    273273                        } 
    274274                        return s || {}; 
    275                 }  
     275                };  
    276276        }else if(dojo.isIE){ 
    277277                gcs = function(node){ 
    278278                        return node.currentStyle; 
    279                 } 
     279                }; 
    280280        }else{ 
    281281                gcs = function(node){ 
    282282                        return dv.getComputedStyle(node, null); 
    283                 } 
     283                }; 
    284284        } 
    285285        dojo.getComputedStyle = gcs; 
    286286 
     
    292292                } 
    293293        }else{ 
    294294                dojo._toPixelValue = function(element, avalue){ 
    295                         if(!avalue){return 0;} 
     295                        if(!avalue){ return 0; } 
    296296                        // on IE7, medium is usually 4 pixels 
    297                         if(avalue=="medium"){return 4;}; 
     297                        if(avalue=="medium"){ return 4; } 
    298298                        // style values can be floats, client code may 
    299299                        // want to round this value for integer pixels. 
    300300                        if(avalue.slice && (avalue.slice(-2)=='px')){ return parseFloat(avalue); } 
     
    671671                // For whatever reason, TABLE and BUTTON are always border-box by default. 
    672672                // If you have assigned a different box to either one via CSS then 
    673673                // box functions will break. 
    674                 return (dojo.boxModel=="border-box")||(n=="TABLE")||(n=="BUTTON"); // boolean 
     674                return dojo.boxModel=="border-box" || n=="TABLE" || n=="BUTTON"; // boolean 
    675675        } 
    676676 
    677677        dojo._setContentSize = function(/*DomNode*/node, /*Number*/widthPx, /*Number*/heightPx, /*Object*/computedStyle){ 
     
    787787         
    788788        dojo._isBodyLtr = function(){ 
    789789                //FIXME: could check html and body tags directly instead of computed style?  need to ignore case, accept empty values 
    790                 return typeof dojo._bodyLtr == "undefined" ?  
    791                                 (dojo._bodyLtr = dojo.getComputedStyle(dojo.body()).direction == "ltr") : 
    792                                 dojo._bodyLtr; // Boolean  
     790                return !("_bodyLtr" in dojo) ?  
     791                        dojo._bodyLtr = dojo.getComputedStyle(dojo.body()).direction == "ltr" : 
     792                        dojo._bodyLtr; // Boolean  
    793793        } 
    794794         
    795795        dojo._getIeDocumentElementOffset = function(){ 
     
    964964        //              Pass a boolean condition if you want to explicitly add or remove. 
    965965        //      condition: 
    966966        //              If passed, true means to add the class, false means to remove. 
    967         if(typeof condition == "undefined"){ 
     967        if(condition === undefined){ 
    968968                condition = !dojo.hasClass(node, classStr); 
    969969        } 
    970970        dojo[condition ? "addClass" : "removeClass"](node, classStr); 
  • Users/peller/workspace/trunk2/dojo/_base/xhr.js

     
    5959                }).forEach(function(item){ 
    6060                        var _in = item.name; 
    6161                        var type = (item.type||"").toLowerCase(); 
    62                         if((type == "radio")||(type == "checkbox")){ 
     62                        if(type == "radio" || type == "checkbox"){ 
    6363                                if(item.checked){ setValue(ret, _in, item.value); } 
    6464                        }else if(item.multiple){ 
    6565                                ret[_in] = []; 
     
    114114                        } 
    115115                } 
    116116        } 
    117         if((ret.length)&&(ret.charAt(ret.length-1)== "&")){ 
     117        if(ret.length && ret.charAt(ret.length-1) == "&"){ 
    118118                ret = ret.substr(0, ret.length-1); 
    119119        } 
    120120        return ret; // string 
     
    208208        "text": function(xhr){ return xhr.responseText; }, 
    209209        "json": function(xhr){ 
    210210                if(!djConfig.usePlainJson){ 
    211                         console.debug("please consider using a mimetype of text/json-comment-filtered" 
     211                        console.debug("consider using a mimetype of text/json-comment-filtered" 
    212212                                + " to avoid potential security issues with JSON endpoints" 
    213213                                + " (use djConfig.usePlainJson=true to turn off this message)"); 
    214214                } 
    215215                return dojo.fromJson(xhr.responseText); 
    216216        }, 
    217         "json-comment-optional": function(xhr){  
    218                 // NOTE: we provide the json-comment-filtered option as one solution to 
    219                 // the "JavaScript Hijacking" issue noted by Fortify and others. It is 
    220                 // not appropriate for all circumstances. 
    221                 var value = xhr.responseText; 
    222                 var cStartIdx = value.indexOf("\/*"); 
    223                 var cEndIdx = value.lastIndexOf("*\/"); 
    224                 if((cStartIdx == -1)||(cEndIdx == -1)){ 
    225                         return dojo.fromJson(xhr.responseText); 
    226                 } 
    227                 return dojo.fromJson(value.substring(cStartIdx+2, cEndIdx)); 
    228         }, 
    229217        "json-comment-filtered": function(xhr){  
    230218                // NOTE: we provide the json-comment-filtered option as one solution to 
    231219                // the "JavaScript Hijacking" issue noted by Fortify and others. It is 
    232220                // not appropriate for all circumstances. 
    233                 var value = xhr.responseText; 
    234                 var cStartIdx = value.indexOf("\/*"); 
    235                 var cEndIdx = value.lastIndexOf("*\/"); 
    236                 if((cStartIdx == -1)||(cEndIdx == -1)){ 
    237                         // FIXME: throw exception instead? 
    238                         console.debug("your JSON wasn't comment filtered!");  
    239                         return ""; 
     221                var match = xhr.responseText.match(/\/\*(.*)\*\//); 
     222                if(!match){ 
     223                        throw new Error("your JSON wasn't comment filtered!"); 
    240224                } 
    241                 return dojo.fromJson(value.substring(cStartIdx+2, cEndIdx)); 
     225                return dojo.fromJson(match[1]); 
    242226        }, 
    243227        "javascript": function(xhr){  
    244228                // FIXME: try Moz and IE specific eval variants? 
     
    260244        } 
    261245}; 
    262246 
     247dojo._contentHandlers["json-comment-optional"] = function(xhr){ 
     248        var handlers = dojo._contentHandlers; 
     249        try{ 
     250                return handlers["json-comment-filtered"](xhr); 
     251        }catch(e){ 
     252                return handlers["json"](xhr); 
     253        } 
     254}; 
     255 
    263256(function(){ 
    264257 
    265258        dojo._ioSetArgs = function(/*Object*/args, 
     
    350343                //              to do cleanup on an error. It will receive two arguments: error (the  
    351344                //              Error object) and dfd, the Deferred object returned from this function. 
    352345 
    353                 var ioArgs = {}; 
    354                 ioArgs.args = args; 
     346                var ioArgs = {args: args, url: args.url}; 
    355347 
    356348                //Get values from form if requestd. 
    357349                var formObject = null; 
     
    360352                        //IE requires going through getAttributeNode instead of just getAttribute in some form cases,  
    361353                        //so use it for all.  See #2844 
    362354                        var actnNode = form.getAttributeNode("action"); 
    363                         ioArgs.url = args.url || (actnNode ? actnNode.value : null);  
     355                        ioArgs.url = ioArgs.url || (actnNode ? actnNode.value : null);  
    364356                        formObject = dojo.formToObject(form); 
    365                 }else{ 
    366                         ioArgs.url = args.url; 
    367357                } 
    368358 
    369359                // set up the query params 
     
    386376                ioArgs.handleAs = args.handleAs || "text"; 
    387377                var d = new dojo.Deferred(canceller); 
    388378                d.addCallbacks(okHandler, function(error){ 
    389                                 return errHandler(error, d); 
     379                        return errHandler(error, d); 
    390380                }); 
    391381 
    392382                //Support specifying load, error and handle callback functions from the args. 
     
    417407                // FIXME: need to wire up the xhr object's abort method to something 
    418408                // analagous in the Deferred 
    419409                return d; 
    420          
    421410        } 
    422411 
    423412        var _deferredCancel = function(/*Deferred*/dfd){ 
     
    431420        } 
    432421        var _deferredOk = function(/*Deferred*/dfd){ 
    433422                //summary: okHandler function for dojo._ioSetArgs call. 
    434                  
     423 
    435424                return dojo._contentHandlers[dfd.ioArgs.handleAs](dfd.ioArgs.xhr); 
    436425        } 
    437426        var _deferError = function(/*Error*/error, /*Deferred*/dfd){ 
     
    564553                // workaround for IE6's apply() "issues" 
    565554                var ioArgs = dfd.ioArgs; 
    566555                var args = ioArgs.args; 
    567                 ioArgs.xhr.open(type, ioArgs.url, (args.sync !== true), (args.user ? args.user : undefined), (args.password ? args.password: undefined)); 
     556                ioArgs.xhr.open(type, ioArgs.url, args.sync !== true, args.user || undefined, args.password || undefined); 
    568557                if(args.headers){ 
    569558                        for(var hdr in args.headers){ 
    570559                                if(hdr.toLowerCase() === "content-type" && !args.contentType){