fix vexi.string
authorbrian <brian@brianweb.net>
Sat, 8 May 2004 04:21:06 +0000 (04:21 +0000)
committerbrian <brian@brianweb.net>
Sat, 8 May 2004 04:21:06 +0000 (04:21 +0000)
darcs-hash:20040508042106-24bed-5e482d2263c08db14fee9139b32464f8d6a67d68.gz

src/org/ibex/core/Ibex.java
src/org/ibex/js/JSScope.java

index 2b8c7aa..0a48c5f 100644 (file)
@@ -241,36 +241,59 @@ public final class Ibex extends JS.Cloneable {
     }
     
     public static final JSMath ibexMath = new JSMath() {
+            // FEATURE: find a cleaner way to do this
             private JS gs = new JSScope.Global();
             public Object get(Object key) throws JSExn {
                 //#switch(key)
-                case "isNaN": return gs.get("isNaN");
-                case "isFinite": return gs.get("isFinite");
-                case "NaN": return gs.get("NaN");
-                case "Infinity": return gs.get("Infinity");
+                case "isNaN": return METHOD;
+                case "isFinite": return METHOD;
+                case "NaN": return METHOD;
+                case "Infinity": return METHOD;
                 //#end
                 return super.get(key);
             }
-        };
+            public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+                //#switch(name)
+                case "isNaN": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "isFinite": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "NaN": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "Infinity": return gs.callMethod(name,a,b,c,rest,nargs);
+                //#end
+                return super.callMethod(name,a,b,c,rest,nargs);
+            }
+    };
 
     public static final JS ibexString = new JS() {
             private JS gs = new JSScope.Global();
-            public void put(Object key, Object val) { }
             public Object get(Object key) throws JSExn {
                 //#switch(key)
-                case "parseInt": return gs.get("parseInt");
-                case "parseFloat": return gs.get("parseFloat");
-                case "decodeURI": return gs.get("decodeURI");
-                case "decodeURIComponent": return gs.get("decodeURIComponent");
-                case "encodeURI": return gs.get("encodeURI");
-                case "encodeURIComponent": return gs.get("encodeURIComponent");
-                case "escape": return gs.get("escape");
-                case "unescape": return gs.get("unescape");
-                case "fromCharCode": return gs.get("stringFromCharCode");
+                case "parseInt": return METHOD;
+                case "parseFloat": return METHOD;
+                case "decodeURI": return METHOD;
+                case "decodeURIComponent": return METHOD;
+                case "encodeURI": return METHOD;
+                case "encodeURIComponent": return METHOD;
+                case "escape": return METHOD;
+                case "unescape": return METHOD;
+                case "fromCharCode": return METHOD;
                 //#end
-                return null;
+                return super.get(key);
+            }
+            public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+                //#switch(name)
+                case "parseInt": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "parseFloat": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "decodeURI": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "decodeURIComponent": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "encodeURI": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "encodeURIComponent": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "escape": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "unescape": return gs.callMethod(name,a,b,c,rest,nargs);
+                case "fromCharCode": return gs.callMethod(name,a,b,c,rest,nargs);
+                //#end
+                return super.callMethod(name,a,b,c,rest,nargs);
             }
-        };
+    };
 
     private class XMLHelper extends XML {
         private class Wrapper extends XML.Exn { public JSExn wrapee; public Wrapper(JSExn jse) { super(""); wrapee = jse; } }
index 675ddc7..f025b24 100644 (file)
@@ -43,6 +43,7 @@ public class JSScope extends JS {
             case "undefined": return null;
             case "stringFromCharCode": return METHOD;
             case "parseInt": return METHOD;
+            case "parseFloat": return METHOD;
             case "isNaN": return METHOD;
             case "isFinite": return METHOD;
             case "decodeURI": return METHOD;
@@ -51,7 +52,6 @@ public class JSScope extends JS {
             case "encodeURIComponent": return METHOD;
             case "escape": return METHOD;
             case "unescape": return METHOD;
-            case "parseInt": return METHOD;
             //#end
             return super.get(key);
         }
@@ -70,6 +70,7 @@ public class JSScope extends JS {
                 case 1: {
                     //#switch(method)
                     case "parseInt": return parseInt(a0, N(0));
+                    case "parseFloat": return parseFloat(a0);
                     case "isNaN": { double d = toDouble(a0); return d == d ? F : T; }
                     case "isFinite": { double d = toDouble(a0); return (d == d && !Double.isInfinite(d)) ? T : F; }
                     case "decodeURI": throw new JSExn("unimplemented");
@@ -91,9 +92,9 @@ public class JSScope extends JS {
             return super.callMethod(method, a0, a1, a2, rest, nargs);
         }
 
-        private Object parseInt(Object arg, Object r) {
+        private Object parseInt(Object arg, Object r) throws JSExn {
             int radix = JS.toInt(r);
-            String s = (String)arg;
+            String s = JS.toString(arg);
             int start = 0;
             int length = s.length();
             int sign = 1;
@@ -132,8 +133,8 @@ public class JSScope extends JS {
             return JS.N((long)sign*n);
         }
 
-        private Object parseFloat(Object arg) {
-            String s = (String)arg;
+        private Object parseFloat(Object arg) throws JSExn {
+            String s = JS.toString(arg);
             int start = 0;
             int length = s.length();
             while(start < length && Character.isWhitespace(s.charAt(0))) start++;