5 public class Test extends JS {
6 static JS.UnpauseCallback up = null;
9 public static void main(String[] args) throws Exception {
10 if(args.length == 0) { System.err.println("Usage Test filename"); System.exit(1); }
11 JS f = JS.fromReader(args[0],1,new FileReader(args[0]));
12 System.out.println(((JSFunction)f).dump());
13 JSScope s = new JSScope(new JSScope.Global());
14 s.put(JS.S("sys"),new Test());
15 f = JS.cloneWithNewParentScope(f,s);
16 //JS ret = f.call(null,null,null,null,0);
17 Interpreter i = new Interpreter((JSFunction)f, true, new Interpreter.JSArgs(f));
20 JS.UnpauseCallback up = Test.up; Test.up = null;
21 if("throw".equals(action)) ret = up.unpause(new JSExn("this was thrown to a paused context"));
22 else if("bgget".equals(action)) ret = up.unpause(JS.S("I'm returning this from a get request"));
24 System.out.println("got a background put " + action);
28 System.out.println("Script returned: " + JS.toString(ret));
31 public JS get(JS key) throws JSExn {
32 if(!JS.isString(key)) return null;
33 if("print".equals(JS.toString(key))) return METHOD;
34 if("bgget".equals(JS.toString(key))) {
38 } catch(NotPauseableException e) {
39 throw new Error("should never happen");
43 return super.get(key);
46 public void put(JS key, JS val) throws JSExn {
47 if("bgput".equals(JS.toString(key))) {
48 action = JS.toString(val);
51 } catch(NotPauseableException e) {
52 throw new Error("should never happen");
59 public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
60 if(!JS.isString(method)) return null;
61 if("print".equals(JS.toString(method))) {
62 System.out.println(JS.toString(a0));