Changeset 77

Show
Ignore:
Timestamp:
11/07/06 16:55:23 (2 years ago)
Author:
Jan-Klaas Kollhof
Message:

new 'code precompilation' support for simpler method and class creation, support for destructuring assignment( [a,b] = [1,2]), ...

Files:

Legend:

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

    r75 r77  
    518518    }); 
    519519     
    520     /** 
    521         Retrieves data given its URI. 
    522         @param uri             The uri to load. 
    523         @param headers=[]  The headers to use. 
    524         @return                 The content of the file. 
    525     **/ 
    526     mod.loadURI=function(uri, headers){ 
    527         headers = (headers !== undefined) ? headers : []; 
     520 
     521    mod.loadURI=function(uri, cb){ 
     522        var errorNotHandled=true; 
    528523        try{ 
    529524            var xmlhttp = mod.getHTTPRequestObject(); 
    530             xmlhttp.open("GET", uri, false); 
    531             for(var i=0;i< headers.length;i++){ 
    532                 xmlhttp.setRequestHeader(headers[i][0], headers[i][1]); 
    533             } 
     525        }catch(e){ 
     526            cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); 
     527            return; 
     528        } 
     529         
     530        xmlhttp.onreadystatechange=function(){ 
     531            if (xmlhttp.readyState==4) { 
     532                //todo: the status checking needs testing 
     533                if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 
     534                    var s= str(xmlhttp.responseText); 
     535                    xmlhttp = null; 
     536                    cb(s); 
     537                }else{ 
     538                    if(errorNotHandled){ 
     539                        errorNotHandled=false; 
     540                        cb(null, new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status))); 
     541                    } 
     542                } 
     543                xmlhttp=null; 
     544            }else if (xmlhttp.readyState==2){ 
     545                //status property should be available (MS IXMLHTTPRequest documentation) 
     546                //in Mozilla it is not if the request failed(server not reachable) 
     547                //in IE it is not available at all ?! 
     548                try{//see if it is mozilla otherwise don't care. 
     549                    var isNetscape = netscape; 
     550                    try{//if status is not available the request failed. 
     551                        var s=xmlhttp.status; 
     552                    }catch(e){//call the callback because Mozilla will not get to readystate 4 
     553                        if(errorNotHandled){ 
     554                            xmlhttp = null; 
     555                            errorNotHandled=false; 
     556                            cb(null, new mod.LoadURIFailed(uri, new mod.Exception("url request failed ",e))); 
     557                        } 
     558                    } 
     559                }catch(e){ 
     560                } 
     561            } 
     562        }; 
     563         
     564        try{ 
     565            xmlhttp.open("GET", uri, true); 
    534566            xmlhttp.send(""); 
    535567        }catch(e){ 
    536             throw new mod.LoadURIFailed(uri, e); 
    537         } 
    538         //todo: the status checking needs testing 
    539         if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 
    540             var s= str(xmlhttp.responseText); 
    541             return s; 
    542         }else{ 
    543              throw new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status)); 
    544         } 
    545     }; 
    546  
     568            if(errorNotHandled){ 
     569                errorNotHandled=false; 
     570                xmlhttp=null; 
     571                cb (null, new mod.LoadURIFailed(uri, e)); 
     572            } 
     573        } 
     574    }; 
     575     
    547576     
    548577    /** 
     
    599628     
    600629    /** 
    601        Loads a module given its name(someModule.someSubModule)
     630       Loads a module given its name(someModule.someSubModule) asynchronously
    602631       jsolait.getSearchURIsForModuleName() will be used to determine the possible locations for the source of the module. 
    603632       
    604633       @param name   The name of the module to load. 
    605        @return           The module object. 
    606     **/ 
    607     mod.loadModule = function(name){ 
     634       @param loadedCB   A callback which gets called (callback(module, error)  
     635                                when the module is loaded or an error occurs. 
     636    **/ 
     637    mod.loadModule=function(name, loadedCB){ 
    608638 
    609639        if(mod.modules[name]){ //module already loaded 
    610             return mod.modules[name]
     640            loadedCB(mod.modules[name])
    611641        }else{ 
    612642            var src,sourceURI; 
    613643            var searchURIs = mod.getSearchURIsForModuleName(name); 
     644             
    614645            var failedURIs=[]; 
    615             for(var i=0;i<searchURIs.length;i++){ 
    616                 try{ 
    617                     sourceURI = searchURIs[i]; 
    618                     src = mod.loadURI(sourceURI); 
    619                     break; 
     646            var currentURI=''; 
     647            var i=0 
     648            var handler=function(src, err){ 
     649                if(err){ 
     650                    failedURIs.push(currentURI);//err.sourceURI); 
     651                    if(searchURIs.length){ 
     652                        mod.loadURI(currentURI=searchURIs.shift(), handler); 
     653                    }else{ 
     654                        loadedCB(null, new mod.LoadModuleFailed(name, failedURIs)); 
     655                    } 
     656                }else{ 
     657                    mod.createModuleFromSource(name, src, currentURI, function(m, err){ 
     658                        loadedCB(m, err); 
     659                    }); 
     660                } 
     661            } 
     662            mod.loadURI(currentURI=searchURIs.shift(), handler); 
     663        } 
     664    }; 
     665     
     666    mod.createModuleFromSource =function(name, source, sourceURI, createdCB){ 
     667        var newMod = new mod.ModuleClass(name, source, sourceURI); 
     668     
     669        var cmpSrc = mod.compileSource(source); 
     670         
     671        var deps= cmpSrc.imports; 
     672        var source= 'with(mod){\n%s\n}'.format(cmpSrc.src); 
     673         
     674        var locals={ 
     675            str:str, 
     676            repr:repr, 
     677            id:id, 
     678            bind:bind, 
     679            isinstance:isinstance, 
     680            issubclass:issubclass, 
     681            Class:Class 
     682        }; 
     683         
     684        mod.resolveDependencies(deps, locals, function(locals, err){ 
     685            if(err){ 
     686                createdCB(newMod, err); 
     687            }else{ 
     688 
     689                var argNames = ['mod','imprt', 'jsolait']; 
     690                var args = []; 
     691                 
     692                args.push(newMod); 
     693                args.push(new Function("","")); 
     694                args.push(mod); 
     695                 
     696                for(var key in locals){ 
     697                    argNames.push(key); 
     698                    args.push(locals[key]); 
     699                }               
     700                 
     701                try{//to run the module source 
     702                    var modFn = new Function(argNames.join(","), source); 
     703                    modFn.apply(newMod, args); 
    620704                }catch(e){ 
    621                     failedURIs.push(e.sourceURI); 
    622                 } 
    623             } 
    624             if(src == null){ 
    625                 throw new mod.LoadModuleFailed(name, failedURIs); 
     705                    createdCB(newMod, new mod.CreateModuleFailed(newMod, e)); 
     706                    return; 
     707                } 
     708                               
     709                applyNames(newMod); 
     710                mod.modules[name] = newMod; 
     711                createdCB(newMod); 
     712            } 
     713        }); 
     714    }; 
     715     
     716    mod.resolveDependencies=function(deps, attachTo, resolvedCB){ 
     717        var step = function(name){ 
     718            var n=name.replace(/\s/g,"").split(":"); 
     719            name = n[0]; 
     720            if(n.length>1){ 
     721                var items = n[1].split(","); 
    626722            }else{ 
    627                 try{//interpret the script 
    628                     var m = mod.createModuleFromSource(name, src, sourceURI); 
    629                     return m; 
    630                 }catch(e){ 
    631                     throw new mod.LoadModuleFailed(name, [sourceURI], e); 
    632                 } 
    633             } 
    634         } 
    635     }; 
    636             
    637     mod.__imprt__ = function(name, attachTo){ 
    638         var n=name.replace(/\s/g,"").split(":"); 
    639         name = n[0]; 
    640         if(n.length>1){ 
    641             var items = n[1].split(","); 
    642         }else{ 
    643             var items=[]; 
    644         } 
    645          
    646         var m = mod.loadModule(name); 
    647          
    648         if(items.length > 0){ 
    649             if(items[0] == '*'){ 
    650                 for(var key in m){ 
    651                     if(key.slice(0,2) != "__" && attachTo[key] == undefined){ 
    652                         attachTo[key] = m[key]; 
    653                     } 
    654                 } 
    655             }else{ 
    656                 for(var i=0;i<items.length;i++){ 
    657                     attachTo[items[i]] = m[items[i]]; 
    658                 } 
    659             } 
    660         }else{ 
    661             var finalModuleName=name.split('.'); 
    662             finalModuleName=finalModuleName.pop(); 
    663             attachTo[finalModuleName] = m; 
    664         } 
    665     }; 
    666      
    667     var StringsOrCommentsOrImprt=/(\/\*([\n\r]|.)*?\*\/)|(\/\/.*)|('(\\'|.)*?')|("(\\"|.)*?")|\b(imprt\(.*?\))/g; 
    668     var ImprtStatement=/^imprt\(['"](.*?)['"]\)$/; 
    669      
    670     mod.getModuleDependenciesFromSource=function(source){ 
    671          
    672         var imprtStatements=[]; 
    673         var items=str(source).match(StringsOrCommentsOrImprt); 
    674         if(items){ 
    675             for(var i=0;i<items.length;i++){ 
    676                 var item = items[i]; 
    677                 var imprtStatement=item.match(ImprtStatement); 
    678                 if(imprtStatement){ 
    679                     imprtStatements.push(imprtStatement[1]); 
    680                 } 
    681             } 
    682         } 
    683         return imprtStatements; 
    684     }; 
     723                var items=[]; 
     724            } 
     725 
     726            mod.loadModule(name, function(m, err){ 
     727                if(err){ 
     728                    resolvedCB(attachTo, err); 
     729                }else{ 
     730                     
     731                    if(items.length > 0){ 
     732                        if(items[0] == '*'){ 
     733                            for(var key in m){ 
     734                                if(key.slice(0,2) != "__" && attachTo[key] == undefined){ 
     735                                    attachTo[key] = m[key]; 
     736                                } 
     737                            } 
     738                        }else{ 
     739                            for(var i=0;i<items.length;i++){ 
     740                                attachTo[items[i]] = m[items[i]]; 
     741                            } 
     742                        } 
     743                    }else{ 
     744                        var finalModuleName=name.split('.'); 
     745                        finalModuleName=finalModuleName.pop(); 
     746                        attachTo[finalModuleName] = m; 
     747                    } 
     748 
     749                    if(deps.length){ 
     750                        step(deps.shift()); 
     751                    }else{ 
     752                        resolvedCB(attachTo); 
     753                    } 
     754                } 
     755            }); 
     756        }; 
     757         
     758        if(deps.length){ 
     759            step(deps.shift()); 
     760        }else{ 
     761            resolvedCB(attachTo); 
     762        } 
     763    }; 
     764 
    685765     
    686766    mod.ModuleClass=Class(function(publ,priv,supr){ 
     
    739819    }; 
    740820     
    741     mod.createModuleFromSource=function(name, source, sourceURI){ 
    742         var newMod = new mod.ModuleClass(name, source, sourceURI); 
    743              
    744         var deps=mod.getModuleDependenciesFromSource(source); 
    745          
    746         var locals={ 
    747             str:str, 
    748             repr:repr, 
    749             id:id, 
    750             bind:bind, 
    751             isinstance:isinstance, 
    752             issubclass:issubclass, 
    753             Class:Class 
    754         }; 
    755          
    756         for(var i=0;i<deps.length;i++){ 
    757             mod.__imprt__(deps[i], locals); 
    758         } 
    759              
    760         var argNames = ['mod', 'imprt', 'jsolait']; 
    761         var args = []; 
    762          
    763         args.push(newMod); 
    764         args.push(new Function("","")); 
    765         args.push(mod); 
    766                  
    767         for(var key in locals){ 
    768             argNames.push(key); 
    769             args.push(locals[key]); 
    770         }                
    771  
    772         var modFn = new Function(argNames.join(","), source); 
    773              
    774         try{//to run the module source 
    775             modFn.apply(newMod, args); 
    776         }catch(e){ 
    777             throw new mod.CreateModuleFailed(newMod, e); 
    778         } 
    779          
    780         applyNames(newMod); 
    781         mod.modules[name] = newMod; 
    782         return newMod; 
    783     };      
    784821     
    785822    mod.Module = function(name, modFn){ 
    786         return mod.createModule(name, str(modFn), '', modFn); 
     823        return mod.createModule(name, str(modFn), 'unknown', modFn); 
    787824    }; 
    788825     
     
    796833    }; 
    797834 
     835    mod.compileSource=function(src){ 
     836        var or=function(){ 
     837            var a=[]; 
     838            for(var i=0;i<arguments.length;i++){ 
     839                a.push(grp(arguments[i])); 
     840            } 
     841            return a.join('|'); 
     842        } 
     843         
     844        var grp=function(a){ 
     845            return '(' + a + ')'; 
     846        } 
     847 
     848        var wrd=function(w){ 
     849            w= w.replace(/\\/g,'\\\\'); 
     850            w= w.replace(/\(/g,'\\('); 
     851            w= w.replace(/\)/g,'\\)'); 
     852            w= w.replace(/\//g,'\\/'); 
     853            w= w.replace(/\*/g,'\\*'); 
     854            w= w.replace(/\./g,'\\.'); 
     855            w= w.replace(/\]/g,'\\]'); 
     856            w= w.replace(/\[/g,'\\['); 
     857            w= w.replace(/\{/g,'\\{'); 
     858            w= w.replace(/\}/g,'\\}'); 
     859             
     860            return '\\b' + w + '\\b'; 
     861        }; 
     862         
     863 
     864        var parens= function(a){ 
     865            return '\\('+a+'\\)'; 
     866        } 
     867         
     868        var re=function(s){ 
     869            return new RegExp(s,'g'); 
     870        }; 
     871         
     872        var string=function(d){ 
     873            return   d + '(\\\\'+d+'|.' + d + ')*?' ; 
     874        }; 
     875         
     876        var identifier=function(){ 
     877           return '\\w+'; 
     878        }; 
     879         
     880        var anyWhiteSpaceStart= grp('(^|[\\n\\r])\\s*') ; 
     881        var someWhiteSpaceStart= grp('(^|[\\n\\r])\\s*') ; 
     882        var startOfLine= grp('^|[\\n\\r]'); 
     883         
     884        var blockComment='/\\*([\\n\\r]|.)*?\\*/'; 
     885         
     886        var comment='//' + '.*' ; 
     887         
     888        var methodDecl= grp([wrd('function'), wrd('def'),wrd('publ')].join('|')) ; 
     889         
     890        var moduleFunctionStatement = startOfLine + methodDecl +'\\s+' +grp(identifier()) + '\\s*' +  grp(parens('.*?')); 
     891         
     892        var classMethodStatement = someWhiteSpaceStart + methodDecl +'\\s+' +grp(identifier()) +  '\\s*' + grp(parens('.*?')); 
     893         
     894        var classMember= someWhiteSpaceStart + wrd('publ')+ '\\s+'  +grp(identifier()); 
     895         
     896        var classStatement = anyWhiteSpaceStart + wrd('class')+'\\s+'  +grp(identifier()) + '\\s+' + wrd('extends') +'\\s+' + grp('.+?') + '\\(\\{'; 
     897        var simpleClassStatement = anyWhiteSpaceStart + wrd('class')+'\\s+'  +grp(identifier()) + '\\s*\\(\\{'; 
     898         
     899        var importStatement = anyWhiteSpaceStart + wrd('import')+'\\s+'  + grp('.+?') + '[\\r\\n;]'; 
     900         
     901        var iterStatement= anyWhiteSpaceStart + wrd('iter') + '\\s+' +grp(identifier())+  '\\s+' + wrd('in') + '\\s+' + grp('.+?') + '\\{'; 
     902         
     903        var modLevelAssignment=startOfLine +grp(identifier())+'\\s*='; 
     904         
     905        var modGlobaling =wrd('mod') + '\\s+' + grp(identifier())  +'\\s*='; 
     906         
     907        var tupleAssingnment ='\\s\\[' + grp('.*?')  + '\\]\\s*=' + grp('.+?') + ';'; 
     908         
     909         
     910        var allStatments=re(or(blockComment, comment, string("'"), string('"'),  
     911                                        classStatement, simpleClassStatement, classMethodStatement,  moduleFunctionStatement,  
     912                                        classMember,importStatement,iterStatement,modLevelAssignment,modGlobaling,tupleAssingnment)); 
     913         
     914 
     915        var Replacer=Class(function(publ,priv,supr){ 
     916            publ.__init__=function(match, repl){ 
     917                this.match=re(match); 
     918                this.replacement=repl; 
     919            }; 
     920             
     921            publ.run = function(a){ 
     922                if(a.match(this.match)){ 
     923                    return a.replace(this.match, this.replacement); 
     924                }else{ 
     925                    return null; 
     926                } 
     927            }; 
     928        }); 
     929         
     930         
     931        var compile=function(src){ 
     932            var replacers=[ 
     933                new Replacer(moduleFunctionStatement, '$1var $3 = mod.$3=function$4' ), 
     934                new Replacer(classMethodStatement, '$1publ.$4=function$5' ) ,       
     935                new Replacer(classStatement, '$1var $3 = mod.$3=Class("$3", $4, function(publ,priv,supr){' ),        
     936                new Replacer(simpleClassStatement, '$1var $3 = mod.$3=Class("$3", function(publ,priv,supr){' ),        
     937                new Replacer(classMember, '$1publ.$3' ), 
     938                new Replacer(modLevelAssignment, '$1var $2 = mod.$2 =' ), 
     939                new Replacer(modGlobaling, '$1 = mod.$1 =' ) 
     940            ]; 
     941             
     942            var importRE=re(importStatement); 
     943            var iterRE =re(iterStatement); 
     944            var tupleRE =re(tupleAssingnment); 
     945             
     946            var imports=[]; 
     947             
     948            src =src.replace(allStatments, function(a){ 
     949                var reslt=null; 
     950 
     951                 
     952                for(var i=0;i<replacers.length;i++){ 
     953                    rslt=replacers[i].run(a); 
     954                    if(rslt!=null){  
     955                        return rslt; 
     956                    }else{ 
     957                        if(a.match(importRE)){ 
     958                            imports.push(RegExp.$3); 
     959                            return '/*' + a + '*/'; 
     960                        }else if(a.match(iterRE)){ 
     961                            imports.push('itertools:iter'); 
     962 
     963                            return a.replace(iterRE, "$1for(var $3,  _$3_iterator_= iter($4);  ($3=_$3_iterator_.next())!== undefined;){"); 
     964                        }else if(a.match(tupleRE)){ 
     965                            var names= RegExp.$1; 
     966                            var expr= RegExp.$2; 
     967                             
     968                            names = names.replace(/\s/g,'').split(','); 
     969                            var s =' var ' + names.join(',')+', _' + names.join('_') + '=' + expr +';' 
     970                            for(var i=0;i<names.length;i++){ 
     971                                s+=names[i] + '= _' + names.join('_') + '['+i+'];'; 
     972                            } 
     973                            return s; 
     974                        } 
     975                    } 
     976                } 
     977                return a; 
     978            }); 
     979             
     980            return {imports: imports, src:src}; 
     981        }; 
     982        var src = compile(src); 
     983        //print(src.src) 
     984        return src; 
     985    }; 
     986     
     987     
     988     
     989    mod.run=function(modName, methodName, alertError){ 
     990        mod.loadModule(modName, function(m, err){ 
     991            if(err){ 
     992                if(alertError){ 
     993                    alert(err); 
     994                } 
     995                throw err; 
     996            }else{ 
     997                try{ 
     998                    m[methodName].call(m); 
     999                }catch(e){ 
     1000                    if(alertError){ 
     1001                        alert(e); 
     1002                    } 
     1003                    throw e 
     1004                } 
     1005            } 
     1006        }); 
     1007     
     1008    }; 
    7981009//---------------------------------------------------String Format ------------------------------------------------------- 
    7991010    /** 
  • branches/experimental/jsolait/jsolait.wsf

    r74 r77  
    3232     
    3333    <script language="JavaScript"> <![CDATA[ 
    34      
     34        jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
     35 
     36 
    3537    jsolait.Module("jsolaitws", function(mod){ 
     38 
    3639        mod.__version__ = "$Revision$" 
    3740        mod.__sourceURI__ = 'file://' + WScript.scriptFullName; 
    38         jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
    3941         
    4042        var fs= new ActiveXObject("Scripting.FileSystemObject"); 
     
    8284            return  this.name +": " + this.message; 
    8385        } 
    84          
    85         mod.run=function(){ 
     86 
     87        mod.run=function(finishedCB){ 
    8688             
    8789            if (WScript.arguments.unnamed.length==0){ 
     
    9395                //todo:check if file exists 
    9496            } 
    95                          
     97             
    9698            //get the base of the file to execute 
    9799            var fileBase= fs.getParentFolderName(fileName); 
     
    99101            jsolait.moduleSearchURIs = [fileBase,  "%(baseURI)s/lib"]; 
    100102             
    101              
    102             //see if there are any jsolait config files in any of the parent folders 
    103             var parentFolder= fileBase; 
    104             while(parentFolder){ 
    105                 try{ 
    106                     var src = jsolait.loadURI(parentFolder+'/.jsolait'); 
    107                     try{ 
    108                         var f = new Function('__baseURI__',src); 
    109                         f(parentFolder); 
    110                         break; 
    111                     }catch(e){ 
    112                         print('error in .jsolait', parentFolder); 
    113                         break; 
    114                     } 
    115                 }catch(e){ 
    116                 } 
    117                 parentFolder=fs.getParentFolderName(parentFolder); 
    118             } 
    119  
    120  
    121103            //change working dir to the file's location 
    122104            //todo:is it OK to change cwd? 
     
    124106                wshShell.currentDirectory = fileBase.slice('file://'.length); 
    125107            } 
    126              
     108 
    127109            if(fileName.toLowerCase() != jsolait.__sourceURI__.toLowerCase()  &&  fileName.toLowerCase() != mod.__sourceURI__.toLowerCase()){ 
    128                 var src = jsolait.loadURI(fileName); 
    129                 var modl = jsolait.createModuleFromSource("__main__", src, fileName); 
    130                 try{ 
    131                     var tmain =typeof(modl.__main__); 
    132                 }catch(e){ 
    133                     var tmain=""; 
    134                 } 
    135                 if(tmain=='function'){ 
    136                     //todo find arguments 
    137                     if(WScript.arguments.named.exists("script-args")){ 
    138                         var args = WScript.arguments.named.Item("script-args"); 
    139                         switch(args.slice(0,1)){ 
    140                             case "{": case "'":  case "[":  case '"': 
    141                                 break; 
    142                             default: 
    143                                 args = jsolait.repr(args); 
     110                jsolait.moduleSourceURIs['__main__']=fileName; 
     111                 
     112                jsolait.loadModule('__main__', function(modl, err){ 
     113                    if(err){ 
     114                        finishedCB(err); 
     115                    }else{ 
     116                        try{ 
     117                            var tmain =typeof(modl.__main__); 
     118                        }catch(e){ 
     119                            var tmain=""; 
    144120                        } 
    145                         f=new Function( "return " + args); 
    146                         args = [f()]; 
    147                     }else{ 
    148                         var args =[]; 
     121                         
     122                        if(tmain=='function'){ 
     123                            //todo find arguments 
     124                            if(WScript.arguments.named.exists("script-args")){ 
     125                                var args = WScript.arguments.named.Item("script-args"); 
     126                                switch(args.slice(0,1)){ 
     127                                    case "{": case "'":  case "[":  case '"': 
     128                                        break; 
     129                                    default: 
     130                                        args = jsolait.repr(args); 
     131                                } 
     132                                f=new Function( "return " + args); 
     133                                args = [f()]; 
     134                            }else{ 
     135                                var args =[]; 
     136                            } 
     137                             
     138                            try{ 
     139                                modl.__main__.apply(modl, args); 
     140                                finishedCB(null); 
     141                            }catch(e){ 
     142                                finishedCB( new mod.Exception("runing %s  __main__()  failed\n".format(modl),e)); 
     143                            } 
     144                        } 
    149145                    } 
    150                      
    151                     try{ 
    152                         modl.__main__.apply(modl, args); 
    153                     }catch(e){ 
    154                         throw new mod.Exception("runing %s  __main__()  failed\n".format(modl),e) 
    155                     } 
    156                 } 
    157                  
     146                });  
    158147            } 
    159148        }; 
    160149    }); 
    161150 
    162     try{ 
    163         jsolait.loadModule("jsolaitws").run(); 
     151    try{    
     152        jsolait.loadModule("jsolaitws", function(jsolaitws,err){ 
     153            jsolaitws.run( function(err){ 
     154                if(err){ 
     155                    WScript.Echo(''+err); 
     156                } 
     157             
     158            }); 
     159        }); 
    164160    }catch(e){ 
    165         WScript.echo(""+e); 
     161         
    166162    } 
    167163        
  • branches/experimental/jsolait/lib/codecs.js

    r73 r77  
    2828    @lastchangeddate    $Date$ 
    2929*/ 
    30 mod.__version__ = "$Revision$"; 
     30__version__ = "$Revision$"; 
    3131/** 
    3232    Returns all all available encoders. 
    3333    @return  An array of encoder names. 
    3434**/ 
    35 mod.listEncoders=function(){ 
     35def listEncoders(){ 
    3636    var c=[]; 
    3737    for(var attr in String.prototype){ 
     
    4646    @return  An array of decoder names. 
    4747**/ 
    48 mod.listDecoders=function(){ 
     48def listDecoders(){ 
    4949    var c=[]; 
    5050    for(var attr in String.prototype){ 
  • branches/experimental/jsolait/lib/crypto.js

    r73 r77  
    2727    @lastchangeddate    $Date$ 
    2828*/ 
    29 mod.__version__="$Revision$"; 
     29__version__="$Revision$"; 
    3030/** 
    3131    Returns all all available encrypters. 
    3232    @return  An array of encrypters names. 
    3333**/ 
    34 mod.listEncrypters=function(){ 
     34def listEncrypters(){ 
    3535    var c=[]; 
    3636    for(var attr in String.prototype){ 
     
    4545    @return  An array of decrypters names. 
    4646**/ 
    47 mod.listDecrypters=function(){ 
     47def listDecrypters(){ 
    4848    var c=[]; 
    4949    for(var attr in String.prototype){ 
  • branches/experimental/jsolait/lib/dom.js

    r73 r77  
    2525    @lastchangeddate    $Date$ 
    2626**/ 
    27 mod.__version__="$Revision$"; 
     27__version__="$Revision$"; 
    2828 
    29 imprt("sets")
     29import sets
    3030 
    3131/** 
    3232    Event class. 
    3333**/ 
    34 mod.Event=Class(function(publ, supr)
    35     publ.__init__=function(type, target){ 
     34class Event(
     35    publ __init__(type, target){ 
    3636        this.type = type; 
    3737        this.target = target; 
    3838    }; 
    3939    ///The event type. 
    40     publ.type=null; 
     40    publ type=null; 
    4141    ///The target of the event 
    42     publ.target=null; 
     42    publ target=null; 
    4343}); 
    4444 
     
    4747    An EventTarget implementation. 
    4848**/ 
    49 mod.EventTarget =Class(function(publ, supr)
    50     publ.__init__=function(){ 
     49class EventTarget(
     50    publ __init__(){ 
    5151        this.eventListeners={}; 
    5252    }; 
     
    5555        @param evt The event to dispatch. 
    5656    **/ 
    57     publ.dispatchEvent = function(evt){ 
     57    publ dispatchEvent(evt){ 
    5858        if(this.eventListeners[evt.type]){ 
    5959            var l = this.eventListeners[evt.type].items; 
     
    7373        @param useCapture  todo: Not used yet. 
    7474    **/ 
    75     publ.addEventListener=function(evtType, listener, useCapture){ 
     75    publ addEventListener(evtType, listener, useCapture){ 
    7676        if(this.eventListeners[evtType]===undefined){ 
    7777            this.eventListeners[evtType] = new sets.Set(); 
     
    8787        @param useCapture  todo: Not used yet. 
    8888    **/ 
    89     publ.removeEventListener=function(evtType, listener, useCapture){ 
     89    publ removeEventListener(evtType, listener, useCapture){ 
    9090        if(this.eventListeners[evtType]){ 
    9191            this.eventListeners[evtType].discard(listener); 
     
    9898    It forwards all events to handler methods using the evt.type as the name for the method. 
    9999**/ 
    100 mod.EventListener=Class(function(publ)
     100class EventListener(
    101101    /** 
    102102        Handles events dispatched by an EventTarget. 
     
    104104        @param  evt  The event to handle. 
    105105    **/ 
    106     publ.handleEvent=function(evt){ 
     106    publ handleEvent(evt){ 
    107107        if(this['handleEvent_' +evt.type]){ 
    108108            this['handleEvent_' + evt.type](evt); 
     
    114114    A combination of an EventTarget and a EventListener. 
    115115**/ 
    116 mod.EventListenerTarget=Class(mod.EventTarget, mod.EventListener, function(publ, supr)
     116class EventListenerTarget extends EventTarget, EventListener(
    117117}); 
  • branches/experimental/jsolait/lib/forms.js

    r73 r77  
    2828**/ 
    2929 
    30 mod.__version__="$Revision$"; 
     30__version__="$Revision$"; 
     31 
     32import urllib; 
     33 
    3134/** 
    3235    A class that resembles the functionality of an HTML form. 
     
    3437    by accessing the element as a named property of the form object(formObj.elemName ...). 
    3538**/ 
    36 mod.Form=Class(function(publ, supr)
     39class Form(
    3740    ///Contains the form elements. 
    38     publ.elements=[]; 
     41    publ elements=[]; 
    3942    ///The URL to submit the form to. 
    40     publ.action=""; 
     43    publ action=""; 
    4144    ///The method to use for subitting the form(GET/POST) 
    42     publ.method="GET"; 
     45    publ method="GET"; 
    4346     
    4447    /** 
     
    4750        @param method="GET"  The method to use for submitting(GET, POST). 
    4851    **/ 
    49     publ.__init__=function(action, method){ 
     52    publ __init__(action, method){ 
    5053        this.elements=[]; 
    5154        this.action= (action==null)?"":action; 
     
    5962        @return The Element set. 
    6063    **/ 
    61     publ.set=function(name, value){ 
     64    publ set(name, value){ 
    6265        var f = null; 
    6366        for(var i=0;i<this.elements;i++){ 
     
    6871        } 
    6972        if(f == null){//add a new element 
    70             f = new mod.Element(name, value); 
     73            f = new Element(name, value); 
    7174            this.eleme