org.ibex.js.Test
authorbrian <brian@brianweb.net>
Sat, 3 Jul 2004 11:04:08 +0000 (11:04 +0000)
committerbrian <brian@brianweb.net>
Sat, 3 Jul 2004 11:04:08 +0000 (11:04 +0000)
darcs-hash:20040703110408-24bed-f5a5ed687c03775328de9499a8ad3dc265ad2caf.gz

src/org/ibex/js/Test.java [new file with mode: 0644]

diff --git a/src/org/ibex/js/Test.java b/src/org/ibex/js/Test.java
new file mode 100644 (file)
index 0000000..92c6f95
--- /dev/null
@@ -0,0 +1,28 @@
+package org.ibex.js;
+
+import java.io.*;
+
+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]));
+        JSScope s = new JSScope(null);
+        s.put("sys",new Test());
+        f = JS.cloneWithNewParentScope(f,s);
+        Object 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;
+        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)) {
+            System.out.println(JS.toString(a0));
+            return null;
+        }
+        return null;
+    }
+}