| 610 | | modPath = "%s%s.js".format(modPath, name.slice(1).join('/')); |
|---|
| 611 | | } |
|---|
| 612 | | try{//to load the source of the module |
|---|
| 613 | | src = mod.loadURI(modPath); |
|---|
| | 613 | if(mod.knownModuleURIs[name[0]] != undefined){ |
|---|
| | 614 | var uri = mod.knownModuleURIs[name[0]].format(mod); |
|---|
| | 615 | searchURIs.push("%s/%s.js".format(uri, name.slice(1).join('/'))); |
|---|
| | 616 | } |
|---|
| | 617 | searchURIs.push("%s/%s.js".format(mod.packagesURI.format(mod),name.join('/'))); |
|---|
| | 618 | } |
|---|
| | 619 | |
|---|
| | 620 | for(var i=0;i<mod.moduleSearchURIs.length; i++){ |
|---|
| | 621 | searchURIs.push("%s/%s.js".format(mod.moduleSearchURIs[i].format(mod), name.join("/"))); |
|---|
| | 622 | } |
|---|
| | 623 | name = name.join("."); |
|---|
| | 624 | } |
|---|
| | 625 | |
|---|
| | 626 | var failedURIs=[]; |
|---|
| | 627 | for(var i=0;i<searchURIs.length;i++){ |
|---|
| | 628 | try{ |
|---|
| | 629 | src = mod.loadURI(searchURIs[i]); |
|---|
| | 630 | break; |
|---|
| 619 | | if(src == null){//go through the search paths and try loading the module |
|---|
| 620 | | var failedURIs=[]; |
|---|
| 621 | | for(var i=0;i<mod.moduleSearchURIs.length; i++){ |
|---|
| 622 | | modPath = "%s/%s.js".format(mod.moduleSearchURIs[i].format(mod), name.join("/")); |
|---|
| 623 | | try{ |
|---|
| 624 | | src = mod.loadURI(modPath); |
|---|
| 625 | | break; |
|---|
| 626 | | }catch(e){ |
|---|
| 627 | | failedURIs.push(e.sourceURI); |
|---|
| 628 | | } |
|---|
| 629 | | } |
|---|
| 630 | | if(src == null){ |
|---|
| 631 | | throw new mod.ImportFailed(name.join('.'), failedURIs); |
|---|
| 632 | | } |
|---|
| 633 | | } |
|---|
| 634 | | |
|---|
| 635 | | try{//interpret the script |
|---|
| 636 | | var srcURI = src.__sourceURI__; |
|---|
| 637 | | src = 'Module.currentURI="%s";\n%s\nModule.currentURI=null;\n'.format(src.__sourceURI__.replace(/\\/g, '\\\\'), src); |
|---|
| 638 | | var f=new Function("",src); |
|---|
| 639 | | f(); |
|---|
| 640 | | }catch(e){ |
|---|
| 641 | | throw new mod.ImportFailed(name.join('.'), [srcURI], e); |
|---|
| 642 | | } |
|---|
| 643 | | |
|---|
| 644 | | return mod.modules[name.join('.')]; |
|---|
| | 636 | if(src == null){ |
|---|
| | 637 | throw new mod.ImportFailed(name, failedURIs); |
|---|
| | 638 | }else{ |
|---|
| | 639 | try{//interpret the script |
|---|
| | 640 | var srcURI = src.__sourceURI__; |
|---|
| | 641 | src = 'Module.currentURI="%s";\n%s\nModule.currentURI=null;\n'.format(src.__sourceURI__.replace(/\\/g, '\\\\'), src); |
|---|
| | 642 | var f=new Function("",src); |
|---|
| | 643 | f(); |
|---|
| | 644 | }catch(e){ |
|---|
| | 645 | throw new mod.ImportFailed(name, [srcURI], e); |
|---|
| | 646 | } |
|---|
| | 647 | |
|---|
| | 648 | if(mod.modules[name] != null){ |
|---|
| | 649 | return mod.modules[name]; |
|---|
| | 650 | }else{ |
|---|
| | 651 | throw new mod.ImportFailed(name, [srcURI], mod.Exception("Module did not register itself and cannot be imported. " + name)); |
|---|
| | 652 | } |
|---|
| | 653 | } |
|---|