X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FTest.java;h=621e08dd6c980c487682a216e538b3fcb29ddbe2;hp=5c7055e9a5889a10e9d7b21a4d7fa2442486aa03;hb=14dcf4ac275ea25af9e7bb517e61a82d2b935d0d;hpb=ce791e4058158295bce9cf7b6698c2b565d571d7 diff --git a/src/org/ibex/js/Test.java b/src/org/ibex/js/Test.java index 5c7055e..621e08d 100644 --- a/src/org/ibex/js/Test.java +++ b/src/org/ibex/js/Test.java @@ -3,22 +3,58 @@ package org.ibex.js; import java.io.*; public class Test extends JS { + static JS.UnpauseCallback up = null; + static String action; + 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])); + JS f = JS.fromReader(args[0],1,new FileReader(args[0])); System.out.println(((JSFunction)f).dump()); - JSScope s = new JSScope(null); + JSScope s = new JSScope(new JSScope.Global()); s.put(JS.S("sys"),new Test()); f = JS.cloneWithNewParentScope(f,s); - JS ret = f.call(null,null,null,null,0); + //JS ret = f.call(null,null,null,null,0); + Interpreter i = new Interpreter((JSFunction)f, true, new Interpreter.JSArgs(f)); + JS ret = i.resume(); + while(up != null) { + JS.UnpauseCallback up = Test.up; Test.up = null; + if("throw".equals(action)) ret = up.unpause(new JSExn("this was thrown to a paused context")); + else if("bgget".equals(action)) ret = up.unpause(JS.S("I'm returning this from a get request")); + else { + System.out.println("got a background put " + action); + ret = up.unpause(); + } + } System.out.println("Script returned: " + JS.toString(ret)); } public JS get(JS key) throws JSExn { if(!JS.isString(key)) return null; if("print".equals(JS.toString(key))) return METHOD; + if("bgget".equals(JS.toString(key))) { + action = "bgget"; + try { + up = JS.pause(); + } catch(NotPauseableException e) { + throw new Error("should never happen"); + } + return null; + } return super.get(key); } + + public void put(JS key, JS val) throws JSExn { + if("bgput".equals(JS.toString(key))) { + action = JS.toString(val); + try { + up = JS.pause(); + } catch(NotPauseableException e) { + throw new Error("should never happen"); + } + return; + } + super.put(key,val); + } public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn { if(!JS.isString(method)) return null;