Changeset 23

Show
Ignore:
Timestamp:
11/17/05 15:28:54 (3 years ago)
Author:
Jan-Klaas Kollhof
Message:

updated revision handling for module version strings

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jsolait/trunk/jsolait/jsolait.js

    r20 r23  
    11/* 
    22    Copyright (c) 2003-2005 Jan-Klaas Kollhof 
    3      
     3 
    44    This file is part of the JavaScript O Lait library(jsolait). 
    5      
     5 
    66    jsolait is free software; you can redistribute it and/or modify 
    77    it under the terms of the GNU Lesser General Public License as published by 
    88    the Free Software Foundation; either version 2.1 of the License, or 
    99    (at your option) any later version. 
    10      
     10 
    1111    This software is distributed in the hope that it will be useful, 
    1212    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414    GNU Lesser General Public License for more details. 
    15      
     15 
    1616    You should have received a copy of the GNU Lesser General Public License 
    1717    along with this software; if not, write to the Free Software 
     
    2222    The main jsolait script. 
    2323    It provides the core functionalities  for creating classes, modules and for importing modules. 
    24      
     24 
    2525    @author Jan-Klaas Kollhof 
    2626    @version 2.0 
     
    3434    Creates a new class object which inherits from superClass. 
    3535    @param name="anonymous"  The name of the new class. 
    36                                             If the created class is a public member of a module then  
     36                                            If the created class is a public member of a module then 
    3737                                            the __name__ property of that class is automatically set by Module(). 
    3838    @param bases *                  The base classes. 
    3939    @param classScope(-1)        A function which is executed for class construction. 
    40                                             As 1st parameter it will get the new class' protptype for  
     40                                            As 1st parameter it will get the new class' protptype for 
    4141                                            overrideing or extending the super class. As 2nd parameter it will get 
    4242                                            the super class' wrapper for calling inherited methods. 
     
    4949 
    5050    classScope = args.pop(); 
    51      
     51    var classID =  Class.__idcount__++; 
     52 
    5253    if((args.length>0) && (typeof args[0] =='string')){ 
    5354        name=args.shift(); 
    5455    }else{ 
    55         name="anonymous"
     56        name="anonymous" + classID
    5657    } 
    57      
     58 
    5859    var bases = args; 
    59      
     60 
    6061    //set up the 'public static' fields of the class 
    6162    var __class__={__isArray__ : false, 
    6263                     __name__ : name, 
    6364                     __bases__: bases, 
    64                      __id__: Class.__idcount__++
     65                     __id__:classID
    6566                     __hash__: function(){ 
    6667                        return this.__id__; 
     
    7071                        } 
    7172                    }; 
    72      
     73 
    7374    var baseProtos=[];//stores the prototypes of all the base classes 
    7475    var proto; //the prototype to use for the new class 
     
    8384        __class__.__bases__=[Object]; 
    8485    }else{ //inherit from all base classes 
    85         //inheritance is done by  
     86        //inheritance is done by 
    8687        var baseProto; 
    8788        for(var i=0;i<bases.length;i++){ 
     
    9596            } 
    9697            __class__.__isArray__ = __class__.__isArray__ || baseClass.__isArray__; 
    97              
     98 
    9899            if(i==0){//for the first base class just use it's proto as the final proto 
    99100                proto = baseProto; 
     
    105106                } 
    106107            } 
    107             //extend the new class' static interface  
     108            //extend the new class' static interface 
    108109            //todo: any props that should not be copied 
    109110            for(var key in baseClass){ 
     
    113114            } 
    114115        } 
    115         //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?)  
     116        //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?) 
    116117        //but will be faster than having toString call __str__, also overwriting methods unless they are ment to be overridden is not cool anyways. 
    117118        proto.toString=proto.__str__; 
     
    127128    } 
    128129    proto.__class__=__class__; 
    129    
     130 
    130131    var privId = '__priv__' + __class__.__id__; 
    131      
     132 
    132133    //run teh class setup function provided as classScope 
    133134    if(classScope.length-1 > baseProtos.length){ 
     
    136137        classScope.apply(this,[proto].concat(baseProtos)); 
    137138    } 
    138          
     139 
    139140    //allthough a single constructor would suffice for generating normal objects, Arrays and callables, 
    140141    //we use 3 different ones. This will minimize the code inside the constructor and therefore 
    141142    //minimize object construction time 
    142143    if(proto.__call__){ 
    143         //if the callable interface is implemented we need a class constructor  
     144        //if the callable interface is implemented we need a class constructor 
    144145        //which generates a function upon construction 
    145146        var NewClass = function(calledBy){ 
     
    148149                    return rslt.__call__.apply(rslt, arguments); 
    149150                }; 
    150                  
     151 
    151152                var privId='__priv__' + arguments.callee.__id__; 
    152153                rslt[privId]={}; 
    153                  
     154 
    154155                var proto=arguments.callee.prototype; 
    155156                for(var n in proto){ 
     
    166167    }else if(__class__.__isArray__){ 
    167168        //Since we cannot inherit from Array directly we take the same approach as with the callable above 
    168         //and just have a constructor which creates an Array  
     169        //and just have a constructor which creates an Array 
    169170        var NewClass = function(calledBy){ 
    170171            if(calledBy !== Class){ 
    171172                rslt=[]; 
    172                  
     173 
    173174                var privId='__priv__' + arguments.callee.__id__; 
    174175                rslt[privId]={}; 
    175                  
     176 
    176177                var proto=arguments.callee.prototype; 
    177178                for(var n in proto){ 
     
    195196        }; 
    196197    }else{ 
    197         //this is a 'normal' object constructor which does nothing but call the __init__ method  
     198        //this is a 'normal' object constructor which does nothing but call the __init__ method 
    198199        //unless it does not exsit or the constructor was used for prototyping 
    199200        var NewClass = function(calledBy){ 
     
    203204                if(this.__init__){ 
    204205                    this.__init__.apply(this, arguments); 
    205                 }     
     206                } 
    206207            } 
    207208        }; 
    208209    } 
    209      
     210 
    210211    //reset the constructor for new objects to the actual constructor. 
    211212    proto.constructor = NewClass; 
    212213    proto.__class__= NewClass;//no, it is not needed, just like __str__ is not, but it is nicer than constructor 
    213      
     214 
    214215    //this is where the inheritance realy happens 
    215216    NewClass.prototype = proto; 
    216      
     217 
    217218    //apply all the static fileds 
    218219    for(var key in __class__){ 
     
    220221    } 
    221222    NewClass.toString=__class__.__str__; 
    222      
     223 
    223224    return NewClass; 
    224 };     
     225}; 
    225226Class.__idcount__=0; 
    226227Class.toString = function(){ 
     
    228229}; 
    229230 
    230 Class.__createProto__=function(){  
     231Class.__createProto__=function(){ 
    231232    throw "Can't use Class as a base class."; 
    232233}; 
     
    245246    @param version            The version of a module. 
    246247    @param moduleScope    A function which is executed for module creation. 
    247                                      As 1st parameter it will get the module variable.                           
     248                                     As 1st parameter it will get the module variable. 
    248249                                     The imported modules(imports) will be passed to the moduleScope starting with the 2nd parameter. 
    249250**/ 
     
    253254    newMod.version = version; 
    254255    newMod.__sourceURI__ = Module.currentURI; 
    255      
     256 
    256257    newMod.toString=function(){ 
    257258        //todo:SVN adaption 
    258         return "[module '%s' version: %s]".format(this.name, this.version); 
     259        return "[module '%s' version: %s]".format(this.name, (this.version+'').replace(/\$Revision:\s(\d+) \$/, "rev.$1")); 
    259260    }; 
    260261 
     
    263264        publ.module = newMod; 
    264265    }); 
    265      
     266 
    266267    try{//to execute the scope of the module 
    267268        moduleScope.call(newMod, newMod); 
     
    269270        throw new Module.ModuleScopeExecFailed(newMod, e); 
    270271    } 
    271      
     272 
    272273    //set __name__  for methods and classes 
    273274    for(var n in newMod){ 
     
    285286}; 
    286287 
    287 Module.__createProto__=function(){  
     288Module.__createProto__=function(){ 
    288289    throw "Can't use Module as a base class."; 
    289290}; 
    290291 
    291      
     292 
    292293/** 
    293294    Base class for all module-Exceptions. 
     
    306307        this.trace = trace; 
    307308    }; 
    308      
    309      
     309 
     310 
    310311    publ.__str__=function(){ 
    311312        var s = "%s %s".format(this.name, this.module); 
     
    318319    publ.toTraceString=function(indent){ 
    319320        indent = indent==null ? 0 : indent; 
    320          
     321 
    321322        //todo:use  constructor.__name__ 
    322323        var s="%s in %s:\n%s".format(this.name, this.module, this.message.indent(4)).indent(indent); 
     
    330331        return s; 
    331332    }; 
    332      
    333     
    334      
     333 
     334 
     335 
    335336    ///The name of the Exception. 
    336337    publ.name;//todo is that needed? 
     
    340341    publ.module="jsolait"; 
    341342    ///The error which caused the Exception or undefined. 
    342     publ.trace;       
     343    publ.trace; 
    343344}); 
    344345 
     
    359360    publ.module; 
    360361}); 
    361   
    362      
     362 
     363 
    363364/** 
    364      
     365 
    365366    @author                 Jan-Klaas Kollhof 
    366367    @lastchangedby       $LastChangedBy$ 
     
    369370Module("jsolait", "$Revision$", function(mod){ 
    370371    jsolait=mod; 
     372 
    371373    mod.modules={}; 
    372              
     374 
    373375    ///The paths of  the modules that come with jsolait. 
    374376    //do not edit the following lines, it will be replaced by the build script 
     
    385387                                        "urllib":"%(baseURI)s/lib/urllib.js", 
    386388                                        "xml":"%(baseURI)s/lib/xml.js", 
    387                                         "xmlrpc":"%(baseURI)s/lib/xmlrpc.js"};  
    388     /*@moduleURIs end*/     
    389      
     389                                        "xmlrpc":"%(baseURI)s/lib/xmlrpc.js"}; 
     390    /*@moduleURIs end*/ 
     391 
    390392    ///The base URIs to search for modules in. They may contain StringFormating symbols e.g '%(baseURI)s/lib' 
    391393    mod.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 
    392         
     394 
    393395    ///The location where jsolait is installed. 
    394396    //do not edit the following lines, it will be replaced by the build script 
     
    396398    mod.baseURI="./jsolait"; 
    397399    /*@baseURI end*/ 
    398      
     400 
    399401    /** 
    400402        Creates an HTTP request object for retreiving files. 
     
    413415                }catch(e){ 
    414416                    try{// to get the old MS HTTP request object 
    415                         obj = new ActiveXObject("microsoft.XMLHTTP");  
     417                        obj = new ActiveXObject("microsoft.XMLHTTP"); 
    416418                    }catch(e){ 
    417419                        throw new mod.Exception("Unable to get an HTTP request object."); 
    418420                    } 
    419                 }     
     421                } 
    420422            } 
    421423        } 
    422424        return obj; 
    423425    }; 
    424      
     426 
    425427    /** 
    426428        Retrieves a file given its URL. 
     
    437439            xmlhttp.open("GET", uri, false); 
    438440            for(var i=0;i< headers.length;i++){ 
    439                 xmlhttp.setRequestHeader(headers[i][0], headers[i][1]);     
     441                xmlhttp.setRequestHeader(headers[i][0], headers[i][1]); 
    440442            } 
    441443            xmlhttp.send(""); 
     
    451453        } 
    452454    }; 
    453      
     455 
    454456    /** 
    455457        Thrown when a file could not be loaded. 
     
    469471        publ.sourceURI; 
    470472    }); 
    471      
    472      
     473 
     474 
    473475     /** 
    474476       Imports a module given its name(someModule.someSubModule). 
    475477       A module's file location is determined by treating each module name as a directory. 
    476478       Only the last one is assumed to point to a file. 
    477        If the module's URL is not known (i.e the module name was not found in jsolait.knownModuleURIs)  
     479       If the module's URL is not known (i.e the module name was not found in jsolait.knownModuleURIs) 
    478480       then it will be searched using all URIs found in jsolait.moduleSearchURIs. 
    479481       @param name   The name of the module to load. 
     
    495497                } 
    496498            } 
    497              
     499 
    498500            if(src == null){//go through the search paths and try loading the module 
    499501                var failedURIs=[]; 
     
    511513                } 
    512514            } 
    513                          
     515 
    514516            try{//interpret the script 
    515517                var srcURI = src.__sourceURI__; 
     
    520522                throw new mod.ImportFailed(name, [srcURI], e); 
    521523            } 
    522              
    523             return mod.modules[name];  
    524         } 
    525     }; 
    526      
    527      
     524 
     525            return mod.modules[name]; 
     526        } 
     527    }; 
     528 
     529 
    528530    /** 
    529531        Thrown when a module could not be found. 
     
    546548        publ.moduleURIs; 
    547549    }); 
    548      
     550 
    549551    /** 
    550552        Imports a module given its name. 
     
    556558        return mod.__imprt__(name); 
    557559    }; 
    558      
     560 
    559561    mod.__registerModule__=function(modObj, modName){ 
    560562        if(modName != 'jsolait'){ 
     
    562564        } 
    563565    }; 
    564         
     566 
    565567    mod.registerModule=function(modObj, modName){ 
    566568        modName = modName===undefined?modObj.name : modName; 
     
    569571 
    570572 
    571 //---------------------------------------------------String Format -------------------------------------------------------     
    572     /** 
    573         Creates a format specifier object.  
     573//---------------------------------------------------String Format ------------------------------------------------------- 
     574    /** 
     575        Creates a format specifier object. 
    574576    **/ 
    575577    var FormatSpecifier=function(s){ 
     
    582584        this.paddingFlag = s[2]; 
    583585        if(this.paddingFlag==""){ 
    584             this.paddingFlag =" ";  
     586            this.paddingFlag =" "; 
    585587        } 
    586588        this.signed=(s[3] == "+"); 
     
    603605        Usage: 
    604606            resultString = formatString.format(value1, v2, ...); 
    605          
     607 
    606608        Each formatString can contain any number of formatting specifiers which are 
    607609        replaced with the formated values. 
    608          
    609         specifier([...]-items are optional):  
     610 
     611        specifier([...]-items are optional): 
    610612            "%[(key)][flag][sign][min][percision]typeOfValue" 
    611              
    612             (key)  If specified the 1st argument is treated as an object/associative array and the formating values  
     613 
     614            (key)  If specified the 1st argument is treated as an object/associative array and the formating values 
    613615                     are retrieved from that object using the key. 
    614                  
     616 
    615617            flag: 
    616618                0      Use 0s for padding. 
     
    620622                +      Numeric values will contain a +|- infront of the number. 
    621623            min: 
    622                 l      The string will be padded with the padding character until it has a minimum length of l.  
     624                l      The string will be padded with the padding character until it has a minimum length of l. 
    623625            percision: 
    624626               .x     Where x is the percision for floating point numbers and the lenght for 0 padding for integers. 
    625627            typeOfValue: 
    626                 d   Signed integer decimal.      
    627                 i   Signed integer decimal.      
     628                d   Signed integer decimal. 
     629                i   Signed integer decimal. 
    628630                b   Unsigned binary.                       //This does not exist in python! 
    629                 o   Unsigned octal.     
    630                 u   Unsigned decimal.    
    631                 x   Unsigned hexidecimal (lowercase).   
    632                 X   Unsigned hexidecimal (uppercase).   
    633                 e   Floating point exponential format (lowercase).       
    634                 E   Floating point exponential format (uppercase).       
    635                 f   Floating point decimal format.       
    636                 F   Floating point decimal format.       
    637                 c   Single character (accepts byte or single character string).      
    638                 s   String (converts any object using object.toString()).   
     631                o   Unsigned octal. 
     632                u   Unsigned decimal. 
     633                x   Unsigned hexidecimal (lowercase). 
     634                X   Unsigned hexidecimal (uppercase). 
     635                e   Floating point exponential format (lowercase). 
     636                E   Floating point exponential format (uppercase). 
     637                f   Floating point decimal format. 
     638                F   Floating point decimal format. 
     639                c   Single character (accepts byte or single character string). 
     640                s   String (converts any object using object.toString()). 
    639641        Examples: 
    640642            "%02d".format(8) == "08" 
    641643            "%05.2f".format(1.234) == "01.23" 
    642644            "123 in binary is: %08b".format(123) == "123 in binary is: 01111011" 
    643              
    644         @param *  Each parameter is treated as a formating value.  
     645 
     646        @param *  Each parameter is treated as a formating value. 
    645647        @return The formated String. 
    646648    **/ 
     
    660662        var frmt; 
    661663        var sign=""; 
    662          
     664 
    663665        for(var i=0;i<sf.length;i++){ 
    664666            s=sf[i]; 
     
    694696                    } 
    695697                } 
    696                      
     698 
    697699                if(frmt.type == "s"){//String 
    698700                    if (obj === null){ 
     
    702704                    } 
    703705                    s=obj.toString().pad(frmt.paddingFlag, frmt.minLength); 
    704                      
     706 
    705707                }else if(frmt.type == "c"){//Character 
    706708                    if(frmt.paddingFlag == "0"){ 
     
    724726                        sign = "-"; //negative signs are always needed 
    725727                    }else if(frmt.signed){ 
    726                         sign = "+"; // if sign is always wanted add it  
     728                        sign = "+"; // if sign is always wanted add it 
    727729                    }else{ 
    728730                        sign = ""; 
     
    782784        return rslt; 
    783785    }; 
    784      
     786 
    785787    /** 
    786788        Padds a String with a character to have a minimum length. 
    787          
     789 
    788790        @param flag   "-":      to padd with " " and left justify the string. 
    789                             Other: the character to use for padding.  
     791                            Other: the character to use for padding. 
    790792        @param len    The minimum length of the resulting string. 
    791793    **/ 
     
    807809        return s; 
    808810    }; 
    809      
     811 
    810812    String.prototype.indent=function(indent){ 
    811813        var out=[]; 
     
    816818        return out.join('\n'); 
    817819    }; 
    818      
     820 
    819821    String.prototype.mul=function(l){ 
    820822        var a=new Array(l+1); 
    821823        return a.join(this); 
    822824    }; 
    823      
    824     ///Tests the module. 
    825     mod.test=function(){ 
    826          
    827     }; 
     825 
    828826}); 
    829827 
     828 
  • jsolait/trunk/jsolait/lib/codecs.js

    r9 r23  
    11/* 
    22    Copyright (c) 2004-2005 Jan-Klaas Kollhof 
    3      
     3 
    44    This file is part of the JavaScript o lait library(jsolait). 
    5      
     5 
    66    jsolait is free software; you can redistribute it and/or modify 
    77    it under the terms of the GNU Lesser General Public License as published by 
    88    the Free Software Foundation; either version 2.1 of the License, or 
    99    (at your option) any later version. 
    10      
     10 
    1111    This software is distributed in the hope that it will be useful, 
    1212    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414    GNU Lesser General Public License for more details. 
    15      
     15 
    1616    You should have received a copy of the GNU Lesser General Public License 
    1717    along with this software; if not, write to the Free Software 
     
    5555        return c; 
    5656    }; 
    57      
     57 
    5858    /** 
    5959        Decodes an encoded string. 
     
    7373        } 
    7474    }; 
    75      
     75 
    7676    /** 
    7777        Encodes a string. 
     
    9191        } 
    9292    }; 
    93      
     93 
    9494    /** 
    9595        Decodes a Base64 encoded string to a byte string. 
     
    119119         } 
    120120    }; 
    121      
     121 
    122122    /** 
    123123        Encodes a string using Base64. 
     
    145145            var ri=0; 
    146146            for(var i=0;i<s.length; i+=3){ 
    147                 sbin=((s.charCodeAt(i) & 0xff) << 16) | ((s.charCodeAt(i+1) & 0xff ) << 8) | (s.charCodeAt(i+2) & 0xff);     
     147                sbin=((s.charCodeAt(i) & 0xff) << 16) | ((s.charCodeAt(i+1) & 0xff ) << 8) | (s.charCodeAt(i+2) & 0xff); 
    148148                rslt[ri] = (base64[(sbin >> 18) & 0x3f] + base64[(sbin >> 12) & 0x3f] + base64[(sbin >>6) & 0x3f] + base64[sbin & 0x3f]); 
    149149                ri++; 
     
    162162        return decodeURIComponent(this); 
    163163    }; 
    164      
     164 
    165165    /** 
    166166        Encodes a URI using encodeURIComponent. 
     
    169169        return encodeURIComponent(this); 
    170170    }; 
     171 
     172    mod.__main__=function(){ 
     173    } 
    171174}); 
  • jsolait/trunk/jsolait/lib/iter.js

    r17 r23  
    11/* 
    22  Copyright (c) 2004 Jan-Klaas Kollhof 
    3   
     3 
    44  This is free software; you can redistribute it and/or modify 
    55  it under the terms of the GNU General Public License as published by 
    66  the Free Software Foundation; either version 2 of the License, or 
    77  (at your option) any later version. 
    8   
     8 
    99  This software is distributed in the hope that it will be useful, 
    1010  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1111  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1212  GNU General Public License for more details. 
    13   
     13 
    1414  You should have received a copy of the GNU General Public License 
    1515  along with this software; if not, write to the Free Software 
    1616  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    17   
     17 
    1818*/ 
    1919 
     
    2323    if given a callback asynchronously. 
    2424    An iterable object is an object which has an iterator function (__iter__) which returns an Iterator object. 
    25      
     25 
    2626    The Range class is there to create an iterable object over a range of numbers. 
    27      
     27 
    2828    @creator                 Jan-Klaas Kollhof 
    2929    @created                2004-12-08 
     
    3232*/ 
    3333Module("iter", "$Revision$", function(mod){ 
    34          
     34 
    3535    /** 
    3636        Base class for Iterators. 
     
    5151        }; 
    5252    }); 
    53      
     53 
    5454    /** 
    5555        A simple range class to iterate over a range of numbers. 
     
    8282            this.current=this.start - this.step; 
    8383        }; 
    84          
     84 
    8585        publ.next = function(){ 
    8686            if(this.current + this.step > this.end){ 
     
    9292            } 
    9393        }; 
    94          
    95     }); 
    96      
     94 
     95    }); 
     96 
    9797    Range = mod.Range; 
    98      
     98 
    9999    /** 
    100100        Iterator for Arrays. 
     
    114114        }; 
    115115    }); 
    116      
     116 
    117117    /** 
    118118        Iterator for Objects. 
     
    125125                this.keys.push(n); 
    126126            } 
    127              
     127 
    128128            this.index = -1; 
    129129        }; 
    130          
     130 
    131131        publ.next = function(){ 
    132132            this.index += 1; 
     
    144144        }; 
    145145    }); 
    146      
     146 
    147147    Array.prototype.__iter__ = function(){ 
    148148        return new mod.ArrayItereator(this); 
    149149    }; 
    150          
     150 
    151151    /** 
    152152        Interface of a IterationCallback. 
     
    155155    */ 
    156156    mod.IterationCallback = function(item, iteration){}; 
    157      
     157 
    158158    /** 
    159159        Iteration class for handling iteration steps and callbacks. 
     
    174174                this.iterator = new mod.ObjectIterator(iterable); 
    175175            } 
    176              
     176 
    177177            this.callback = callback; 
    178178        }; 
    179          
     179 
    180180        ///Resumes a stoped iteration. 
    181181        publ.resume = function(){ 
     
    192192            } 
    193193        }; 
    194          
     194 
    195195        ///Stops an iteration 
    196196        publ.stop = function(){ 
    197197            this.doStop = true; 
    198198        }; 
    199          
    200         ///Starts/resumes an iteration         
     199 
     200        ///Starts/resumes an iteration 
    201201        publ.start = function(){ 
    202202            this.resume(); 
    203203        }; 
    204204    }); 
    205      
     205 
    206206    /** 
    207207        Class for handling asynchronous iterations. 
     
    212212            @param iterable An itaratable object. 
    213213            @param interval The time in ms betwen each step. 
    214             @param thisObj  
     214            @param thisObj 
    215215            @param callback An IterationCallback object. 
    216216        */ 
     
    227227            this.isRunning = false; 
    228228        }; 
    229          
     229 
    230230        publ.stop=function(){ 
    231231            if(this.isRunning){ 
    232232                this.isRunning = false; 
    233                 clearTimeout(this.timeout);     
     233                clearTimeout(this.timeout); 
    234234                delete iter.iterations[this.id]; 
    235235            } 
    236236        }; 
    237          
     237 
    238238        publ.resume = function(){ 
    239239            if(this.isRunning == false){ 
     
    249249            } 
    250250        }; 
    251      
     251 
    252252        publ.handleAsyncStep = function(){ 
    253253            if(this.isRunning){ 
     
    263263        }; 
    264264    }); 
    265      
    266      
     265 
     266 
    267267    /** 
    268268        Iterates over an iterable object and calls a callback for each item. 
     
    282282        } 
    283283        if(delay >-1){ 
    284             var it = new mod.AsyncIteration(iterable, delay, thisObj, cb);       
     284            var it = new mod.AsyncIteration(iterable, delay, thisObj, cb); 
    285285        }else{ 
    286286            var it = new mod.Iteration(iterable, thisObj, cb); 
     
    289289        return it; 
    290290    }; 
    291      
     291 
    292292    iter.handleAsyncStep = function(id){ 
    293293        if(iter.iterations[id]){ 
     
    297297    ///Helper object containing all async. iteration objects. 
    298298    iter.iterations = {}; 
    299        
    300      
     299 
     300 
    301301    mod.__main__=function(){ 
    302          
    303          
     302 
     303 
    304304        var  testing = imprt('testing'); 
    305305        var task=function(){ 
     
    309309            } 
    310310        }; 
    311          
     311 
    312312        r = []; 
    313313        for(var i=0;i<100;i++){ 
    314314            r[i] = i; 
    315315        } 
    316                         
    317         print("for loop \t\t\t" + testing.timeExec(100,function(){ 
     316 
     317        print("for loop \t\t\t" + testing.profile(function(){ 
    318318            var s=''; 
    319319            for(var i=0;i<100;i++){ 
     
    322322            } 
    323323        })); 
    324          
    325         print("Range iter \t\t" + testing.timeExec(100,function(){ 
     324 
     325        print("Range iter \t\t" + testing.profile(function(){ 
    326326            var s=''; 
    327327            iter(new mod.Range(100), function(item,i){ 
     
    330330            }); 
    331331        })); 
    332          
    333         print("Array iter \t\t\t" + testing.timeExec(100,function(){ 
     332 
     333        print("Array iter \t\t\t" + testing.profile(function(){ 
    334334            var s=''; 
    335335            iter(r , function(item,i){ 
     
    337337                task(); 
    338338            }); 
    339              
    340         })); 
    341          
    342         print("for in on Array \t\t" + testing.timeExec(100,function(){ 
     339 
     340        })); 
     341 
     342        print("for in on Array \t\t" + testing.profile(function(){ 
    343343            var s=''; 
    344344            for(var i in r){ 
     
    347347            } 
    348348        })); 
    349          
     349 
    350350        r = []; 
    351351        for(var i=0;i<100;i++){ 
    352352            r["k"+i] = i; 
    353353        } 
    354          
    355         print("for in  on as.Array \t" + testing.timeExec(100,function(){ 
     354 
     355        print("for in  on as.Array \t" + testing.profile(function(){ 
    356356            var s=''; 
    357357            for(var i in r){ 
     
    360360            } 
    361361        })); 
    362          
     362 
    363363        r = {}; 
    364364        for(var i=0;i<100;i++){ 
    365365            r["k"+i] = i; 
    366366        } 
    367          
    368         print("for in on dictionary \t" + testing.timeExec(100,function(){ 
     367 
     368        print("for in on dictionary \t" + testing.profile(function(){ 
    369369            var s=''; 
    370370            for(var i in r){ 
     
    373373            } 
    374374        })); 
    375          
     375 
    376376        r = []; 
    377377        for(var i=0;i<100;i++){ 
    378378            r[i] = i; 
    379379        } 
    380          
    381         print("for on Array + iter \t" + testing.timeExec(100,function(){ 
     380 
     381        print("for on Array + iter \t" + testing.profile(function(){ 
    382382            var s=''; 
    383383            for(i=r.__iter__(); item=i.next() !==undefined;){ 
  • jsolait/trunk/jsolait/lib/operators.js

    r21 r23  
    1 Module("operators", "0.0.1", function(mod){ 
     1/* 
     2  Copyright (c) 2005 Jan-Klaas Kollhof 
     3 
     4  This file is part of the JavaScript O Lait library(jsolait). 
     5 
     6  jsolait is free software; you can redistribute it and/or modify 
     7  it under the terms of the GNU Lesser General Public License as published by 
     8  the Free Software Foundation; either version 2.1 of the License, or 
     9  (at your option) any later version. 
     10 
     11  This software is distributed in the hope that it will be useful, 
     12  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14  GNU Lesser General Public License for more details. 
     15 
     16  You should have received a copy of the GNU Lesser General Public License 
     17  along with this software; if not, write to the Free Software 
     18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     19*/ 
     20 
     21Module("operators", "$Revision: 20 $",