Revision: 1746
          http://svn.sourceforge.net/vexi/?rev=1746&view=rev
Author:   mkpg2
Date:     2007-03-23 03:40:27 -0700 (Fri, 23 Mar 2007)

Log Message:
-----------
Development - fetch variables.

Modified Paths:
--------------
    core/trunk/org.ibex.js/src_dev/org/ibex/js/RunJS.java
    core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/model.t
    core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/server.t
    core/trunk/org.vexi.devl/src/org/ibex/js/ScopeInfoManager.java
    core/trunk/org.vexi.devl/src/org/ibex/js/ThreadInfo.java
    core/trunk/org.vexi.devl/src/org/vexi/debug/DebugServer.java
    core/trunk/org.vexi.devl/src_junit/test/debug/TestDebugger.java
    core/trunk/org.vexi.devl/src_junit/test/debug/testclient.t
    core/trunk/org.vexi.devl/src_junit/test/debug/vars/TestVars.java
    core/trunk/org.vexi.devl/src_junit/test/debug/vars/main.t

Added Paths:
-----------
    core/trunk/org.vexi.devl/src_junit/org/
    core/trunk/org.vexi.devl/src_junit/org/ibex/
    core/trunk/org.vexi.devl/src_junit/org/ibex/js/
    core/trunk/org.vexi.devl/src_junit/org/ibex/js/TestObjTree.java
    core/trunk/org.vexi.devl/src_junit/org/ibex/js/obj.js
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/RunDebugee.java
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/TestProps.java
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/main.t
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testArray.t
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testNested.t
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObject.t
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObscured.t
    core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testStepping.t
    core/trunk/org.vexi.devl/src_junit/test/debug/vars/testVarsFromPrevious.t

Modified: core/trunk/org.ibex.js/src_dev/org/ibex/js/RunJS.java
===================================================================
--- core/trunk/org.ibex.js/src_dev/org/ibex/js/RunJS.java       2007-03-23 
10:37:35 UTC (rev 1745)
+++ core/trunk/org.ibex.js/src_dev/org/ibex/js/RunJS.java       2007-03-23 
10:40:27 UTC (rev 1746)
@@ -32,6 +32,10 @@
        
        boolean isRoot;
        
+       static public String[] pathFromClass(Class resourceLocator){
+               String resourceDir = resourceLocator.getResource(".").getPath();
+               return new String[]{resourceDir};
+       }
        
        public RunJS(String[]  jsPath){
                this(jsPath,new String[]{}, new JS[]{});
@@ -52,9 +56,8 @@
                this.sysObj = sysObj;
                isRoot = false;
        }
+
        
-       
-       
        static public void runJSFile(String[] jsPath, String filename) throws 
Exception{
                runJSFile(jsPath, filename, new String[]{}, new JS[]{});
        }

Modified: core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/model.t
===================================================================
--- core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/model.t       
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/model.t       
2007-03-23 10:40:27 UTC (rev 1746)
@@ -15,7 +15,13 @@
        // Position of currently broken. Null otherwise
        static.breakPosition; // {srcName: xxxx, ln: n}
 
+       ///////
+       // VARS
+       ///////
+       
        static.vars;
+       static.vars_threadid;  // Thread  ID of current vars
+       static.vars_callpos;   // Callpos ID of current vars
        
        ///////
        // THREADS

Modified: core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/server.t
===================================================================
--- core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/server.t      
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.debugclient/src/org/vexi/debugclient/core/server.t      
2007-03-23 10:40:27 UTC (rev 1746)
@@ -18,7 +18,11 @@
            model..currentThread = r.currentThread;
            if(r.sleepingThreads!=null) model..sleepingThreads = 
r.sleepingThreads;
            if(r.scheduledThreads!=null) model..scheduledThreads = 
r.scheduledThreads;
-           if(r.vars!=null)model..vars = r.vars;
+           if(r.vars!=null){
+               model..vars = r.vars;
+               model..vars_threadid = r.currentThread.id;
+               model..vars_callpos = -1;
+           }
        }
 
     static.start = function(serverFactory){
@@ -73,10 +77,10 @@
           var ret = getServer().quit();
         }      
        };
+
        ////////////
        // Breakpoints
-
-       
+       /* FIXME move these!
        static.loadBreakPoints = function(){    
                var bps = static.getBreakPoints();
                if(bps.length > 0){
@@ -121,7 +125,7 @@
                }else{
                        vexi.file.remove(vexi.biscuits.breakpoints);
                }
-       }
+       }*/
        
        static._setBreakPoint = function(srcName, ln){
                if(getServer().addBreakPoint(srcName, ln)){
@@ -144,7 +148,11 @@
        ////////
        // Fetch stuff
        ////////
-    static.getSource = function(name){
+    static.fetchSource = function(name){
+               // REMARK - the source does not form part of the model
+               // as there is little to be gained by doing this
+               // (just the source name) so view elements that need the
+               // current source file just fetch it using the name.
        var s = getServer().getSource(name);
        /*vexi.log.info("-------");
        vexi.log.info(s);
@@ -152,10 +160,27 @@
        return s;
     }
     
-       static.getBreakPoints = function(name){
-               // FEATURE cache return result
+       static.fetchBreakPoints = function(name){
+               // FIXME set model
         return getServer().getBreakPoints();
     }
        
+       static.fetchProps = function(path){
+               vexi.log.info(path.join(","));
+               var children = getServer().fetchProps(model..vars_threadid, 
model..vars_callpos, path);
+               vexi.log.info(children);
+               var obj = model..vars[path[0]];
+               for(var i=1; path.length>i; i++){
+                       for(var k in obj){
+                               vexi.log.info(k + ": " + obj[k]);
+                       };
+                       vexi.log.info(path[i]);
+                       obj = obj.value[path[i]];
+                       
+               }
+               obj.value=children;
+               
+    };
+       
    <ui:box/>
 </vexi>
\ No newline at end of file

Modified: core/trunk/org.vexi.devl/src/org/ibex/js/ScopeInfoManager.java
===================================================================
--- core/trunk/org.vexi.devl/src/org/ibex/js/ScopeInfoManager.java      
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src/org/ibex/js/ScopeInfoManager.java      
2007-03-23 10:40:27 UTC (rev 1746)
@@ -1,10 +1,13 @@
 package org.ibex.js;
 
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.Vector;
 
@@ -13,9 +16,189 @@
 import org.ibex.util.Log;
 import org.vexi.debug.MessagePasser.IMessagePart;
 
+/** A Tree */
+class ObjTree implements org.vexi.debug.Constants{
+       ObjTree(String name){ this.name = name;}
+       
+       String name;
+       Map children = new HashMap();
+       
+       ObjTree add(Vector v){return add(v, 0);}
+       private ObjTree add(Vector v, int depth){
+               if(depth>=v.size()) return this; 
+               String childsName = (String) v.get(depth);
+               ObjTree child = (ObjTree) children.get(childsName);
+               if(child==null){
+                       child = new ObjTree(childsName);
+                       children.put(childsName,child);
+               }
+               child.add(v,depth+1);
+               return null;
+       }
+
+       ObjTree get(Vector v){return get(v,0);}
+       private ObjTree get(Vector v, int depth){
+               if(depth>=v.size()) return this; 
+               String childsName = (String)v.get(depth);
+               ObjTree child = (ObjTree) children.get(childsName);
+               if(child!=null) return child.get(v, depth+1);
+               return null;
+       }
+       boolean contains(Vector v){return get(v,0)!=null;}
+       
+
+       
+       //////
+       // Construct XMLRPC message
+       /////
+       public Hashtable constructScope(Scope scope){
+               Hashtable r = new Hashtable();
+               if(scope == null)
+                       return r;
+
+               // Not necessarily all of the parent scope is visible. Search 
upto
+               // slot end.
+               int end = scope.base + scope.vars.length;
+               RTScopeInfo rtsi = RTScopeInfo.Map.get(scope);
+               //debugScopeInfo(rtsi);
+               for(int j=end-1; j>=0; j--){
+                       if(j<scope.base){
+                               scope = scope.parent;
+                               rtsi = RTScopeInfo.Map.get(scope);
+                       }
+                       //// Get the variable ///////
+                       JS var;
+                       try {
+                               var = scope.get(j);
+                       } catch (JSExn e1) {
+                               var = JSU.S(e1.getMessage());
+                               e1.printStackTrace();
+                       }
+                       ///// VAR NAME ///////
+                       ScopeInfo si = RTScopeInfo.Map.get(rtsi);
+                       String varname = 
ScopeInfoManager.reverseLookupScopeInfo(si, j);
+                       Hashtable h = constructJS(varname,"",var);
+                       //h.put("scopeDepth",new Integer(sd));
+                       r.put(varname, h);      
+               }
+               return r;
+       }
+
+       public Hashtable contructObjChildren(JS val) {
+               Hashtable ret = new Hashtable();
+               try {
+                       // list children
+                       JS.Enumeration E = val.keys().iterator();
+                       while(E.hasNext()){
+                               // Not necessarily a String!!
+                               JS jskey = E.next();
+                               String nametype;
+                               if(jskey instanceof JSNumber)
+                                       nametype = ":n";
+                               else
+                                       nametype = "";
+                               String name;
+                               try{
+                                 name = JSU.toString(jskey);
+                               }catch(JSExn jse){
+                  // Won't be possible for the client to return all the 
information to fetch in this case ..., but oh well.
+                                 name = "??";
+                               }
+                               // REMARK - is this type business necessary?
+                               // Unfortunately JS.Obj currently treats 
numbers and their
+                               // string representations differently ...
+                               String key = name + nametype;
+                               Hashtable h = constructJS(name, nametype, 
val.get(jskey));
+                               ret.put(key, h);
+                       }
+               } catch (JSExn e) {
+                       e.printStackTrace();
+                       throw new RuntimeException(e);
+               }
+               return ret;
+       }
+       
+       private Hashtable constructJS(String name, String nametype, JS jsvalue){
+               Hashtable h = new Hashtable();
+           h.put("name",name);
+           if(!"".equals(nametype))h.put("nametype",nametype);
+           String type = typeOfJS(jsvalue);
+           Object value = "";
+           try {
+               value = valueOfJS(jsvalue);
+        } catch (JSExn e) {
+                       e.printStackTrace();
+                       type = "debuggererror";
+                       value = e.getMessage();
+               }
+           h.put("type", type);
+           h.put("value",value);
+           if(type.equals(VARTYPE_OBJECT)){
+               Vector path = new Vector();
+               path.add(name);
+               ObjTree ot = get(path);
+               if(ot!=null) h.put("value", ot.contructObjChildren(jsvalue));
+           }
+           
+           //h.put("scopeDepth", new Integer(scopeDepth));
+           return h;
+       }
+       
+       private static String typeOfJS(JS jsvalue){
+               String type;
+           if(jsvalue == null){
+                       type = VARTYPE_NULL;
+               }else if(jsvalue instanceof JSPrimitive){
+            type = VARTYPE_PRIMITIVE;
+       }else if(jsvalue instanceof JS.Obj){
+                       type = VARTYPE_OBJECT;
+               }else if(jsvalue instanceof JSFunction){
+                       type = VARTYPE_FUNCTION;
+               }else{
+                       type = VARTYPE_UNKNOWN;
+               }
+           return type;
+       }
+       
+       private static Object valueOfJS(JS jsvalue) throws JSExn{
+           Object value = "";
+               if(jsvalue instanceof JSPrimitive){
+            if(jsvalue instanceof JSNumber){ 
+               if(JSU.isInt(jsvalue)){
+                       value = new Integer(JSU.toInt(jsvalue)); 
+               }else if(jsvalue instanceof JSNumber.B){
+                       value = new Boolean(JSU.toBoolean(jsvalue));
+               }else{
+                       value = new Double(JSU.toDouble(jsvalue));
+               }
+            }else{
+               value = JSU.toString(jsvalue);
+            }
+               }else if(jsvalue instanceof JSFunction){
+                       value = ((JSFunction)jsvalue).extendedToString();
+               }
+               return value;
+       }
+       
+}
+
 public class ScopeInfoManager implements org.vexi.debug.Constants{
        
+       /////
+       // MANAGE open paths (in variable view)
+       ////
+       static private Scope currentScope;
+    /**Currently open tree in the var view of the debugger client, 
+     * so we know to resend/update them when stepping through
+     * where possible*/
+       static ObjTree openPaths = new ObjTree(null);
        
+       static void setCurrentScope(Scope newScope){
+               // FEATURE could try harder to retain opened paths...
+               if(newScope!=currentScope)openPaths = new ObjTree(null);
+               currentScope = newScope;
+       }
+       
        /*
        private void debugScopeInfo(RuntimeScopeInfo rtsi){
                String sikey = 
scopeInfoKey(rtsi.f,getLastNEWSCOPE(rtsi.f,rtsi.pc));
@@ -34,17 +217,27 @@
                
        }*/
        
+       // FIXME - remove this?
        static public Object getVarInfo(int id, int callStackPos){
                ThreadInfo ti = ThreadInfo.getThreadInfo(id);
                Scope scope = (Scope) ti.getScope(callStackPos);
                return new VarMessage(scope).constructMessage();
        }
        
-       
+       static public Object getProps(int id, int callStackPos, Vector path) 
throws JSExn{
+               ThreadInfo ti = ThreadInfo.getThreadInfo(id);
+               Scope scope = (Scope) ti.getScope(callStackPos);
+               // TODO - remove first so we don't get any unwanted 
+               // expansions of the tree
+               openPaths.add(path);
+               JS var = descendToProp(scope, path);
+               return openPaths.get(path).contructObjChildren(var);
+       }
        static class VarMessage implements IMessagePart
        {  
                private Scope scope;
                VarMessage(Scope scope){
+                       setCurrentScope(this.scope);
                        this.scope = scope;
                        if(scope==null){
                                Log.warn(ScopeInfoManager.class, 
"constructVarMessage() - scope was null");
@@ -56,30 +249,12 @@
                 *    "value" -> variable value
                 *    "scopeDepth" -> variable scope depth */
                public Object constructMessage() {
-                       Vector v = new Vector();
+                       return openPaths.constructScope(scope);
+                       /*
+                       Hashtable r = new Hashtable();
                        if(scope == null)
-                               return v;
-                       /*
-                       for(int i=1; i<=sd; i++)
-                       {
-                               RuntimeScopeInfo rtsi = (RuntimeScopeInfo) 
scopeToRTSI.get(new Integer(i));
-                               String sikey = 
scopeInfoKey(rtsi.f,getLastNEWSCOPE(rtsi.f,rtsi.pc));
-                               System.out.println("sikey - " + sikey);
-                               ScopeInfo si = (ScopeInfo) 
scopeInfos.get(sikey);
-                               System.out.println("sinfo " + si.base + "->" + 
si.end);
-                               
-                       }
-                       
-                       for(int i=1; i<=sd; i++)
-                       {
-                               
-                               RuntimeScopeInfo rtsi = (RuntimeScopeInfo) 
scopeToRTSI.get(new Integer(i));
-                               System.out.println(rtsi.f.sourceName + ":" + 
rtsi.f.firstLine + ":" + rtsi.pc);
-                       }*/
+                               return r;
 
-                       
-                       
-
                        // Not necessarily all of the parent scope is visible. 
Search upto
                        // slot end.
                        int end = scope.base + scope.vars.length;
@@ -89,8 +264,6 @@
                                if(j<scope.base){
                                        scope = scope.parent;
                                        rtsi = RTScopeInfo.Map.get(scope);
-                                       //debugScopeInfo(rtsi);
-                                       //sd--; 
                                }
                                //// Get the variable ///////
                                JS var;
@@ -103,88 +276,64 @@
                                ///// VAR NAME ///////
                                ScopeInfo si = RTScopeInfo.Map.get(rtsi);
                                String varname = reverseLookupScopeInfo(si, j);
-                               Hashtable h = constructVar(varname,var);
+                               Hashtable h = constructVar(varname,var, scope);
                            //h.put("scopeDepth",new Integer(sd));
-                           v.add(h);   
+                           r.put(varname, h);  
                        }
-                       return v;
+                       return r;*/
                }
                public String fieldName() {
                        return "vars";
                }
+               
        }
-       
 
 
+       static JS descendToProp(Scope scope, Vector path) throws JSExn{ 
+               String rootName = (String)path.firstElement();
 
-
-       
-       Hashtable constructVarChildren(Hashtable pathObject, Scope scope) {
-               Hashtable ret = new Hashtable();
-               int sd = ((Integer) pathObject.get("scopeDepth")).intValue();
-               // Path in reverse order
-               Vector path = (Vector) pathObject.get("elements");
-               String rootName = (String)path.lastElement();
-               // Goto correct scope (incase vars overlap)
-               /*for(int i=0; i<this.sd-sd; i++){
-                       scope = scope.parent;
-               }*/
                // Use runtime scopeinfo to recover scopeinfo
                RTScopeInfo rtsi = RTScopeInfo.Map.get(scope);
-        // Uses scopeinfo to recover var index from varname
+               // Uses scopeinfo to recover var index from varname
                ScopeInfo si = RTScopeInfo.Map.get(rtsi);
                JSNumber.I jsi = (I) si.mapping.get(rootName);
-               
+
+               JS var = scope.get(jsi);
+
+               // get children of var 
+               for(int i=1; i<path.size(); i++){
+                       // <name>:<type> or <name> for a string
+                       String childkey =  (String)path.get(i);
+                       String[] strs = childkey.split(":");
+                       String value = strs[0];
+                       String type = strs.length>1?strs[1]:"";
+                       JS jskey;
+                       if("".equals(type) || "s".equals(type))
+                               jskey = JSU.S(value);
+                       else if("n".equals(type))
+                               jskey = JSU.N(new Double(value));
+                       else
+                               break;
+                       var = var.get(jskey); 
+               }
+               return var;
+       }
+       /*
+       static Hashtable constructObjChildren(Scope scope, Vector path) {
+               Hashtable ret = new Hashtable();
                try {
-            //Keep children sorted
-                       TreeSet children = new TreeSet(
-                               new Comparator(){
-                                       public int compare(Object arg1, Object 
arg2) {
-                                               Hashtable var1 = 
(Hashtable)arg1;
-                                               Hashtable var2 = 
(Hashtable)arg2;
-                                               String nametype1 = (String) 
var1.get("nametype");
-                                               String nametype2 = (String) 
var2.get("nametype");
-                                               String name1 = (String) 
var1.get("name");
-                                               String name2 = (String) 
var2.get("name");
-                                               int typecompare = 
nametype1.compareTo(nametype2);
-                                               if(typecompare!=0)
-                                                       return typecompare;
-                                               if(nametype1.equals("number"))
-                                               return 
Double.compare(Double.parseDouble(name1), Double.parseDouble(name2));
-                                               
-                                               return 
name1.compareTo((String)name2);
-                                       }       
-                               });
-                       JS var = scope.get(jsi);
-
-                       // get children of var 
-                       for(int i=path.size()-2; i>=0; i--){
-                               // <name>:<type>
-                               String childkey =  (String)path.get(i);
-                               String type = 
childkey.substring(childkey.indexOf(':')+1);
-                               String value = 
childkey.substring(0,childkey.indexOf(':'));
-                               JS jskey;
-                               if("string".equals(type))
-                                       jskey = JSU.S(value);
-                               else if("number".equals(type))
-                                       jskey = JSU.N(new Double(value));
-                               else
-                                       break;
-                               var = var.get(jskey); 
-                       }
-                               
+                       
+                       
                        // list children
-                       JS.Enumeration E = var.keys();
+                       JS.Enumeration E = var.keys().iterator();
                        while(E.hasNext()){
                                // Not necessarily a String!!
                                JS jskey = E.next();
                                String type;
-                               if(jskey instanceof JSString)
-                                 type = "string";
-                               else if(jskey instanceof JSNumber)
-                                 type = "number";
+                               if(jskey instanceof JSNumber)
+                                 type = ":n";
                                else
-                                 type = "other";
+                                 type = "";
                                String name;
                                try{
                                  name = JSU.toString(jskey);
@@ -192,54 +341,88 @@
                   // Won't be possible for the client to return all the 
information to fetch in this case ..., but oh well.
                                  name = "??";
                                }
-                               Hashtable h = 
constructVar(name,type,var.get(jskey));
-                               children.add(h);        
+                               Hashtable h = 
constructProp(name,type,var.get(jskey));
+                               // REMARK - is this type business necessary?
+                               // Unfortunately JS.Obj currently treats 
numbers and their
+                               // string representations differently ...
+                               ret.put(name + type, h);        
                        }
-                       
-                       
-                       ret.put("success", Boolean.TRUE);
-                       ret.put("children", new Vector(children));
                } catch (JSExn e) {
                        e.printStackTrace();
-                       ret.put("success", Boolean.FALSE);
-                       ret.put("error", e.getMessage());
+                       throw new RuntimeException(e);
                }
                return ret;
        }
-       private static Hashtable constructVar(String name, JS jsvalue){
-           return constructVar(name, "string", jsvalue);
+       private static String typeOfJS(JS jsvalue){
+               String type;
+           if(jsvalue == null){
+                       type = VARTYPE_NULL;
+               }else if(jsvalue instanceof JSPrimitive){
+            type = VARTYPE_PRIMITIVE;
+       }else if(jsvalue instanceof JS.Obj){
+                       type = VARTYPE_OBJECT;
+               }else if(jsvalue instanceof JSFunction){
+                       type = VARTYPE_FUNCTION;
+               }else{
+                       type = VARTYPE_UNKNOWN;
+               }
+           return type;
        }
-       private static Hashtable constructVar(String name, String nametype, JS 
jsvalue){
+       
+       private static Object valueOfJS(JS jsvalue) throws JSExn{
+           Object value = "";
+               if(jsvalue instanceof JSPrimitive){
+            if(jsvalue instanceof JSNumber){ 
+               if(JSU.isInt(jsvalue)){
+                       value = new Integer(JSU.toInt(jsvalue)); 
+               }else if(jsvalue instanceof JSNumber.B){
+                       value = new Boolean(JSU.toBoolean(jsvalue));
+               }else{
+                       value = new Double(JSU.toDouble(jsvalue));
+               }
+            }else{
+               value = JSU.toString(jsvalue);
+            }
+               }else if(jsvalue instanceof JSFunction){
+                       value = ((JSFunction)jsvalue).extendedToString();
+               }
+               return value;
+       }
+       
+       private static Hashtable constructVar(String name, JS jsvalue, Scope 
scope){
                Hashtable h = new Hashtable();
            h.put("name",name);
+           String type = typeOfJS(jsvalue);
+           Object value = "";
+           try {
+               value = valueOfJS(jsvalue);
+        } catch (JSExn e) {
+                       e.printStackTrace();
+                       type = "debuggererror";
+                       value = e.getMessage();
+               }
+           h.put("type", type);
+           h.put("value",value);
+           if(type.equals(VARTYPE_OBJECT)){
+               Vector path = new Vector();
+               path.add(name);
+               ObjTree ot = openPaths.get(path);
+               if(ot!=null) h.put("value", ot.contructObjChildren(jsvalue));
+           }
+           
+           //h.put("scopeDepth", new Integer(scopeDepth));
+           return h;
+       }
+       
+       static Hashtable constructProp(String name, String nametype, JS 
jsvalue){
+               Hashtable h = new Hashtable();
+           h.put("name",name);
            h.put("nametype", nametype);
-           String type;
+           String type = typeOfJS(jsvalue);
            Object value = "";
            try {
-            if(jsvalue == null){
-                               type = VARTYPE_NULL;
-                       }else if(jsvalue instanceof JSPrimitive){
-                type = VARTYPE_PRIMITIVE;
-                if(jsvalue instanceof JSNumber){ 
-                       if(JSU.isInt(jsvalue)){
-                               value = new Integer(JSU.toInt(jsvalue)); 
-                       }else if(jsvalue instanceof JSNumber.B){
-                               value = new Boolean(JSU.toBoolean(jsvalue));
-                       }else{
-                               value = new Double(JSU.toDouble(jsvalue));
-                       }
-                }else{
-                       value = JSU.toString(jsvalue);
-                }
-                       }else if(jsvalue instanceof JS.Obj){
-                               type = VARTYPE_OBJECT;
-                       }else if(jsvalue instanceof JSFunction){
-                               type = VARTYPE_FUNCTION;
-                               value = 
((JSFunction)jsvalue).extendedToString();
-                       }else{
-                               type = VARTYPE_UNKNOWN;
-                       }
-               } catch (JSExn e) {
+               value = valueOfJS(jsvalue);
+        } catch (JSExn e) {
                        e.printStackTrace();
                        type = "debuggererror";
                        value = e.getMessage();
@@ -247,13 +430,13 @@
            h.put("value",value);
            h.put("type", type);
            return h;
-       }
+       }*/
        
        
        
        
        // Returns key (name) from value (scopeslot)
-       static private String reverseLookupScopeInfo(ScopeInfo si, int slot){
+       static String reverseLookupScopeInfo(ScopeInfo si, int slot){
                Iterator I = si.mapping.keySet().iterator();
                while(I.hasNext()){
                        

Modified: core/trunk/org.vexi.devl/src/org/ibex/js/ThreadInfo.java
===================================================================
--- core/trunk/org.vexi.devl/src/org/ibex/js/ThreadInfo.java    2007-03-23 
10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src/org/ibex/js/ThreadInfo.java    2007-03-23 
10:40:27 UTC (rev 1746)
@@ -67,6 +67,7 @@
                }
 
                public Scope getScope(int callStackPos) {
+                       if(callStackPos==-1)callStackPos= callStack.size();
                        int relPos = callStackPos - basepos;
                        if(relPos<0) return parent.getScope(callStackPos);
                        else{

Modified: core/trunk/org.vexi.devl/src/org/vexi/debug/DebugServer.java
===================================================================
--- core/trunk/org.vexi.devl/src/org/vexi/debug/DebugServer.java        
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src/org/vexi/debug/DebugServer.java        
2007-03-23 10:40:27 UTC (rev 1746)
@@ -142,6 +142,10 @@
                return 
printResponse("getVarInfo",ScopeInfoManager.getVarInfo(threadId, callStackPos));
        }
        
+       public Object fetchProps(int threadId, int callStackPos, Vector path) 
throws Exception{
+               return 
printResponse("fetchProps",ScopeInfoManager.getProps(threadId, callStackPos, 
path));
+       }
+       
        public Hashtable getState(int stateCounter) throws Exception{
                try{
                        return (Hashtable) 
printResponse("getState",handler.msg.getState(stateCounter));

Added: core/trunk/org.vexi.devl/src_junit/org/ibex/js/TestObjTree.java
===================================================================
--- core/trunk/org.vexi.devl/src_junit/org/ibex/js/TestObjTree.java             
                (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/org/ibex/js/TestObjTree.java     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,58 @@
+package org.ibex.js;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import org.vexi.debug.DebugServer;
+
+import junit.framework.TestCase;
+
+public class TestObjTree extends TestCase implements org.vexi.debug.Constants {
+       
+       public static void main(String[] args) throws Throwable {
+               new TestObjTree().testConstruct();
+       }
+       
+       
+       Vector a = new Vector();        {a.add("a");    }
+       Vector ab = new Vector();       {ab.add("a");   ab.add("b"); }
+       Vector abc = new Vector();      {abc.add("a");  abc.add("b"); 
abc.add("c");}
+       Vector xy = new Vector();       {xy.add("x");   xy.add("y"); }
+       static JS export = null;
+       static JS getExport() throws JSExn
+       {       if(export==null)
+                       export = new 
RunJS(RunJS.pathFromClass(TestObjTree.class)).getExport("obj.js");
+               return export;
+       }
+       public void testConstruct() throws JSExn{
+               JS obj = getExport().get(JSU.S("obj"));
+               JS obja = obj.get(JSU.S("a"));
+               // Check
+               assertEquals(JSU.S("bar"),obja.get(JSU.S("foo")));
+               //
+               ObjTree ot = new ObjTree(null);
+               ot.add(a);
+               Hashtable msg = ot.get(a).contructObjChildren(obja);
+               DebugServer.printResponse("", msg);
+               
assertEquals(VARTYPE_OBJECT,((Hashtable)msg.get("b")).get("type"));
+               assertEquals("bar",((Hashtable)msg.get("foo")).get("value"));
+
+       }
+       
+       public void testAdd(){
+               ObjTree ot = new ObjTree(null);
+               ot.add(ab);
+               assertTrue(ot.contains(ab));
+               assertTrue(ot.contains(a));
+               assertFalse(ot.contains(abc));
+       }
+       
+       public void testGet(){
+               ObjTree ot = new ObjTree(null);
+               ot.add(ab);
+               ObjTree c = ot.get(ab);
+               assertNull(ot.get(xy));
+               assertEquals("b",ot.get(ab).name);
+       }
+
+}

Added: core/trunk/org.vexi.devl/src_junit/org/ibex/js/obj.js
===================================================================
--- core/trunk/org.vexi.devl/src_junit/org/ibex/js/obj.js                       
        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/org/ibex/js/obj.js       2007-03-23 
10:40:27 UTC (rev 1746)
@@ -0,0 +1,3 @@
+
+sys.print("constructing obj");
+export.obj = {a:{b:{mumra:"rules"},foo:"bar"}};
\ No newline at end of file

Modified: core/trunk/org.vexi.devl/src_junit/test/debug/TestDebugger.java
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/TestDebugger.java     
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/TestDebugger.java     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -1,9 +1,14 @@
 package test.debug;
 
 
+import org.ibex.js.TestObjTree;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import test.debug.fetchprops.TestProps;
 import test.debug.simple.TestSimple;
+import test.debug.thread.TestThread;
+import test.debug.vars.TestVars;
 import test.js.JSTestSuite;
 
 
@@ -15,9 +20,11 @@
        
        public static Test suite() {
        TestSuite suite = new 
TestSuite(JSTestSuite.nameFromClass(TestDebugger.class));
-       suite.addTestSuite(TestSimple.class);
-       //suite.addTestSuite(TestThread.class);
-       //suite.addTestSuite(TestVars.class);
+       suite.addTest(TestSimple.suite());
+       suite.addTest(TestThread.suite());
+       suite.addTest(TestVars.suite());
+       suite.addTest(TestProps.suite());
+       suite.addTestSuite(TestObjTree.class);
        return suite;
     }
 }

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/RunDebugee.java
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/RunDebugee.java    
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/RunDebugee.java    
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,16 @@
+package test.debug.fetchprops;
+
+
+public class RunDebugee {
+
+       /**
+        * @param args
+        * @throws Exception 
+        */
+       public static void main(String[] args) throws Exception {
+               String path = RunDebugee.class.getResource(".").getPath();
+               org.vexi.devl.Main.main(new 
String[]{"-db","-dbclient=NONE",path,"main"});
+               
+       }
+
+}

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/TestProps.java
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/TestProps.java     
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/TestProps.java     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,27 @@
+package test.debug.fetchprops;
+
+import junit.framework.Test;
+import test.core.CoreTestSuite;
+import test.debug.DebuggerTestSuite;
+
+public class TestProps extends DebuggerTestSuite {
+
+       public TestProps() {
+               super(TestProps.class);
+       }
+       
+       // Main method to just execute client (so server can be manually 
executed
+       // as a debugable process.
+       public static void main(String[] args) throws Exception {
+               new TestProps().run("testObject");
+       }
+       
+       public static Test suite(){
+       return CoreTestSuite.suite(new TestProps());
+    }
+       
+       protected boolean filter(String name) {
+               return name.startsWith("testStepping");
+       }
+       
+}

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/main.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/main.t             
                (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/main.t     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,13 @@
+<vexi xmlns:ui="vexi://ui" >
+       
+       vexi.log.error("fetchprops -start");
+       var obj = { nestedobj: {x:1,y:{z:"c"}}, foo:"bar", mumra:1, nestedarr: 
["a","z"]};
+       var array = [3,2,1, {foo:"bar"}];
+       vexi.log.error("fetchprops - middle");
+       vexi.log.error("fetchprops - middle2");
+       {
+               var obj = {thundercat: "liono"};
+               vexi.log.error("fetchprops - end");
+       }
+       <ui:box/>
+</vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testArray.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testArray.t        
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testArray.t        
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,19 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 6);
+               tc..resume();tc..waitForHalt();
+               server..fetchProps(["array"]);
+               // Test first level
+               .util..assertEquals(3,model..vars.array.value["0:n"].value);
+               .util..assertEquals(2,model..vars.array.value["1:n"].value);
+               .util..assertEquals(1,model..vars.array.value["2:n"].value);
+
+               
+       };
+
+       <ui:box/>
+</vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testNested.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testNested.t       
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testNested.t       
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,21 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 6);
+               tc..resume();tc..waitForHalt();
+               server..fetchProps(["obj"]);
+               server..fetchProps(["obj","nestedobj"]);
+               server..fetchProps(["obj","nestedobj","y"]);
+               
.util..assertEquals(1,model..vars.obj.value.nestedobj.value.x.value);
+               
.util..assertEquals("c",model..vars.obj.value.nestedobj.value.y.value.z.value);
+
+               server..fetchProps(["array"]);          
+               server..fetchProps(["array","3:n"]);
+               
.util..assertEquals("bar",model..vars.array.value["3:n"].value.foo.value);
+       };
+
+       <ui:box/>
+</vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObject.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObject.t       
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObject.t       
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,16 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 6);
+               tc..resume();tc..waitForHalt();
+               server..fetchProps(["obj"]);
+               // Test first level
+               .util..assertEquals("bar",model..vars.obj.value.foo.value);
+               .util..assertEquals(1,model..vars.obj.value.mumra.value);
+       };
+
+       <ui:box/>
+</vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObscured.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObscured.t     
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testObscured.t     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,16 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 10);
+               tc..resume();tc..waitForHalt();
+               
+               server..fetchProps(["obj"]);
+               // Test first level
+               
.util..assertEquals("liono",model..vars.obj.value.thundercat.value);
+       };
+
+       <ui:box/>
+</vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testStepping.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testStepping.t     
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/fetchprops/testStepping.t     
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,17 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 6);
+               tc..resume();tc..waitForHalt();
+               server..fetchProps(["obj"]);
+               server..fetchProps(["obj","nestedobj"]);
+               tc..stepOver(); tc..waitForHalt();
+               
.util..assertEquals("object",model..vars.obj.value.nestedobj.type);
+               
.util..assertEquals(1,model..vars.obj.value.nestedobj.value.x.value);
+       };
+
+       <ui:box/>
+</vexi>

Modified: core/trunk/org.vexi.devl/src_junit/test/debug/testclient.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/testclient.t  2007-03-23 
10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/testclient.t  2007-03-23 
10:40:27 UTC (rev 1746)
@@ -115,23 +115,14 @@
        static.assertVar = function(name, val, vartype){
                if(vartype==null)vartype = "primitive";
                var vs = model..vars;
-               for(var i=0; vs.length>i; i++){
-                       if(vs[i].name==name){
-                               
if(val!=null).util..assertEquals(val,vs[i].value, "var " + name + " value 
incorrect");
-                               .util..assertEquals(vartype,vs[i].type, "var " 
+ name + " vartype incorrect");
-                               return;
-                       }
-               }
-               throw "No variable named " + name;
+               if(vs[name]==null) throw "No variable named " + name;
+               if(val!=null).util..assertEquals(val,vs[name].value, "var " + 
name + " value incorrect");
+               .util..assertEquals(vartype,vs[name].type, "var " + name + " 
vartype incorrect");
        };
 
        static.assertNoVar = function(name){
                var vs = model..vars;
-               for(var i=0; vs.length>i; i++){
-                       if(vs[i].name==name){
-                               throw "var " + name + " should not be defined";
-                       }
-               }
+               if(vs[name]!=null) throw "var " + name + " should not be 
defined";
        };
        
        <ui:box/>

Modified: core/trunk/org.vexi.devl/src_junit/test/debug/vars/TestVars.java
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/vars/TestVars.java    
2007-03-23 10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/vars/TestVars.java    
2007-03-23 10:40:27 UTC (rev 1746)
@@ -13,97 +13,15 @@
        // Main method to just execute client (so server can be manually 
executed
        // as a debugable process.
        public static void main(String[] args) throws Exception {
-               new TestVars().run("testVars");
+               new TestVars().run("testFetchProps");
        }
        
        public static Test suite(){
        return CoreTestSuite.suite(new TestVars());
     }
-       
-       ///////////
-       // TESTS
-       ////////
        /*
-       private void assertBeforeC(VarInfo vi){
-               
-               vi.assertVar("a",new Integer(1));
-               vi.assertVar("b","b");
-               vi.assertVar("c",null, VARTYPE_FUNCTION);
-               // FEATURE - don't display uninitialized/undeclared variables 
somehow
-               vi.assertVar("f", null); //tc.assertNoVar("f");
-               vi.assertNoVar("d");
-               vi.assertNoVar("e");
-       }
-       
-       private void assertInsideC(VarInfo vi){
-               vi.assertVar("a",new Integer(1));
-               vi.assertVar("b","b");
-               vi.assertVar("c",null, VARTYPE_FUNCTION);
-               vi.assertVar("d","d");
-       }
-       
-       public void testCallstack() throws Exception{
-               tc.waitForHalt();
-               tc.setBreakPoint("main", 9);
-               tc.resume();
-               tc.waitForHalt();
-               tc.assertCallStack(new String[]{"main:13","main:9"});
-               tc.resume();
-       }
-       
-       public void testVars() throws Exception{
-               tc.waitForHalt();
-               //
-
-               //tc.setBreakPoint("main", 17);
-               
-               // Test start 
-               tc.setBreakPoint("main", 12);
-               tc.resume();tc.waitForHalt();
-               VarInfo vi = tc.getVarInfo();
-               assertBeforeC(vi);
-               
-               
-               // Test within function
-               tc.setBreakPoint("main", 9);
-               tc.resume();tc.waitForHalt();
-               vi = tc.getVarInfo();
-               assertInsideC(vi);
-               
-               // Test later
-               tc.setBreakPoint("main", 21);
-               tc.resume();tc.waitForHalt();
-               vi = tc.getVarInfo();
-               vi.assertVar("a",new Integer(1));
-               vi.assertVar("b","b");
-               vi.assertVar("c",null, VARTYPE_FUNCTION);
-               vi.assertVar("f", new Integer(6));
-               
-               // Test in thread
-               tc.setBreakPoint("main", 17);
-               tc.resume();tc.waitForHalt();
-               vi = tc.getVarInfo();
-               vi.assertVar("a",new Integer(1));
-               vi.assertVar("b","b");
-               vi.assertVar("c",null, VARTYPE_FUNCTION);
-               vi.assertVar("e","e");
-               vi.assertNoVar("f");
-               
-               
-               tc.resume();tc.waitForStop();
-               
-       }
-       
-       public void testVarsFromPrevious() throws Exception{
-               tc.waitForHalt();
-               tc.setBreakPoint("main", 9);
-               tc.resume();tc.waitForHalt();
-               VarInfo vi = tc.getVarInfo(0);
-               assertBeforeC(vi);
-               vi = tc.getVarInfo(1);
-               assertInsideC(vi);
-               
-               tc.resume();tc.waitForStop();
+       protected boolean filter(String name) {
+               return name.startsWith("testFetchProps");
        }*/
-       
+
 }

Modified: core/trunk/org.vexi.devl/src_junit/test/debug/vars/main.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/vars/main.t   2007-03-23 
10:37:35 UTC (rev 1745)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/vars/main.t   2007-03-23 
10:40:27 UTC (rev 1746)
@@ -1,8 +1,8 @@
 <vexi xmlns:ui="vexi://ui" >
        
        vexi.log.info("vars test");
-       var a = 1;
-       var b = "b";
+       var obj = { nested: {x:1,y:2}, foo:"bar", mumra:1};
+       var a = 1;      var b = "b";
 
        var c = function(){
                var d = "d";
@@ -20,5 +20,10 @@
        var f = 6;
        vexi.log.info(a + "," + b + "," + f);
        
+       {
+               var obj = {a:"x",b:"y"};
+               vexi.log.info("blah");
+       }
+       
        <ui:box/>
 </vexi>

Added: core/trunk/org.vexi.devl/src_junit/test/debug/vars/testVarsFromPrevious.t
===================================================================
--- core/trunk/org.vexi.devl/src_junit/test/debug/vars/testVarsFromPrevious.t   
                        (rev 0)
+++ core/trunk/org.vexi.devl/src_junit/test/debug/vars/testVarsFromPrevious.t   
2007-03-23 10:40:27 UTC (rev 1746)
@@ -0,0 +1,19 @@
+<vexi xmlns:ui="vexi://ui" xmlns:tc="testclient"
+         xmlns:model="org.vexi.debugclient.core.model"
+         xmlns:server="org.vexi.debugclient.core.server"
+         xmlns="">
+       static.runtest = function(){
+               tc..waitForHalt();
+               tc..setBreakPoint("main", 9);
+               tc..resume();tc..waitForHalt();
+               //server..fetchVarInfo(model..currentThread.id,0);
+               .shared..assertBeforeC();
+               //server..fetchVarInfo(model..currentThread.id,1);
+               .shared..assertInsideC();
+               
+               tc..resume();tc..waitForStop();
+               
+       };
+
+       <ui:box/>
+</vexi>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to