new js api
[org.ibex.core.git] / src / org / ibex / js / Test.java
index 92c6f95..5c7055e 100644 (file)
@@ -6,20 +6,23 @@ public class Test extends JS {
     public static void main(String[] args) throws Exception {
         if(args.length == 0) { System.err.println("Usage Test filename"); System.exit(1); }
         JS f = JS.fromReader(args[0],0,new FileReader(args[0]));
+        System.out.println(((JSFunction)f).dump());
         JSScope s = new JSScope(null);
-        s.put("sys",new Test());
+        s.put(JS.S("sys"),new Test());
         f = JS.cloneWithNewParentScope(f,s);
-        Object ret = f.call(null,null,null,null,0);
+        JS ret = f.call(null,null,null,null,0);
         System.out.println("Script returned: " + JS.toString(ret));
     }
     
-    public Object get(Object key) throws JSExn {
-        if("print".equals(key)) return METHOD;
+    public JS get(JS key) throws JSExn {
+        if(!JS.isString(key)) return null;
+        if("print".equals(JS.toString(key))) return METHOD;
         return super.get(key);
     }
     
-    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
-        if("print".equals(method)) {
+    public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
+        if(!JS.isString(method)) return null;
+        if("print".equals(JS.toString(method))) {
             System.out.println(JS.toString(a0));
             return null;
         }