Changeset 73

Show
Ignore:
Timestamp:
07/31/06 17:29:41 (2 years ago)
Author:
Jan-Klaas Kollhof
Message:

removing all with(){...} blocks from generated module code because it caused problems in FireFox? where objects could not be looked up inside catch blocks. Module dependencies are now resolved before modulecreation by parsing the source code and finding all imprt statements.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jsolait/jsolait.js

    r72 r73  
    3030**/ 
    3131 
    32 jsolait=(function(publ){{with(publ){ 
    33      
    34     publ.__name__='jsolait'; 
    35      
    36     publ.__version__="$Revision$"; 
    37      
    38     publ.__str__ =function(){ 
     32jsolait=(function(mod){ 
     33     
     34    mod.__name__='jsolait'; 
     35     
     36    mod.__version__="$Revision$"; 
     37     
     38    mod.__str__ =function(){ 
    3939        return "[module '%s' version: %s]".format(this.__name__, (this.__version__+'').replace(/\$Revision:\s(\d+) \$/, "Rev.$1")); 
    4040    }; 
    41     publ.toString=__str__; 
     41    mod.toString=mod.__str__; 
    4242     
    4343    ///The location where jsolait is installed. 
    4444    //do not edit the following lines, it will be replaced by the build script 
    4545    /*@baseURI begin*/ 
    46     publ.baseURI="./jsolait"; 
     46    mod.baseURI="./jsolait"; 
    4747    /*@baseURI end*/ 
    4848         
     
    5050    //do not edit the following lines, it will be replaced by the build script 
    5151    /*@moduleSourceURIs begin*/ 
    52     publ.moduleSourceURIs={}; 
     52    mod.moduleSourceURIs={}; 
    5353    /*@moduleSourceURIs end*/ 
    5454     
     
    5858        they may contain StringFormating symbols e.g '%(baseURI)s/lib' 
    5959    **/ 
    60     publ.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 
     60    mod.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 
    6161    
    62     publ.packagesURI = "%(baseURI)s/packages"; 
    63      
    64     publ.modules={}; 
     62    mod.packagesURI = "%(baseURI)s/packages"; 
     63     
     64    mod.modules={}; 
    6565  
    6666    /** 
     
    6969        @return A string repr. the object. 
    7070    **/ 
    71     publ.str = String; 
     71    var str = String; 
    7272 
    7373    /** 
     
    7777        @return A representation of the object. 
    7878    **/ 
    79     publ.repr = function(obj){ 
     79    var repr = function(obj){ 
    8080        if(obj == null){ 
    8181            return null; 
     
    122122        @return A String containing a id value for the obj. 
    123123    **/ 
    124     publ.id = function(obj, forceId){ 
     124    var id = function(obj, forceId){ 
    125125        switch(typeof obj.__id__){ 
    126126             
     
    134134                    return obj.__id__; 
    135135                }else{ 
    136                     throw new Exception('Objec cannot be IDed: %s'.format(obj)); 
     136                    throw new mod.Exception('Objec cannot be IDed: %s'.format(obj)); 
    137137                } 
    138138             
     
    154154        @return A method which when run executes the function with the this-object being the obj specified. 
    155155    **/ 
    156     publ.bind = function(obj, fn){ 
     156    var bind = function(obj, fn){ 
    157157        return function(){ 
    158158            return fn.apply(obj, arguments); 
     
    176176        @return True if the object is an instance of cls. False otherwise. 
    177177    **/ 
    178     publ.isinstance=function(obj, cls){ 
     178    var isinstance=function(obj, cls){ 
    179179        if(obj instanceof cls){ 
    180180            return true; 
     
    197197        @return True if cls is a subclass of baseclass otherwise false. 
    198198    **/ 
    199     publ.issubclass=function(cls, baseclass){ 
     199    var issubclass=function(cls, baseclass){ 
    200200        if(baseclass === Object || cls===baseclass || (cls.prototype instanceof baseclass)){ 
    201201            return true; 
     
    230230                                                the super class' wrapper for calling inherited methods. 
    231231    **/ 
    232     publ.Class=function(name, base1, classScope){ 
     232    var Class=function(name, base1, classScope){ 
    233233        var args=[]; 
    234234        for(var i=0;i<arguments.length;i++){ 
     
    406406    Class.__createProto__=function(){ throw "Can't use Class as a base class.";}; 
    407407     
     408    mod.Class = Class; 
     409     
    408410    Function.__createProto__ = function(){ throw "Cannot inherit from Function. implement the callable interface instead using YourClass::__call__.";}; 
    409411    Array.__createProto__=function(){ var r =[]; r.__str__ = Array.prototype.toString;  return r; }; 
     
    414416    String.__str__ =String.toString=function(){return "[class String]";}; 
    415417     
    416     publ.Exception=Class(function(publ){ 
     418    mod.Exception=Class(function(publ,priv,supr){ 
    417419        /** 
    418420            Initializes a new Exception. 
     
    437439        publ.toTraceString=function(indent){ 
    438440            indent = indent==null ? 0 : indent; 
    439  
    440441            //todo:use  constructor.__name__? 
    441             var s="%s in %s:\n%s".format(this.name, this.module, this.message.indent(4)).indent(indent); 
     442            var s="%s in %s:\n%s".format(this.constructor.__name__, this.module, this.message.indent(4)).indent(indent); 
    442443            if(this.trace){ 
    443444                if(this.trace.toTraceString){ 
     
    455456        publ.message; 
    456457        ///The module the Exception belongs to. 
    457         publ.module=publ
     458        publ.module=mod
    458459        ///The error which caused the Exception or undefined. 
    459460        publ.trace; 
    460461    }); 
    461      
    462     publ.ModuleClass=Class(function(publ){ 
    463         publ.__name__; 
    464         publ.__version__; 
    465         publ.__source__; 
    466         publ.__sourceURI__; 
    467          
    468         publ.__init__=function(name, source, sourceURI){ 
    469             this.__name__=name; 
    470             this.__version__=""; 
    471             this.__source__ = source; 
    472             this.__sourceURI__ = sourceURI; 
    473         }; 
    474          
    475         publ.__str__=function(){ 
    476             //todo:SVN adaption 
    477             return "[module '%s' version: %s]".format(this.__name__, (this.__version__+'').replace(/\$Revision:\s(\d+) \$/, "Rev.$1")); 
    478         }; 
    479     }); 
    480      
     462         
    481463    /** 
    482464        Creates an HTTP request object for retreiving files. 
    483465        @return HTTP request object. 
    484466    **/ 
    485     publ.getHTTPRequestObject=function() { 
     467    mod.getHTTPRequestObject=function() { 
    486468        var obj; 
    487469        try{ //to get the mozilla httprequest object 
     
    497479                        obj = new ActiveXObject("microsoft.XMLHTTP"); 
    498480                    }catch(e){ 
    499                         throw new Exception("Unable to get an HTTP request object."); 
     481                        throw new mod.Exception("Unable to get an HTTP request object."); 
    500482                    } 
    501483                } 
     
    508490        Thrown when a file could not be loaded. 
    509491    **/ 
    510     publ.LoadURIFailed=Class(Exception, function(publ, priv,supr){ 
     492    mod.LoadURIFailed=Class(mod.Exception, function(publ, priv,supr){ 
    511493        /** 
    512494            Initializes a new LoadURIFailed Exception. 
     
    529511        @return                 The content of the file. 
    530512    **/ 
    531     publ.loadURI=function(uri, headers){ 
     513    mod.loadURI=function(uri, headers){ 
    532514        headers = (headers !== undefined) ? headers : []; 
    533515        try{ 
    534             var xmlhttp = getHTTPRequestObject(); 
     516            var xmlhttp = mod.getHTTPRequestObject(); 
    535517            xmlhttp.open("GET", uri, false); 
    536518            for(var i=0;i< headers.length;i++){ 
     
    539521            xmlhttp.send(""); 
    540522        }catch(e){ 
    541             throw new LoadURIFailed(uri, e); 
     523            throw new mod.LoadURIFailed(uri, e); 
    542524        } 
    543525        //todo: the status checking needs testing 
     
    546528            return s; 
    547529        }else{ 
    548              throw new LoadURIFailed(uri, new Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 
     530             throw new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 
    549531        } 
    550532    }; 
     
    557539         
    558540    **/ 
    559     publ.getSearchURIsForModuleName=function(name){ 
     541    mod.getSearchURIsForModuleName=function(name){ 
    560542        var sourceURI; 
    561543         
    562544        var searchURIs = []; 
    563545         
    564         if(moduleSourceURIs[name] != undefined){ 
    565             searchURIs.push(moduleSourceURIs[name].format(jsolait)); 
     546        if(mod.moduleSourceURIs[name] != undefined){ 
     547            searchURIs.push(mod.moduleSourceURIs[name].format(mod)); 
    566548        }else{ 
    567549            name = name.split('.'); 
    568550            if(name.length>1){ 
    569                 if(moduleSourceURIs[name[0]] != undefined){ 
    570                     var uri = moduleSourceURIs[name[0]].format(jsolait); 
     551                if(mod.moduleSourceURIs[name[0]] != undefined){ 
     552                    var uri = mod.moduleSourceURIs[name[0]].format(mod); 
    571553                    searchURIs.push("%s/%s.js".format(uri, name.slice(1).join('/'))); 
    572554                } 
    573                 searchURIs.push("%s/%s.js".format(packagesURI.format(jsolait),name.join('/'))); 
     555                searchURIs.push("%s/%s.js".format(mod.packagesURI.format(mod),name.join('/'))); 
    574556            } 
    575557             
    576             for(var i=0;i<moduleSearchURIs.length; i++){ 
    577                 searchURIs.push("%s/%s.js".format(moduleSearchURIs[i].format(jsolait), name.join("/"))); 
     558            for(var i=0;i<mod.moduleSearchURIs.length; i++){ 
     559                searchURIs.push("%s/%s.js".format(mod.moduleSearchURIs[i].format(mod), name.join("/"))); 
    578560            } 
    579561            name =  name.join("."); 
     
    585567        Thrown when a module could not be found. 
    586568    **/ 
    587     publ.LoadModuleFailed=Class(Exception, function(publ, supr){ 
     569    mod.LoadModuleFailed=Class(mod.Exception, function(publ, priv, supr){ 
    588570        /** 
    589571            Initializes a new LoadModuleFailed Exception. 
     
    610592       @return           The module object. 
    611593    **/ 
    612     publ.loadModule = function(name){ 
    613  
    614         if(modules[name]){ //module already loaded 
    615             return modules[name]; 
     594    mod.loadModule = function(name){ 
     595 
     596        if(mod.modules[name]){ //module already loaded 
     597            return mod.modules[name]; 
    616598        }else{ 
    617599            var src,sourceURI; 
    618              
    619             var searchURIs =getSearchURIsForModuleName(name); 
    620              
     600            var searchURIs = mod.getSearchURIsForModuleName(name); 
    621601            var failedURIs=[]; 
    622602            for(var i=0;i<searchURIs.length;i++){ 
    623603                try{ 
    624604                    sourceURI = searchURIs[i]; 
    625                     src = loadURI(sourceURI); 
     605                    src = mod.loadURI(sourceURI); 
    626606                    break; 
    627607                }catch(e){ 
     
    629609                } 
    630610            } 
    631              
    632611            if(src == null){ 
    633                 throw new LoadModuleFailed(name, failedURIs); 
     612                throw new mod.LoadModuleFailed(name, failedURIs); 
    634613            }else{ 
    635614                try{//interpret the script 
    636                     var m = createModuleFromSource(name, src, sourceURI); 
     615                    var m = mod.createModuleFromSource(name, src, sourceURI); 
    637616                    return m; 
    638617                }catch(e){ 
    639                     throw new LoadModuleFailed(name, [sourceURI], e); 
     618                    throw new mod.LoadModuleFailed(name, [sourceURI], e); 
    640619                } 
    641620            } 
     
    643622    }; 
    644623            
    645     publ.__imprt__ = function(name, destinationScope){ 
     624    mod.__imprt__ = function(name, attachTo){ 
    646625        var n=name.replace(/\s/g,"").split(":"); 
    647626        name = n[0]; 
     
    652631        } 
    653632         
    654         var m = loadModule(name); 
     633        var m = mod.loadModule(name); 
    655634         
    656635        if(items.length > 0){ 
    657636            if(items[0] == '*'){ 
    658637                for(var key in m){ 
    659                     if(key.slice(0,2) != "__" && destinationScope[key] == undefined){ 
    660                         destinationScope[key] = m[key]; 
     638                    if(key.slice(0,2) != "__" && attachTo[key] == undefined){ 
     639                        attachTo[key] = m[key]; 
    661640                    } 
    662641                } 
    663642            }else{ 
    664643                for(var i=0;i<items.length;i++){ 
    665                     destinationScope[items[i]] = m[items[i]]; 
    666                 } 
    667             } 
    668         }else{ 
    669             destinationScope[name] = m; 
    670         } 
    671     }; 
    672      
    673     publ.CreateModuleFailed=Class(Exception, function(publ, supr){ 
     644                    attachTo[items[i]] = m[items[i]]; 
     645                } 
     646            } 
     647        }else{ 
     648            attachTo[name] = m; 
     649        } 
     650    }; 
     651     
     652    var StringsOrCommentsOrImprt=/(\/\*([\n\r]|.)*?\*\/)|(\/\/.*)|('(\\'|.)*?')|("(\\"|.)*?")|\b(imprt\(.*?\))/g; 
     653    var ImprtStatement=/^imprt\(['"](.*?)['"]\)$/; 
     654     
     655    mod.getModuleDependenciesFromSource=function(source){ 
     656         
     657        var imprtStatements=[]; 
     658        var items=str(source).match(StringsOrCommentsOrImprt); 
     659        if(items){ 
     660            for(var i=0;i<items.length;i++){ 
     661                var item = items[i]; 
     662                var imprtStatement=item.match(ImprtStatement); 
     663                if(imprtStatement){ 
     664                    imprtStatements.push(imprtStatement[1]); 
     665                } 
     666            } 
     667        } 
     668        return imprtStatements; 
     669    }; 
     670     
     671    mod.ModuleClass=Class(function(publ,priv,supr){ 
     672        publ.__name__; 
     673        publ.__version__; 
     674        publ.__source__; 
     675        publ.__sourceURI__; 
     676         
     677        publ.__init__=function(name, source, sourceURI){ 
     678            this.__name__=name; 
     679            this.__version__="0.0.0"; 
     680            this.__source__ = source; 
     681            this.__sourceURI__ = sourceURI; 
     682            this.Exception = Class(mod.Exception, new Function()); 
     683            this.Exception.prototype.module = this; 
     684        }; 
     685         
     686        publ.__str__=function(){ 
     687            //todo:SVN adaption 
     688            return "[module '%s' version: %s]".format(this.__name__, (this.__version__+'').replace(/\$Revision:\s(\d+) \$/, "Rev.$1")); 
     689        }; 
     690    }); 
     691     
     692    mod.CreateModuleFailed=Class(mod.Exception, function(publ, priv, supr){ 
    674693        /** 
    675694            Initializes a new CreateModuleFailed Exception. 
     
    682701        }; 
    683702        ///The module that could not be createed. 
    684         publ.module; 
     703        publ.failedModule; 
     704         
     705        publ.__str___=function(){ 
     706            return str(this.failedModule); 
     707         
     708        } 
    685709    }); 
    686710     
    687     publ.createModule=function(name, source, sourceURI, modFn){ 
    688         var newMod = new ModuleClass(name, source, sourceURI); 
    689          
    690         var privateScope={imprt: function(imp){ 
    691                 var s = arguments.callee.scope; 
    692                 __imprt__(imp, s); 
    693             }}; 
    694         privateScope.imprt.scope=privateScope; 
    695         privateScope.Exception = Class(Exception, new Function()); 
    696         privateScope.Exception.prototype.module = newMod; 
     711    mod.createModule=function(name, source, sourceURI, modFn){ 
     712        var newMod = new mod.ModuleClass(name, source, sourceURI); 
     713         
     714        try{//to run the module source 
     715            modFn.call(newMod, newMod); 
     716        }catch(e){ 
     717            throw new mod.CreateModuleFailed(newMod, e); 
     718        } 
     719         
     720        applyNames(newMod); 
     721        
     722        mod.modules[name] = newMod; 
     723        return newMod; 
     724    }; 
     725     
     726    mod.createModuleFromSource=function(name, source, sourceURI){ 
     727        var newMod = new mod.ModuleClass(name, source, sourceURI); 
     728             
     729        var deps=mod.getModuleDependenciesFromSource(source); 
    697730         
    698731        var locals={ 
     
    703736            isinstance:isinstance, 
    704737            issubclass:issubclass, 
    705             jsolait:jsolait, 
    706738            Class:Class 
    707739        }; 
    708740         
     741        for(var i=0;i<deps.length;i++){ 
     742            mod.__imprt__(deps[i], locals); 
     743        } 
     744             
     745        var argNames = ['mod', 'imprt', 'jsolait']; 
     746        var args = []; 
     747         
     748        args.push(newMod); 
     749        args.push(new Function("","")); 
     750        args.push(mod); 
     751                 
     752        for(var key in locals){ 
     753            argNames.push(key); 
     754            args.push(locals[key]); 
     755        }                
     756         
     757        var modFn = new Function(argNames.join(","), source); 
     758             
    709759        try{//to run the module source 
    710             modFn.call(newMod, newMod, privateScope, locals); 
     760            modFn.apply(newMod, args); 
    711761        }catch(e){ 
    712             throw new CreateModuleFailed(newMod, e); 
     762            throw new mod.CreateModuleFailed(newMod, e); 
    713763        } 
    714764         
    715765        applyNames(newMod); 
    716         applyNames(privateScope); 
    717          
    718         modules[name] = newMod; 
     766        mod.modules[name] = newMod; 
    719767        return newMod; 
    720     }; 
    721      
    722     publ.createModuleFromSource=function(name, source, sourceURI){ 
    723         var modFn = new Function("publ,priv,__builtin__", "with(__builtin__){with(publ){with(priv){\n" + source + "\n}}}"); 
    724         return createModule(name, source, sourceURI, modFn); 
    725768    };      
    726769     
    727     publ.Module = function(name, modFn){ 
    728         return createModule(name, str(modFn), '', modFn); 
     770    mod.Module = function(name, modFn){ 
     771        return mod.createModule(name, str(modFn), '', modFn); 
    729772    }; 
    730773     
     
    835878        if(sf){ 
    836879            if(sf.join("") != this){ 
    837                 throw new Exception("Unsupported formating string."); 
    838             } 
    839         }else{ 
    840             throw new Exception("Unsupported formating string."); 
     880                throw new mod.Exception("Unsupported formating string."); 
     881            } 
     882        }else{ 
     883            throw new mod.Exception("Unsupported formating string."); 
    841884        } 
    842885        var rslt=""; 
     
    853896            }else if(s=="%s"){ //making %s faster 
    854897                if(cnt>=arguments.length){ 
    855                     throw new Exception("Not enough arguments for format string."); 
     898                    throw new mod.Exception("Not enough arguments for format string."); 
    856899                }else{ 
    857900                    obj=arguments[cnt]; 
     
    870913                        obj = arguments[0][frmt.key]; 
    871914                    }else{ 
    872                         throw new Exception("Object or associative array expected as formating value."); 
     915                        throw new mod.Exception("Object or associative array expected as formating value."); 
    873916                    } 
    874917                }else{//get the current value 
    875918                    if(cnt>=arguments.length){ 
    876                         throw new Exception("Not enough arguments for format string."); 
     919                        throw new mod.Exception("Not enough arguments for format string."); 
    877920                    }else{ 
    878921                        obj=arguments[cnt]; 
     
    899942                            s=pad(obj, frmt.paddingFlag, frmt.minLength); 
    900943                        }else{ 
    901                             throw new Exception("Character of length 1 required."); 
     944                            throw new mod.Exception("Character of length 1 required."); 
    902945                        } 
    903946                    }else{ 
    904                         throw new Exception("Character or Byte required."); 
     947                        throw new mod.Exception("Character or Byte required."); 
    905948                    } 
    906949                }else if(typeof obj == "number"){ 
     
    9611004                    s=pad(s, frmt.paddingFlag, frmt.minLength);//do padding and justifiing 
    9621005                }else{ 
    963                     throw new Exception("Number required."); 
     1006                    throw new mod.Exception("Number required."); 
    9641007                } 
    9651008            } 
     
    10181061    }; 
    10191062     
    1020     applyNames(publ); 
    1021      
    1022     return publ
    1023 }}}({})); 
     1063    applyNames(mod); 
     1064     
     1065    return mod
     1066}({})); 
  • branches/experimental/jsolait/jsolait.wsf

    r72 r73  
    3333    <script language="JavaScript"> <![CDATA[ 
    3434     
    35     jsolait.Module("jsolaitws", function(publ,priv,__builtin__){with(publ){with(priv){with(__builtin__){ 
    36         __version__ = "$Revision$" 
    37         __sourceURI__ = 'file://' + WScript.scriptFullName; 
     35    jsolait.Module("jsolaitws", function(mod){ 
     36        mod.__version__ = "$Revision$" 
     37        mod.__sourceURI__ = 'file://' + WScript.scriptFullName; 
    3838        jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
    3939         
     
    8383        } 
    8484         
    85         publ.run=function(){ 
     85        mod.run=function(){ 
    8686             
    8787            if (WScript.arguments.unnamed.length==0){ 
     
    106106            } 
    107107             
    108             if(fileName.toLowerCase() != jsolait.__sourceURI__.toLowerCase()  &&  fileName.toLowerCase() != __sourceURI__.toLowerCase()){ 
     108            if(fileName.toLowerCase() != jsolait.__sourceURI__.toLowerCase()  &&  fileName.toLowerCase() != mod.__sourceURI__.toLowerCase()){ 
    109109                var src = jsolait.loadURI(fileName); 
    110                  
    111110                var modl = jsolait.createModuleFromSource("__main__", src, fileName); 
    112111                try{ 
     
    123122                                break; 
    124123                            default: 
    125                                 args = repr(args); 
     124                                args = jsolait.repr(args); 
    126125                        } 
    127126                        f=new Function( "return " + args); 
     
    134133                        modl.__main__.apply(modl, args); 
    135134                    }catch(e){ 
    136                         throw new Exception("runing %s  __main__()  failed\n".format(modl),e) 
     135                        throw new mod.Exception("runing %s  __main__()  failed\n".format(modl),e) 
    137136                    } 
    138137                } 
     
    140139            } 
    141140        }; 
    142     }}}}); 
     141    }); 
    143142 
    144143    try{ 
  • branches/experimental/jsolait/lib/asyncimprt.js

    r72 r73  
    11 
    2  
     2Error.prototype.toString=function(){ 
     3    return this.message; 
     4 
     5
    36var applyNames=function(container){ 
    47    for(var n in container){ 
  • branches/experimental/jsolait/lib/codecs.js

    r68 r73  
    11/* 
    2     Copyright (c) 2004-2006 Jan-Klaas Kollhof 
     2    Copyright (c) 2004-2005 Jan-Klaas Kollhof 
    33 
    44    This file is part of the JavaScript o lait library(jsolait). 
     
    2828    @lastchangeddate    $Date$ 
    2929*/ 
    30 __version__ = "$Revision$"; 
    31  
     30mod.__version__ = "$Revision$"; 
    3231/** 
    3332    Returns all all available encoders. 
    3433    @return  An array of encoder names. 
    3534**/ 
    36 publ.listEncoders=function(){ 
     35mod.listEncoders=function(){ 
    3736    var c=[]; 
    3837    for(var attr in String.prototype){ 
     
    4746    @return  An array of decoder names. 
    4847**/ 
    49 publ.listDecoders=function(){ 
     48mod.listDecoders=function(){ 
    5049    var c=[]; 
    5150    for(var attr in String.prototype){ 
     
    7170        return String.prototype[n].apply(this, args); 
    7271    }else{ 
    73         throw new Exception("Decoder '%s' not found.".format(codec)); 
     72        throw new mod.Exception("Decoder '%s' not found.".format(codec)); 
    7473    } 
    7574}; 
     
    8988        return String.prototype[n].apply(this, args); 
    9089    }else{ 
    91         throw new Exception("Ecnoder '%s' not found.".format(codec)); 
     90        throw new mod.Exception("Ecnoder '%s' not found.".format(codec)); 
    9291    } 
    9392}; 
     
    117116         } 
    118117     }else{ 
    119          throw new Exception("String length must be divisible by 4."); 
     118         throw new mod.Exception("String length must be divisible by 4."); 
    120119     } 
    121120}; 
     
    222221    return out.join(""); 
    223222}; 
    224  
  • branches/experimental/jsolait/lib/crypto.js

    r68 r73  
    11/* 
    2     Copyright (c) 2003-2006 Jan-Klaas Kollhof 
     2    Copyright (c) 2003 Jan-Klaas Kollhof 
    33     
    44    This file is part of the JavaScript o lait library(jsolait). 
     
    2727    @lastchangeddate    $Date$ 
    2828*/ 
    29 __version__ =  "$Revision$"; 
    30  
     29mod.__version__="$Revision$"; 
    3130/** 
    3231    Returns all all available encrypters. 
    3332    @return  An array of encrypters names. 
    3433**/ 
    35 publ.listEncrypters=function(){ 
     34mod.listEncrypters=function(){ 
    3635    var c=[]; 
    3736    for(var attr in String.prototype){ 
     
    4645    @return  An array of decrypters names. 
    4746**/ 
    48 publ.listDecrypters=function(){ 
     47mod.listDecrypters=function(){ 
    4948    var c=[]; 
    5049    for(var attr in String.prototype){ 
     
    7069        return String.prototype[n].apply(this, args); 
    7170    }else{ 
    72         throw new Exception("Decrypter '%s' not found.".format(crydec)); 
     71        throw new mod.Exception("Decrypter '%s' not found.".format(crydec)); 
    7372    } 
    7473}; 
     
    8786        return String.prototype[n].apply(this, args); 
    8887    }else{ 
    89         throw new Exception("Encrypter '%s' not found.".format(crydec)); 
     88        throw new mod.Exception("Encrypter '%s' not found.".format(crydec)); 
    9089    } 
    9190}; 
  • branches/experimental/jsolait/lib/dom.js

    r68 r73  
    11/* 
    2     Copyright (c) 2005-2006 Jan-Klaas Kollhof 
     2    Copyright (c) 2005 Jan-Klaas Kollhof 
    33 
    44    This file is part of the JavaScript o lait library(jsolait). 
     
    2525    @lastchangeddate    $Date$ 
    2626**/ 
    27  
    28 __version__ = "$Revision$"; 
     27mod.__version__="$Revision$"; 
    2928 
    3029imprt("sets"); 
     
    3332    Event class. 
    3433**/ 
    35 publ.Event=Class(function(publ, supr){ 
     34mod.Event=Class(function(publ, supr){ 
    3635    publ.__init__=function(type, target){ 
    3736        this.type = type; 
     
    4847    An EventTarget implementation. 
    4948**/ 
    50 publ.EventTarget =Class(function(publ, supr){ 
     49mod.EventTarget =Class(function(publ, supr){ 
    5150    publ.__init__=function(){ 
    5251        this.eventListeners={}; 
     
    9998    It forwards all events to handler methods using the evt.type as the name for the method. 
    10099**/ 
    101 publ.EventListener=Class(function(publ){ 
     100mod.EventListener=Class(function(publ){ 
    102101    /** 
    103102        Handles events dispatched by an EventTarget. 
     
    115114    A combination of an EventTarget and a EventListener. 
    116115**/ 
    117 publ.EventListenerTarget=Class(EventTarget, EventListener, function(publ, supr){ 
     116mod.EventListenerTarget=Class(mod.EventTarget, mod.EventListener, function(publ, supr){ 
    118117}); 
  • branches/experimental/jsolait/lib/forms.js

    r68 r73  
    11/* 
    2   Copyright (c) 2005-2006 Jan-Klaas Kollhof 
     2  Copyright (c) 2005 Jan-Klaas Kollhof 
    33   
    44  This file is part of the JavaScript O Lait library(jsolait). 
     
    2828**/ 
    2929 
    30 __version__="$Revision$"; 
     30mod.__version__="$Revision$"; 
    3131/** 
    3232    A class that resembles the functionality of an HTML form. 
     
    3434    by accessing the element as a named property of the form object(formObj.elemName ...). 
    3535**/ 
    36 publ.Form=Class(function(publ, supr){ 
     36mod.Form=Class(function(publ, supr){ 
    3737    ///Contains the form elements. 
    3838    publ.elements=[]; 
     
    6868        } 
    6969        if(f == null){//add a new element 
    70             f = new Element(name, value); 
     70            f = new mod.Element(name, value); 
    7171            this.elements.push(f); 
    7272        } 
     
    164164    A form element class. 
    165165**/ 
    166 publ.Element=Class(function(publ, supr){ 
     166mod.Element=Class(function(publ, supr){ 
    167167    ///The name of the element. 
    168168    publ.name=""; 
     
    188188}) ;    
    189189 
    190 publ.__main__=function(){ 
    191     var fm = new Form("http://localhost/echoform.py", "get"); 
     190mod.__main__=function(){ 
     191    var fm = new mod.Form("http://localhost/echoform.py", "get"); 
    192192    print("testing all sorts of chars, the should be encoded."); 
    193193    fm.set("testchars", "abcdefghijklmnopqrstuvwxyz1234567890 \n\t!@#$%^&*()_+-=[]{};'\\:\"|,./<>?"); 
  • branches/experimental/jsolait/lib/itertools.js

    r68 r73  
    4343    @lastchangeddate    $Date$ 
    4444**/ 
    45 __version__ = "$Revision$" 
    46  
     45mod.__version__="$Revision$"; 
    4746 
    4847/** 
    4948    Base class for Iterators. 
    5049**/ 
    51 publ.Iterator=Class(function(publ, supr){ 
     50mod.Iterator=Class(function(publ, supr){ 
    5251    /** 
    5352        Returns the next item in the iteration. 
     
    124123     
    125124    publ.replace = function(item){ 
    126         throw new Exception("Iterator::replace() not implemented"); 
     125        throw new mod.Exception("Iterator::replace() not implemented"); 
    127126    }; 
    128127}); 
     
    131130    A simple range class to iterate over a range of numbers. 
    132131**/ 
    133 publ.Range =Class(Iterator, function(publ, supr){ 
     132mod.Range =Class(mod.Iterator, function(publ, supr){ 
    134133    /** 
    135134        Initializes a new range. 
     
    185184    @param step=1 The steps between each Item. 
    186185**/ 
    187 publ.range = function(start, end, step){ 
    188     var r=Range.__create__(arguments); 
     186mod.range = function(start, end, step){ 
     187    var r=new mod.Range(Class); 
     188    r.__init__.apply(r, arguments); 
    189189    return r; 
    190190}; 
     
    193193    Iterator for Arrays. 
    194194**/ 
    195 publ.ArrayItereator=Class(Iterator, function(publ, supr){ 
     195mod.ArrayItereator=Class(mod.Iterator, function(publ, supr){ 
    196196    publ.__init__=function(array){ 
    197197        this.array = array; 
     
    241241 
    242242Array.prototype.__iter__ = function(){ 
    243     return new ArrayItereator(this); 
     243    return new mod.ArrayItereator(this); 
    244244}; 
    245245 
     
    247247    Iterator for Objects. 
    248248**/ 
    249 publ.ObjectIterator=Class(Iterator, function(publ, supr){ 
     249mod.ObjectIterator=Class(mod.Iterator, function(publ, supr){ 
    250250    publ.__init__=function(obj){ 
    251251        this.obj = obj; 
     
    284284    @return                      An iterator object or the return value returned by the callback. 
    285285**/ 
    286 publ.iter=function(iterable, thisObj, cb){ 
     286mod.iter=function(iterable, thisObj, cb){ 
    287287    var iterator; 
    288288    if(iterable.__iter__ !==undefined){ 
    289289        iterator = iterable.__iter__(); 
    290290    }else if(iterable.length != null){ 
    291         iterator = new ArrayItereator(iterable); 
     291        iterator = new mod.ArrayItereator(iterable); 
    292292    }else if(iterable.constructor == Object){ 
    293         iterator  = new ObjectIterator(iterable); 
     293        iterator  = new mod.ObjectIterator(iterable); 
    294294    }else{ 
    295         throw new Exception("Iterable object does not provide __iter__ method or no Iterator found."); 
     295        throw new mod.Exception("Iterable object does not provide __iter__ method or no Iterator found."); 
    296296    } 
    297297    if(arguments.length==1){ 
     
    311311    @param iteration The Iteration object handling the iteration. 
    312312**/ 
    313 publ.IterationCallback = function(item, iteration){}; 
     313