Changeset 7989

Show
Ignore:
Timestamp:
04/07/07 16:02:39 (20 months ago)
Author:
jburke
Message:

Refs #2608. Changing dojo.global() and doc() to properties for smaller code size and performance. No credible use case to have them as functions.

Location:
dojo/trunk
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/data/util/simpleFetch.js

    r7969 r7989  
    3737        var _errorHandler = function(errorData){ 
    3838                if(request.onError){ 
    39                         var scope = request.scope || dojo.global(); 
     39                        var scope = request.scope || dojo.global; 
    4040                        request.onError.call(scope, errorData); 
    4141                } 
     
    5656                }; 
    5757 
    58                 var scope = requestObject.scope || dojo.global(); 
     58                var scope = requestObject.scope || dojo.global; 
    5959                if(!requestObject.store){ 
    6060                        requestObject.store = self; 
  • dojo/trunk/tests/_base/_loader/bootstrap.js

    r7894 r7989  
    55 
    66                function hasConsole(t){ 
    7                         t.assertTrue("console" in dojo.global()); 
     7                        t.assertTrue("console" in dojo.global); 
    88                        t.assertTrue("assert" in console); 
    99                        t.assertEqual("function", typeof console.assert); 
     
    1111 
    1212                function hasDjConfig(t){ 
    13                         t.assertTrue("djConfig" in dojo.global()); 
     13                        t.assertTrue("djConfig" in dojo.global); 
    1414                }, 
    1515 
     
    1818                        setUp: function(){ 
    1919                                //Set an object in global scope. 
    20                                 dojo.global().globalValue = { 
     20                                dojo.global.globalValue = { 
    2121                                        color: "blue", 
    2222                                        size: 20 
     
    6060                                //the test is re-run. 
    6161                                try{ 
    62                                         delete dojo.global().something; 
     62                                        delete dojo.global.something; 
    6363                                        delete this.something; 
    6464                                }catch(e){} 
  • dojo/trunk/_base/array.js

    r7777 r7989  
    1212        }else{ 
    1313                var _getParts = function(arr, obj){ 
    14                         return [ (d.isString(arr) ? arr.split("") : arr), (obj||d.global()) ]; 
     14                        return [ (d.isString(arr) ? arr.split("") : arr), (obj||d.global) ]; 
    1515                } 
    1616 
     
    8989 
    9090                                // FIXME: there are several ways of handilng thisObject. Is 
    91                                 // dojo.global()always the default context? 
     91                                // dojo.global always the default context? 
    9292                                var _p = _getParts(arr, obj); arr = _p[0]; obj = _p[1]; 
    9393                                for(var i=0,l=arr.length; i<l; i++){  
  • dojo/trunk/_base/Deferred.js

    r7732 r7989  
    232232                                return a[0]; 
    233233                        }else if(dojo.isString(a[0])){ 
    234                                 return dojo.global()[a[0]]; 
     234                                return dojo.global[a[0]]; 
    235235                        } 
    236236                }else if((a[0])&&(a[1])){ 
  • dojo/trunk/_base/html.js

    r7984 r7989  
    1414                // doc: 
    1515                //              optional, defaults to the current value of 
    16                 //              dojo._currentDocument.  Can be used to retreive 
     16                //              dojo.doc.  Can be used to retreive 
    1717                //              node references from other documents. 
    1818 
    1919                if(dojo.isString(id)){ 
    20                         var _d = (doc||dojo.doc()); 
     20                        var _d = (doc||dojo.doc); 
    2121                        var te = _d.getElementById(id); 
    2222                        if((te) && (te.id == id)){ 
     
    4848                // doc: 
    4949                //              optional, defaults to the current value of 
    50                 //              dojo._currentDocument.  Can be used to retreive 
     50                //              dojo.doc.  Can be used to retreive 
    5151                //              node references from other documents. 
    5252                if(dojo.isString(id)){ 
    53                         return (doc||dojo.doc()).getElementById(id); 
     53                        return (doc||dojo.doc).getElementById(id); 
    5454                }else{ 
    5555                        return id; // DomNode 
     
    295295        var _docScroll = function(){ 
    296296                var _b = dojo.body(); 
    297                 var _w = dojo.global(); 
    298                 var de = dojo.doc().documentElement; 
     297                var _w = dojo.global; 
     298                var de = dojo.doc.documentElement; 
    299299                return { 
    300300                        y: (_w.pageYOffset || de.scrollTop || _b.scrollTop || 0), 
     
    312312                // FIXME: need to decide in the brave-new-world if we're going to be 
    313313                // margin-box or border-box. 
    314                 var ownerDocument = dojo.doc(); 
     314                var ownerDocument = dojo.doc; 
    315315                var ret = { 
    316316                        x: 0, 
  • dojo/trunk/_base/lang.js

    r7988 r7989  
    112112                } 
    113113                // locate our method 
    114                 var f = (named ? (scope||dojo.global())[method] : method); 
     114                var f = (named ? (scope||dojo.global)[method] : method); 
    115115                // invoke with collected args 
    116116                return (f)&&(f.apply(scope||this, pre.concat(args))); // Any 
     
    139139                return dojo._hitchArgs.apply(dojo, arguments); 
    140140        }else if(dojo.isString(method)){ 
    141                 scope = scope || dojo.global(); 
     141                scope = scope || dojo.global; 
    142142                return function(){ return scope[method].apply(scope, arguments||[]); } 
    143143        }else{ 
  • dojo/trunk/_base/NodeList.js

    r7960 r7989  
    174174                                //              "after" 
    175175                                // or an offset in the childNodes property 
    176                                 var ta = dojo.doc().createElement("span"); 
     176                                var ta = dojo.doc.createElement("span"); 
    177177                                if(dojo.isString(content)){ 
    178178                                        ta.innerHTML = content; 
  • dojo/trunk/_base/query.js

    r7977 r7989  
    206206                } 
    207207 
    208                 var doc = d.doc(); 
     208                var doc = d.doc; 
    209209                // var parent = d.body(); // FIXME 
    210210                // FIXME: don't need to memoize. The closure scope handles it for us. 
     
    10421042 
    10431043                // FIXME: should support more methods on the return than the stock array. 
    1044                 return _zip(getQueryFunc(query)(root||dojo.doc())); 
     1044                return _zip(getQueryFunc(query)(root||dojo.doc)); 
    10451045        } 
    10461046 
  • dojo/trunk/_base/_loader/bootstrap.js

    r7988 r7989  
    4848        } 
    4949 
    50         dojo._currentContext = this; 
    51  
    52         dojo.global = function(){ 
    53                 // summary: 
    54                 //              return the current global context object 
    55                 //              (e.g., the window object in a browser). 
    56                 // description: 
    57                 //              Refer to 'dojo.global()' rather than referring to window to ensure your 
    58                 //              code runs correctly in contexts other than web browsers (eg: Rhino on a server). 
    59                 return this._currentContext; 
    60         } 
     50        // summary: 
     51        //              return the current global context object 
     52        //              (e.g., the window object in a browser). 
     53        // description: 
     54        //              Refer to 'dojo.global' rather than referring to window to ensure your 
     55        //              code runs correctly in contexts other than web browsers (eg: Rhino on a server). 
     56        dojo.global = this; 
    6157 
    6258        var _config = { 
     
    10096 
    10197dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){ 
    102         var obj=context||dojo.global(); 
     98        var obj=context||dojo.global; 
    10399        for(var i=0, p; obj&&(p=parts[i]); i++){ 
    104100                obj = (p in obj ? obj[p] : (create ? obj[p]={} : undefined)); 
     
    118114        //      context: 
    119115        //              Optional. Object to use as root of path. Defaults to 
    120         //              'dojo.global()'. Null may be passed. 
     116        //              'dojo.global'. Null may be passed. 
    121117        var parts=name.split("."), p=parts.pop(), obj=dojo._getProp(parts, true, context); 
    122118        return (obj && p ? (obj[p]=value) : undefined); // Any 
     
    133129        //      context: 
    134130        //              Optional. Object to use as root of path. Defaults to 
    135         //              'dojo.global()'. Null may be passed. 
     131        //              'dojo.global'. Null may be passed. 
    136132        //      create:  
    137133        //              Optional. If true, Objects will be created at any point along the 
     
    150146        // obj: 
    151147        //              Optional. Object to use as root of path. Defaults to 
    152         //              'dojo.global()'. Null may be passed. 
     148        //              'dojo.global'. Null may be passed. 
    153149        return Boolean(dojo.getObject(name, false, obj)); // Boolean 
    154150} 
     
    170166        //      see also: 
    171167        //              http://trac.dojotoolkit.org/ticket/744 
    172         return dojo.global().eval ? dojo.global().eval(scriptFragment) : eval(scriptFragment);  // mixed 
     168        return dojo.global.eval ? dojo.global.eval(scriptFragment) : eval(scriptFragment);      // mixed 
    173169} 
    174170 
  • dojo/trunk/_base/_loader/hostenv_browser.js

    r7963 r7989  
    247247        dojo._writeIncludes = function(){} 
    248248 
    249         //TODOC:  HOW TO DOC THIS? 
    250         // @global: dojo._currentDocument 
     249        // @global: dojo.doc 
    251250        // summary: 
    252         //              Current document object. 'dojo._currentDocument' can be modified 
    253         //              for temporary context shifting. 
     251        //              Current document object. 'dojo.doc' can be modified 
     252        //              for temporary context shifting. Also see dojo.withDoc(). 
    254253        // description: 
    255         //    dojo.doc() returns dojo._currentDocument. Refer to dojo.doc() rather 
     254        //    Refer to dojo.doc rather 
    256255        //    than referring to 'window.document' to ensure your code runs 
    257256        //    correctly in managed contexts. 
    258         if(window["document"]){ 
    259                 dojo._currentDocument = window.document; 
    260         } 
    261  
    262         dojo.doc = function(){ 
    263                 // summary: 
    264                 //              return the document object associated with the dojo.global() 
    265                 return dojo._currentDocument; 
    266         } 
     257        dojo.doc = window["document"] || null; 
    267258 
    268259        dojo.body = function(){ 
    269260                // summary: 
    270                 //              return the body object associated with dojo.doc() 
     261                //              return the body object associated with dojo.doc 
    271262 
    272263                // Note: document.body is not defined for a strict xhtml document 
    273                 return dojo.doc().body || dojo.doc().getElementsByTagName("body")[0]; 
     264                // Would like to memoize this, but dojo.doc can change vi dojo.withDoc(). 
     265                return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0]; 
    274266        } 
    275267 
     
    278270                //              changes the behavior of many core Dojo functions that deal with 
    279271                //              namespace and DOM lookup, changing them to work in a new global 
    280                 //              context. The varibles dojo._currentContext and dojo._currentDocument 
     272                //              context. The varibles dojo.global and dojo.doc 
    281273                //              are modified as a result of calling this function. 
    282                 dojo._currentContext = globalObject; 
    283                 dojo._currentDocument = globalDocument; 
     274                dojo.global = globalObject; 
     275                dojo.doc = globalDocument; 
    284276        }; 
    285277 
     
    296288                                                                /*Array?*/cbArguments){ 
    297289                // summary: 
    298                 //              Call callback with globalObject as dojo.global() and 
    299                 //              globalObject.document as dojo.doc(). If provided, globalObject 
     290                //              Call callback with globalObject as dojo.global and 
     291                //              globalObject.document as dojo.doc. If provided, globalObject 
    300292                //              will be executed in the context of object thisObject 
    301293                // description: 
    302                 //              When callback() returns or throws an error, the dojo.global() 
    303                 //              and dojo.doc() will be restored to its previous state. 
     294                //              When callback() returns or throws an error, the dojo.global 
     295                //              and dojo.doc will be restored to its previous state. 
    304296                var rval; 
    305                 var oldGlob = dojo._currentContext; 
    306                 var oldDoc = dojo._currentDocument; 
     297                var oldGlob = dojo.global; 
     298                var oldDoc = dojo.doc; 
    307299                try{ 
    308300                        dojo.setContext(globalObject, globalObject.document); 
     
    319311                                                                /*Array?*/cbArguments){ 
    320312                // summary: 
    321                 //              Call callback with documentObject as dojo.doc(). If provided, 
     313                //              Call callback with documentObject as dojo.doc. If provided, 
    322314                //              callback will be executed in the context of object thisObject 
    323315                // description: 
    324                 //              When callback() returns or throws an error, the dojo.doc() will 
     316                //              When callback() returns or throws an error, the dojo.doc will 
    325317                //              be restored to its previous state. 
    326318                var rval; 
    327                 var oldDoc = dojo._currentDocument; 
     319                var oldDoc = dojo.doc; 
    328320                try{ 
    329                         dojo._currentDocument = documentObject; 
     321                        dojo.doc = documentObject; 
    330322                        rval = dojo._fireCallback(callback, thisObject, cbArguments); 
    331323                }finally{ 
    332                         dojo._currentDocument = oldDoc; 
     324                        dojo.doc = oldDoc; 
    333325                } 
    334326                return rval; 
  • dojo/trunk/_base/_loader/hostenv_rhino.js

    r7963 r7989  
    185185} 
    186186 
    187 dojo.doc = function(){ 
    188         // summary: 
    189         //              return the document object associated with the dojo.global() 
    190         return document; 
    191 } 
     187// summary: 
     188//              return the document object associated with the dojo.global 
     189dojo.doc = typeof(document) != "undefined" ? document : null; 
    192190 
    193191dojo.body = function(){