Revision: 4296
          http://vexi.svn.sourceforge.net/vexi/?rev=4296&view=rev
Author:   mkpg2
Date:     2011-11-26 05:20:20 +0000 (Sat, 26 Nov 2011)
Log Message:
-----------
Refactor. Make JSU .java not .jpp for convenience.

Modified Paths:
--------------
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSMath.jpp

Added Paths:
-----------
    trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java

Removed Paths:
-------------
    trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp

Copied: trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java (from rev 
4279, trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp)
===================================================================
--- trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java                
                (rev 0)
+++ trunk/org.vexi-library.js/src/main/java/org/ibex/js/JSU.java        
2011-11-26 05:20:20 UTC (rev 4296)
@@ -0,0 +1,363 @@
+package org.ibex.js;
+
+import java.io.*;
+
+import org.ibex.js.JS.ConstructorList;
+import org.ibex.js.parse.*;
+import org.ibex.net.HTTP.*;
+import org.ibex.util.*;
+
+public class JSU implements Constants{
+    static public class Wrapper extends XML.Exn {
+       public JSExn wrapee;
+       public Wrapper(JSExn jse, XML xml) {
+               super("", 0, xml.getLine(), xml.getCol());
+               wrapee = jse;
+       }
+    }
+       
+
+    public static JS deepcopy(JS obj) throws JSExn{
+       if(obj==null) return obj;
+       else if(obj instanceof JS.Copyable){
+               return ((JS.Copyable)obj).deepcopy();
+       }else{
+               throw new JSExn("deepcopy not supported for: 
"+obj.getClass().getName());
+       }
+    }
+    ////////////////////
+    // CLONE stuff  
+    
+    // full unclone (unwraps all)
+    public static JS unclone(JS j) {
+       JS clone;
+       do {
+               clone = j;
+           j = clone.unclone();
+       } while(j!=clone);
+       return j;
+    }
+    
+    static public Fountain getFountain(JS j) {
+        while(j != null && j instanceof JS.Clone) j = j.unclone();
+        if (j != null && j instanceof Fountain) return ((Fountain)j);
+        return null;
+    }
+    
+    static public Fountain.HTTP getHTTPFountain(JS j) throws JSExn {
+       Fountain r = getFountain(j);
+       if(!(r instanceof Fountain.HTTP)) throw new JSExn("Expected http, got 
"+r);
+       return (Fountain.HTTP)r;
+    }
+    
+    static public InputStream getInputStream(JS js) throws IOException {
+       Fountain f = getFountain(js);
+       return (f!=null)?f.getInputStream():null;
+    }
+    
+    static public OutputStream getOutputStream(JS js) throws IOException { 
+       Fountain f = getFountain(js);
+       return (f!=null)?f.getOutputStream():null;
+    }
+    
+    // HACK - this is an unideal way to handle it, as it relies
+    // on everywhere that handles IOExceptions from fountains to
+    // call this...
+    static public JSExn handleFountainExn(IOException e) {
+       if(e instanceof HTTPErrorResponse) {
+               HTTPErrorResponse he = (HTTPErrorResponse)e;
+               JSExn je = new JSExn(e.getMessage(),SC_http);
+               Fountain.ByteArray stream = new Fountain.ByteArray(he.bytes);
+               JS.Obj jeObj = je.getObject();
+               jeObj.putSafe(SC_code,JSU.S(he.code));
+               jeObj.putSafe(SC_stream,stream);
+               String mimetype = he.info.contentType;
+               // remove ; charset ... (TODO - verify we have already taken 
this into account)
+               if(mimetype.indexOf(";")!=-1)
+                       mimetype = mimetype.substring(0,mimetype.indexOf(";"));
+               jeObj.putSafe(SC_mimetype, JSU.S(mimetype));
+               return je;
+       }
+       return new JSExn(e.getMessage(),e);
+    }
+
+    /** Coerce a JS object into a boolean. */
+    public static boolean toBoolean(JS o) { return isTruthy(o); }
+
+    static public int toInt(JS js) throws JSExn{ return JSMath.toInt(js); }
+    static public long toLong(JS js) throws JSExn{ return JSMath.toLong(js); }
+    static public double toDouble(JS js) throws JSExn{ return 
JSMath.toDouble(js); }
+    
+    
+    /** Coerce a JS object to a String. */
+    public static String toString(JS o) {
+        if(o == null) return "null";
+        return o.coerceToString();
+    }
+    public static String toString(Object o) {
+        if(o == null) return "null";
+        else if(o instanceof JS) return ((JS)o).coerceToString();
+        return 
o.getClass().getSimpleName()+"@"+Integer.toHexString(o.hashCode());
+    }
+
+    
+    public static boolean isInt(JS o) {
+        if(o == null) return true;
+        if(o instanceof JSNumber.I) return true;
+        if(o instanceof JSNumber) {
+            JSNumber n = (JSNumber) o;
+            return n.toInt() == n.toDouble();
+        }
+        if(o instanceof JSString) {
+            String s = ((JSString)o).s;
+            for(int i=0;i<s.length();i++)
+                if(s.charAt(i) < '0' || s.charAt(i) > '9') return false;
+            return s.length()>0;
+        }
+        return false;
+    }
+    
+    public static boolean isFraction(JS o) {
+        if(o instanceof JSNumber) {
+            return ((JSNumber)o).isFraction();
+        }else{
+            return false;
+        }
+    }
+    
+    public static boolean isString(JS o) {
+        if(o instanceof JSString) return true;
+        return false;
+    }
+    
+    static public JS constructorsOf(JS arg){
+       JSArray r = new JSArray();
+       if(!(arg instanceof JS.Obj)) return r;
+       for(ConstructorList l = ((JS.Obj)arg).constructors;l!=null;l=l.next){
+               r.add(l.value);
+       }
+       return r;
+    }
+    
+    // Instance Methods 
////////////////////////////////////////////////////////////////////
+    public final static JS MATH = new JSMath();
+    //public final static JS GLOBAL = new Scope.Global();    
+    
+    // TODO - move to Constants
+    public static final JS T = JSBoolean.TRUE;
+    public static final JS F = JSBoolean.FALSE;
+    
+    public static final JS B(boolean b) { return b ? T : F; }
+    public static final JS B(int i) { return i==0 ? F : T; }
+    
+    private static final int CACHE_SIZE = 65536 / 4; // must be a power of two
+    private static final JSString[] stringCache = new JSString[CACHE_SIZE];
+    public static final JS S(String s) {
+        if(s == null) return null;
+        int slot = s.hashCode()&(CACHE_SIZE-1);
+        JSString ret = stringCache[slot];
+        if(ret == null || !ret.s.equals(s)) stringCache[slot] = ret = new 
JSString(s);
+        return ret;
+    }
+    public static final JS S(String s, boolean intern) { return intern ? 
JSString.intern(s) : S(s); }
+
+    public static final JS N(double d) { return new JSNumber.D(d); }
+    public static final JS N(long l) { return new JSNumber.L(l); }
+    
+    public static final JS N(Number n) {
+        if(n instanceof Integer) return N(n.intValue());
+        if(n instanceof Long) return N(n.longValue());
+        return N(n.doubleValue());
+    }
+
+    private static final JSNumber.I negone = new JSNumber.I(-1);
+    private static final JSNumber.I[] icache = new JSNumber.I[128];
+    static { for (int i=0; i < icache.length; i++) icache[i] = new 
JSNumber.I(i); }
+    public static final JS N(int i) {
+        return i == -1 ? negone : i >= 0 && i < icache.length ? icache[i] : 
new JSNumber.I(i);
+    }
+
+    static public JSFunction cloneWithNewGlobalScope(Function f, JS s) {
+        return new JSFunction(f, new Scope.Top(s)); 
+    }
+    static public JSFunction cloneWithNewParentScope(Function f, Scope 
parentScope) {
+        return new JSFunction(f, parentScope); 
+    }
+
+    
+    static public JS stackframe(int fromtop){
+        Interpreter cx = Scheduler.findCurrent().findCurrentInterpreter();
+        // HACKish
+        String sfLine = cx.stack.stackframe(fromtop);
+        if(sfLine==null){
+            return null;
+        }else{
+            String[] sf = sfLine.split(":",2);
+            String source = sf[0];
+            String line = sf[1];
+            if(line.indexOf(' ')!=-1){
+                line = line.split(" ")[0];
+            }
+            JSArray r = new JSArray(2);
+            r.add(JSU.S(source));
+            r.add(JSU.S(line));
+            return r;
+        }
+    }
+    
+    static public final int NULL = 1;
+    static public final int OBJ = 2;
+    static public final int FOUNTAIN = 4;
+    static public final int NOTNULL = 6;
+    static public final int ANY = 7;
+    
+    //static public final int[] applyArgs = new int[]{OBJ|NULL,ARRAY};
+    // 6, 8 
+    static public JS[] checkApply(JS[] jsargs) throws JSExn{
+       if(jsargs.length<2) return JSU.EMPTY_JS_ARRAY;
+        if(!(jsargs[1] instanceof JSArrayLike)) throw new JSExn("Arg 2 should 
be an array");
+        return ((JSArrayLike)jsargs[1]).toArray();
+    }
+    
+    final static public void checkArgs(JS[] args, int[] types) throws JSExn{
+        if(args.length>types.length) throw new JSExn("Too many args, expected 
"+types.length+", got " + args.length);
+       for(int i=0; i<types.length; i++){
+            JS arg = i>=args.length?null:args[i]; 
+            int type = types[i];
+            
+            if(arg==null){ 
+                if((type & NULL)==0) throw new JSExn("Arg " + i + " cannot be 
null");
+                else continue;
+            }
+            switch(type & ~NULL){
+            case OBJ:
+                // TODO - check probably incomplete ...
+                if(arg instanceof JSPrimitive) throw new JSExn("Arg " + i + " 
should be a js object");
+                break;
+            case FOUNTAIN:  
+                if(getFountain(arg)==null) throw new JSExn("Arg " + i + " 
should be a FOUNTAIN");
+                break;
+            default:
+            }
+        }
+    }
+    
+    static public JS expectArg(JS[] args, int index) throws JSExn { 
+        if(args.length<=index) throw new JSExn("Expected argument 
["+index+"]");
+        return args[index];
+    }
+    static public JS getArg(JS[] args, int index) { return getArg(args, index, 
null); }
+    static public JS getArg(JS[] args, int index, JS default_) {
+        if(args.length<=index) return default_;
+        return args[index];
+    }
+    static public int expectArg_int(JS[] args, int index) throws JSExn {
+        JS js = getArg(args, index);
+        if(isInt(js)) return toInt(js);
+        throw new JSExn("Arg "+index+" is not an integer: "+js.toString());
+    }
+    static public int getArg_int(JS[] args, int index, int default_) throws 
JSExn {
+        JS js = getArg(args, index);
+        if(js==null) return default_;
+        return expectArg_int(args, index);
+    }
+    
+    /** lets us put multi-level get/put/call keys all in the same method */
+    static public class Sub extends JS.Obj {
+        final JS main;
+        final JS key;
+        public Sub(JS main, JS key) { 
+               this.main = main;
+               this.key = key; 
+        }
+        public void put(JS key, JS val) throws JSExn {
+               main.put(JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(key)), val);
+        }
+        public JS get(JS key) throws JSExn {
+            return main.get(JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(key)));
+        }
+        public JS callMethod(JS this_, JS method, JS[] args) throws JSExn {
+            return main.callMethod(this_, JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(method)), args);
+        }
+    }
+    
+
+    
+    ///////
+    // DEBUG (consider moving to DevUtil in src_dev)
+    ///
+    public static String opName(int op){
+        if (op < 0) return ByteCodes.bytecodeToString[-op];
+        else return Tokens.codeToString[op];
+    }
+
+    
+    static public Basket.List backtrace(){
+       return new JSExn("").backtrace;
+    }
+    
+    static private boolean xor(boolean a, boolean b){
+        return a && !b || !a && b;
+    }
+    
+    static private boolean isPrimitive(JS a){
+        return a==null || a instanceof JSPrimitive;
+    }
+    static public boolean isTruthy(JS o){
+        if(o==null) return false;
+        return o.isTruthy();
+    }
+    
+    
+    static public boolean coerceEquals(JS a, JS b){
+        if(a==b) return true;
+        if(a==null || b==null) return false;
+            
+        if(isPrimitive(a) && isPrimitive(b)){
+            
+            boolean numA = a instanceof JSNumber;
+            boolean numB = b instanceof JSNumber;
+            if (xor(numA,numB)){
+                if(numB){
+                    JS s = a;
+                    a = b;
+                    b = s;
+                }
+                JSNumber n = (JSNumber)a;
+                if(b instanceof JSBoolean)
+                    return n.toInt()==((JSBoolean)b).toInt();
+                // string
+                String s = ((JSString)b).toString();
+                try {
+                    if (n instanceof JSNumber.D || s.indexOf('.') != -1) {
+                        return Double.parseDouble(s) == n.toDouble();
+                    }
+                    return Long.parseLong(s) == n.toLong();
+                } catch (NumberFormatException e) {
+                    return false;
+                }
+            }
+            
+//            boolean boolA = a instanceof JSBoolean;
+//            boolean boolB = b instanceof JSBoolean;
+//            if (xor(boolA,boolB)){
+//                if(boolB){
+//                    JS s = a;
+//                    a = b;
+//                    b = s;
+//                }
+//                boolean bool = ((JSBoolean)a).b;
+//                if(!bool){
+//                    return "".equals(((JSString)b).s);   
+//                }
+//                return false;
+//            }
+        }
+        return a.equals(b);
+    }
+    
+    static public JS hashOf(JS js) {
+        if(js==null) return null;
+        return JSU.S( Integer.toHexString(js.hashCode()));
+    }
+}

Modified: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSMath.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSMath.jpp       
2011-11-24 07:43:49 UTC (rev 4295)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSMath.jpp       
2011-11-26 05:20:20 UTC (rev 4296)
@@ -85,4 +85,22 @@
         //#end
         return super.get(key);
     }
+    
+    //#repeat long/int/double toLong/toInt/toDouble Long/Integer/Double 
parseLong/parseInt/parseDouble
+    /** Coerce a JS object to a long. */
+    public static long toLong(JS o) throws JSExn {
+        if(o == null) return 0;
+        if(o instanceof JSNumber) return ((JSNumber)o).toLong();
+        if(o instanceof JSString) {
+            try {
+                return Long.parseLong(o.coerceToString());
+            } catch (NumberFormatException nfe) {
+                throw new JSExn("This string is not a number: 
\""+o.coerceToString()+'"');
+            }
+        }
+        if(o instanceof JSDecimal) return ((JSDecimal)o).toLong();
+        if(o instanceof JSBoolean) return ((JSBoolean)o).toLong();
+        throw new JSExn("Can not coerce a " + o.getClass().getName() + " to a 
number");
+    }
+    //#end
 }

Deleted: trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp
===================================================================
--- trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp  2011-11-24 
07:43:49 UTC (rev 4295)
+++ trunk/org.vexi-library.js/src/main/jpp/org/ibex/js/JSU.jpp  2011-11-26 
05:20:20 UTC (rev 4296)
@@ -1,367 +0,0 @@
-package org.ibex.js;
-
-import java.io.*;
-
-import org.ibex.js.JS.ConstructorList;
-import org.ibex.js.parse.*;
-import org.ibex.net.HTTP.*;
-import org.ibex.util.*;
-
-public class JSU implements Constants{
-    static public class Wrapper extends XML.Exn {
-       public JSExn wrapee;
-       public Wrapper(JSExn jse, XML xml) {
-               super("", 0, xml.getLine(), xml.getCol());
-               wrapee = jse;
-       }
-    }
-       
-
-    public static JS deepcopy(JS obj) throws JSExn{
-       if(obj==null) return obj;
-       else if(obj instanceof JS.Copyable){
-               return ((JS.Copyable)obj).deepcopy();
-       }else{
-               throw new JSExn("deepcopy not supported for: 
"+obj.getClass().getName());
-       }
-    }
-    ////////////////////
-    // CLONE stuff  
-    
-    // full unclone (unwraps all)
-    public static JS unclone(JS j) {
-       JS clone;
-       do {
-               clone = j;
-           j = clone.unclone();
-       } while(j!=clone);
-       return j;
-    }
-    
-    static public Fountain getFountain(JS j) {
-        while(j != null && j instanceof JS.Clone) j = j.unclone();
-        if (j != null && j instanceof Fountain) return ((Fountain)j);
-        return null;
-    }
-    
-    static public Fountain.HTTP getHTTPFountain(JS j) throws JSExn {
-       Fountain r = getFountain(j);
-       if(!(r instanceof Fountain.HTTP)) throw new JSExn("Expected http, got 
"+r);
-       return (Fountain.HTTP)r;
-    }
-    
-    static public InputStream getInputStream(JS js) throws IOException {
-       Fountain f = getFountain(js);
-       return (f!=null)?f.getInputStream():null;
-    }
-    
-    static public OutputStream getOutputStream(JS js) throws IOException { 
-       Fountain f = getFountain(js);
-       return (f!=null)?f.getOutputStream():null;
-    }
-    
-    // HACK - this is an unideal way to handle it, as it relies
-    // on everywhere that handles IOExceptions from fountains to
-    // call this...
-    static public JSExn handleFountainExn(IOException e) {
-       if(e instanceof HTTPErrorResponse) {
-               HTTPErrorResponse he = (HTTPErrorResponse)e;
-               JSExn je = new JSExn(e.getMessage(),SC_http);
-               Fountain.ByteArray stream = new Fountain.ByteArray(he.bytes);
-               JS.Obj jeObj = je.getObject();
-               jeObj.putSafe(SC_code,JSU.S(he.code));
-               jeObj.putSafe(SC_stream,stream);
-               String mimetype = he.info.contentType;
-               // remove ; charset ... (TODO - verify we have already taken 
this into account)
-               if(mimetype.indexOf(";")!=-1)
-                       mimetype = mimetype.substring(0,mimetype.indexOf(";"));
-               jeObj.putSafe(SC_mimetype, JSU.S(mimetype));
-               return je;
-       }
-       return new JSExn(e.getMessage(),e);
-    }
-
-    /** Coerce a JS object into a boolean. */
-    public static boolean toBoolean(JS o) { return isTruthy(o); }
-
-    //#repeat long/int/double toLong/toInt/toDouble Long/Integer/Double 
parseLong/parseInt/parseDouble
-    /** Coerce a JS object to a long. */
-    public static long toLong(JS o) throws JSExn {
-        if(o == null) return 0;
-        if(o instanceof JSNumber) return ((JSNumber)o).toLong();
-        if(o instanceof JSString) {
-               try {
-                   return Long.parseLong(o.coerceToString());
-            } catch (NumberFormatException nfe) {
-                throw new JSExn("This string is not a number: 
\""+o.coerceToString()+'"');
-            }
-        }
-        if(o instanceof JSDecimal) return ((JSDecimal)o).toLong();
-        if(o instanceof JSBoolean) return ((JSBoolean)o).toLong();
-        throw new JSExn("Can not coerce a " + o.getClass().getName() + " to a 
number");
-    }
-    //#end
-    
-    /** Coerce a JS object to a String. */
-    public static String toString(JS o) {
-        if(o == null) return "null";
-        return o.coerceToString();
-    }
-    public static String toString(Object o) {
-        if(o == null) return "null";
-        else if(o instanceof JS) return ((JS)o).coerceToString();
-        return 
o.getClass().getSimpleName()+"@"+Integer.toHexString(o.hashCode());
-    }
-
-    
-    public static boolean isInt(JS o) {
-        if(o == null) return true;
-        if(o instanceof JSNumber.I) return true;
-        if(o instanceof JSNumber) {
-            JSNumber n = (JSNumber) o;
-            return n.toInt() == n.toDouble();
-        }
-        if(o instanceof JSString) {
-            String s = ((JSString)o).s;
-            for(int i=0;i<s.length();i++)
-                if(s.charAt(i) < '0' || s.charAt(i) > '9') return false;
-            return s.length()>0;
-        }
-        return false;
-    }
-    
-    public static boolean isFraction(JS o) {
-        if(o instanceof JSNumber) {
-            return ((JSNumber)o).isFraction();
-        }else{
-            return false;
-        }
-    }
-    
-    public static boolean isString(JS o) {
-        if(o instanceof JSString) return true;
-        return false;
-    }
-    
-    static public JS constructorsOf(JS arg){
-       JSArray r = new JSArray();
-       if(!(arg instanceof JS.Obj)) return r;
-       for(ConstructorList l = ((JS.Obj)arg).constructors;l!=null;l=l.next){
-               r.add(l.value);
-       }
-       return r;
-    }
-    
-    // Instance Methods 
////////////////////////////////////////////////////////////////////
-    public final static JS MATH = new JSMath();
-    //public final static JS GLOBAL = new Scope.Global();    
-    
-    // TODO - move to Constants
-    public static final JS T = JSBoolean.TRUE;
-    public static final JS F = JSBoolean.FALSE;
-    
-    public static final JS B(boolean b) { return b ? T : F; }
-    public static final JS B(int i) { return i==0 ? F : T; }
-    
-    private static final int CACHE_SIZE = 65536 / 4; // must be a power of two
-    private static final JSString[] stringCache = new JSString[CACHE_SIZE];
-    public static final JS S(String s) {
-        if(s == null) return null;
-        int slot = s.hashCode()&(CACHE_SIZE-1);
-        JSString ret = stringCache[slot];
-        if(ret == null || !ret.s.equals(s)) stringCache[slot] = ret = new 
JSString(s);
-        return ret;
-    }
-    public static final JS S(String s, boolean intern) { return intern ? 
JSString.intern(s) : S(s); }
-
-    public static final JS N(double d) { return new JSNumber.D(d); }
-    public static final JS N(long l) { return new JSNumber.L(l); }
-    
-    public static final JS N(Number n) {
-        if(n instanceof Integer) return N(n.intValue());
-        if(n instanceof Long) return N(n.longValue());
-        return N(n.doubleValue());
-    }
-
-    private static final JSNumber.I negone = new JSNumber.I(-1);
-    private static final JSNumber.I[] icache = new JSNumber.I[128];
-    static { for (int i=0; i < icache.length; i++) icache[i] = new 
JSNumber.I(i); }
-    public static final JS N(int i) {
-        return i == -1 ? negone : i >= 0 && i < icache.length ? icache[i] : 
new JSNumber.I(i);
-    }
-
-    static public JSFunction cloneWithNewGlobalScope(Function f, JS s) {
-        return new JSFunction(f, new Scope.Top(s)); 
-    }
-    static public JSFunction cloneWithNewParentScope(Function f, Scope 
parentScope) {
-        return new JSFunction(f, parentScope); 
-    }
-
-    
-    static public JS stackframe(int fromtop){
-        Interpreter cx = Scheduler.findCurrent().findCurrentInterpreter();
-        // HACKish
-        String sfLine = cx.stack.stackframe(fromtop);
-        if(sfLine==null){
-            return null;
-        }else{
-            String[] sf = sfLine.split(":",2);
-            String source = sf[0];
-            String line = sf[1];
-            if(line.indexOf(' ')!=-1){
-                line = line.split(" ")[0];
-            }
-            JSArray r = new JSArray(2);
-            r.add(JSU.S(source));
-            r.add(JSU.S(line));
-            return r;
-        }
-    }
-    
-    static public final int NULL = 1;
-    static public final int OBJ = 2;
-    static public final int FOUNTAIN = 4;
-    static public final int NOTNULL = 6;
-    static public final int ANY = 7;
-    
-    //static public final int[] applyArgs = new int[]{OBJ|NULL,ARRAY};
-    // 6, 8 
-    static public JS[] checkApply(JS[] jsargs) throws JSExn{
-       if(jsargs.length<2) return JSU.EMPTY_JS_ARRAY;
-        if(!(jsargs[1] instanceof JSArrayLike)) throw new JSExn("Arg 2 should 
be an array");
-        return ((JSArrayLike)jsargs[1]).toArray();
-    }
-    
-    final static public void checkArgs(JS[] args, int[] types) throws JSExn{
-        if(args.length>types.length) throw new JSExn("Too many args, expected 
"+types.length+", got " + args.length);
-       for(int i=0; i<types.length; i++){
-            JS arg = i>=args.length?null:args[i]; 
-            int type = types[i];
-            
-            if(arg==null){ 
-                if((type & NULL)==0) throw new JSExn("Arg " + i + " cannot be 
null");
-                else continue;
-            }
-            switch(type & ~NULL){
-            case OBJ:
-                // TODO - check probably incomplete ...
-                if(arg instanceof JSPrimitive) throw new JSExn("Arg " + i + " 
should be a js object");
-                break;
-            case FOUNTAIN:  
-                if(getFountain(arg)==null) throw new JSExn("Arg " + i + " 
should be a FOUNTAIN");
-                break;
-            default:
-            }
-        }
-    }
-    
-    static public JS expectArg(JS[] args, int index) throws JSExn { 
-        if(args.length<=index) throw new JSExn("Expected argument 
["+index+"]");
-        return args[index];
-    }
-    static public JS getArg(JS[] args, int index) { return getArg(args, index, 
null); }
-    static public JS getArg(JS[] args, int index, JS default_) {
-        if(args.length<=index) return default_;
-        return args[index];
-    }
-
-    
-    /** lets us put multi-level get/put/call keys all in the same method */
-    static public class Sub extends JS.Obj {
-        final JS main;
-        final JS key;
-        public Sub(JS main, JS key) { 
-               this.main = main;
-               this.key = key; 
-        }
-        public void put(JS key, JS val) throws JSExn {
-               main.put(JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(key)), val);
-        }
-        public JS get(JS key) throws JSExn {
-            return main.get(JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(key)));
-        }
-        public JS callMethod(JS this_, JS method, JS[] args) throws JSExn {
-            return main.callMethod(this_, JSU.S(JSU.toString(this.key) + "." + 
JSU.toString(method)), args);
-        }
-    }
-    
-
-    
-    ///////
-    // DEBUG (consider moving to DevUtil in src_dev)
-    ///
-    public static String opName(int op){
-        if (op < 0) return ByteCodes.bytecodeToString[-op];
-        else return Tokens.codeToString[op];
-    }
-
-    
-    static public Basket.List backtrace(){
-       return new JSExn("").backtrace;
-    }
-    
-    static private boolean xor(boolean a, boolean b){
-        return a && !b || !a && b;
-    }
-    
-    static private boolean isPrimitive(JS a){
-        return a==null || a instanceof JSPrimitive;
-    }
-    static public boolean isTruthy(JS o){
-        if(o==null) return false;
-        return o.isTruthy();
-    }
-    
-    
-    static public boolean coerceEquals(JS a, JS b){
-        if(a==b) return true;
-        if(a==null || b==null) return false;
-            
-        if(isPrimitive(a) && isPrimitive(b)){
-            
-            boolean numA = a instanceof JSNumber;
-            boolean numB = b instanceof JSNumber;
-            if (xor(numA,numB)){
-                if(numB){
-                    JS s = a;
-                    a = b;
-                    b = s;
-                }
-                JSNumber n = (JSNumber)a;
-                if(b instanceof JSBoolean)
-                    return n.toInt()==((JSBoolean)b).toInt();
-                // string
-                String s = ((JSString)b).toString();
-                try {
-                    if (n instanceof JSNumber.D || s.indexOf('.') != -1) {
-                        return Double.parseDouble(s) == n.toDouble();
-                    }
-                    return Long.parseLong(s) == n.toLong();
-                } catch (NumberFormatException e) {
-                    return false;
-                }
-            }
-            
-//            boolean boolA = a instanceof JSBoolean;
-//            boolean boolB = b instanceof JSBoolean;
-//            if (xor(boolA,boolB)){
-//                if(boolB){
-//                    JS s = a;
-//                    a = b;
-//                    b = s;
-//                }
-//                boolean bool = ((JSBoolean)a).b;
-//                if(!bool){
-//                    return "".equals(((JSString)b).s);   
-//                }
-//                return false;
-//            }
-        }
-        return a.equals(b);
-    }
-    
-    static public JS hashOf(JS js) {
-        if(js==null) return null;
-        return JSU.S( Integer.toHexString(js.hashCode()));
-    }
-}

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


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to