org.ibex.js.Test
[org.ibex.core.git] / src / org / ibex / js / Test.java
1 package org.ibex.js;
2
3 import java.io.*;
4
5 public class Test extends JS {
6     public static void main(String[] args) throws Exception {
7         if(args.length == 0) { System.err.println("Usage Test filename"); System.exit(1); }
8         JS f = JS.fromReader(args[0],0,new FileReader(args[0]));
9         JSScope s = new JSScope(null);
10         s.put("sys",new Test());
11         f = JS.cloneWithNewParentScope(f,s);
12         Object ret = f.call(null,null,null,null,0);
13         System.out.println("Script returned: " + JS.toString(ret));
14     }
15     
16     public Object get(Object key) throws JSExn {
17         if("print".equals(key)) return METHOD;
18         return super.get(key);
19     }
20     
21     public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
22         if("print".equals(method)) {
23             System.out.println(JS.toString(a0));
24             return null;
25         }
26         return null;
27     }
28 }