PageRenderTime 46ms CodeModel.GetById 14ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 0ms

/javascript/src/test/resources/com/google/test/metric/javascript/browser_debug.js

http://testability-explorer.googlecode.com/
JavaScript | 156 lines | 100 code | 14 blank | 42 comment | 15 complexity | 255d461d28082557220353b2aa286d28 MD5 | raw file
  1/*
  2        Copyright (c) 2004-2005, The Dojo Foundation
  3        All Rights Reserved.
  4
  5        Licensed under the Academic Free License version 2.1 or above OR the
  6        modified BSD license. For more information on Dojo licensing, see:
  7
  8                http://dojotoolkit.org/community/licensing.shtml
  9*/
 10
 11dojo.hostenv.loadedUris.push("../src/bootstrap1.js");
 12dojo.hostenv.loadedUris.push("../src/hostenv_browser.js");
 13dojo.hostenv.loadedUris.push("../src/bootstrap2.js");
 14
 15function removeComments(contents){
 16        contents = new String((!contents) ? "" : contents);
 17        // clobber all comments
 18        contents = contents.replace( /^(.*?)\/\/(.*)$/mg , "$1");
 19        contents = contents.replace( /(\n)/mg , "__DOJONEWLINE");
 20        contents = contents.replace( /\/\*(.*?)\*\//g , "");
 21        return contents.replace( /__DOJONEWLINE/mg , "\n");
 22}
 23
 24dojo.hostenv.getRequiresAndProvides = function(contents){
 25        // FIXME: should probably memoize this!
 26        if(!contents){ return []; }
 27
 28        // check to see if we need to load anything else first. Ugg.
 29        var deps = [];
 30        var tmp;
 31        RegExp.lastIndex = 0;
 32        var testExp = /dojo.(hostenv.loadModule|hosetnv.require|require|requireIf|hostenv.conditionalLoadModule|hostenv.startPackage|hostenv.provide|provide)\([\w\W]*?\)/mg;
 33        while((tmp = testExp.exec(contents)) != null){
 34                deps.push(tmp[0]);
 35        }
 36        return deps;
 37}
 38
 39dojo.hostenv.getDelayRequiresAndProvides = function(contents){
 40        // FIXME: should probably memoize this!
 41        if(!contents){ return []; }
 42
 43        // check to see if we need to load anything else first. Ugg.
 44        var deps = [];
 45        var tmp;
 46        RegExp.lastIndex = 0;
 47        var testExp = /dojo.(requireAfterIf|requireAfter)\([\w\W]*?\)/mg;
 48        while((tmp = testExp.exec(contents)) != null){
 49                deps.push(tmp[0]);
 50        }
 51        return deps;
 52}
 53
 54/*
 55dojo.getNonExistantDescendants = function(objpath){
 56        var ret = [];
 57        // fast path for no periods
 58        if(typeof objpath != "string"){ return dj_global; }
 59        if(objpath.indexOf('.') == -1){
 60                if(dj_undef(objpath, dj_global)){
 61                        ret.push[objpath];
 62                }
 63                return ret;
 64        }
 65
 66        var syms = objpath.split(/\./);
 67        var obj = dj_global;
 68        for(var i=0;i<syms.length;++i){
 69                if(dj_undef(syms[i], obj)){
 70                        for(var j=i; j<syms.length; j++){
 71                                ret.push(syms.slice(0, j+1).join("."));
 72                        }
 73                        break;
 74                }
 75        }
 76        return ret;
 77}
 78*/
 79
 80dojo.clobberLastObject = function(objpath){
 81        if(objpath.indexOf('.') == -1){
 82                if(!dj_undef(objpath, dj_global)){
 83                        delete dj_global[objpath];
 84                }
 85                return true;
 86        }
 87
 88        var syms = objpath.split(/\./);
 89        var base = dojo.evalObjPath(syms.slice(0, -1).join("."), false);
 90        var child = syms[syms.length-1];
 91        if(!dj_undef(child, base)){
 92                // alert(objpath);
 93                delete base[child];
 94                return true;
 95        }
 96        return false;
 97}
 98
 99var removals = [];
100
101function zip(arr){
102        var ret = [];
103        var seen = {};
104        for(var x=0; x<arr.length; x++){
105                if(!seen[arr[x]]){
106                        ret.push(arr[x]);
107                        seen[arr[x]] = true;
108                }
109        }
110        return ret;
111}
112
113// over-write dj_eval to prevent actual loading of subsequent files
114var old_dj_eval = dj_eval;
115dj_eval = function(){ return true; }
116dojo.hostenv.oldLoadUri = dojo.hostenv.loadUri;
117dojo.hostenv.loadUri = function(uri){
118        if(dojo.hostenv.loadedUris[uri]){
119                return;
120        }
121        try{
122                var text = this.getText(uri, null, true);
123                var requires = dojo.hostenv.getRequiresAndProvides(text);
124                eval(requires.join(";"));
125                dojo.hostenv.loadedUris.push(uri);
126                dojo.hostenv.loadedUris[uri] = true;
127                var delayRequires = dojo.hostenv.getDelayRequiresAndProvides(text);
128                eval(delayRequires.join(";"));
129        }catch(e){
130                alert(e);
131        }
132        return true;
133}
134
135dojo.hostenv.writeIncludes = function(){
136        for(var x=removals.length-1; x>=0; x--){
137                dojo.clobberLastObject(removals[x]);
138        }
139        var depList = [];
140        var seen = {};
141        for(var x=0; x<dojo.hostenv.loadedUris.length; x++){
142                var curi = dojo.hostenv.loadedUris[x];
143                // dojo.debug(curi);
144                if(!seen[curi]){
145                        seen[curi] = true;
146                        depList.push(curi);
147                }
148        }
149
150        dojo.hostenv._global_omit_module_check = true;
151        for(var x=3; x<depList.length; x++){
152                document.write("<script type='text/javascript' src='"+depList[x]+"'></script>");
153        }
154        document.write("<script type='text/javascript'>dojo.hostenv._global_omit_module_check = false;</script>");
155        dj_eval = old_dj_eval;
156}