X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FTest.java;h=8c06220599e081720ba2a85c9102395eb3783f33;hp=9598db48b8c2b5a865621f68a7295d231dc73de1;hb=a1e6b7e9307319c0195b0efbe5e5354c128be481;hpb=f637057f12669bb9fe8d76a72e0bfcc898dc0715 diff --git a/src/org/ibex/js/Test.java b/src/org/ibex/js/Test.java index 9598db4..8c06220 100644 --- a/src/org/ibex/js/Test.java +++ b/src/org/ibex/js/Test.java @@ -13,34 +13,34 @@ public class Test extends JS.Obj { public static void main(String[] args) throws Exception { if(args.length == 0) { System.err.println("Usage Test filename"); System.exit(1); } - JS f = Script.fromReader(args[0],1,new FileReader(args[0])); + JS f = JSU.fromReader(args[0],1,new FileReader(args[0])); System.out.println(((JSFunction)f).dump()); JS s = new JS.Obj(); - s.put(Script.S("sys"),new Test()); - f = Script.cloneWithNewGlobalScope(f,s); + s.put(JSU.S("sys"),new Test()); + f = JSU.cloneWithNewGlobalScope(f,s); //JS ret = f.call(null,null,null,null,0); Interpreter i = new Interpreter((JSFunction)f, true, new JS[0]); JS ret = (JS)i.run(null); try { while(true) { if("throw".equals(action)) ret = (JS)i.run(new JSExn("this was thrown to a paused context")); - else if("bgget".equals(action)) ret = (JS)i.run(Script.S("I'm returning this from a get request")); + else if("bgget".equals(action)) ret = (JS)i.run(JSU.S("I'm returning this from a get request")); else { System.out.println("got a background put " + action); ret = (JS)i.run(null); } } } catch (Pausable.AlreadyRunningException e) {} - System.out.println("Script returned: " + Script.toString(ret)); + System.out.println("Script returned: " + JSU.toString(ret)); } public JS get(JS key) throws JSExn { - if(!Script.isString(key)) return null; - if("print".equals(Script.toString(key))) return METHOD; - if("clone".equals(Script.toString(key))) return METHOD; - if("firethis".equals(Script.toString(key))) return METHOD; - if("bgget".equals(Script.toString(key))) { + if(!JSU.isString(key)) return null; + if("print".equals(JSU.toString(key))) return METHOD; + if("clone".equals(JSU.toString(key))) return METHOD; + if("firethis".equals(JSU.toString(key))) return METHOD; + if("bgget".equals(JSU.toString(key))) { action = "bgget"; try { - Script.pause(); + JSU.pause(); } catch(Pausable.NotPausableException e) { throw new Error("should never happen"); } @@ -50,37 +50,37 @@ public class Test extends JS.Obj { } public void put(JS key, JS val) throws JSExn { - if("bgput".equals(Script.toString(key))) { - action = Script.toString(val); + if("bgput".equals(JSU.toString(key))) { + action = JSU.toString(val); try { - Script.pause(); + JSU.pause(); } catch(Pausable.NotPausableException e) { throw new Error("should never happen"); } return; } - if("exit".equals(Script.toString(key))) { - System.exit(Script.toInt(val)); + if("exit".equals(JSU.toString(key))) { + System.exit(JSU.toInt(val)); return; } super.put(key,val); } public JS call(JS method, JS[] args) throws JSExn { - if(!Script.isString(method)) return null; - if("print".equals(Script.toString(method))) { - System.out.println(Script.str(args[0])); + if(!JSU.isString(method)) return null; + if("print".equals(JSU.toString(method))) { + System.out.println(JSU.str(args[0])); return null; } - if("clone".equals(Script.toString(method))) + if("clone".equals(JSU.toString(method))) return args.length < 1 || args[0] == null ? null : new JS.Clone(args[0]); - if("firethis".equals(Script.toString(method))) { - String action = Script.toString(args[0]); + if("firethis".equals(JSU.toString(method))) { + String action = JSU.toString(args[0]); JS target = args[1]; JS key = args[2]; if(action.equals("get")) return args[1].getAndTriggerTraps(key); - else if(action.equals("put")) args[1].putAndTriggerTraps(key,Script.S("some value")); - else if(action.equals("trigger")) return target.justTriggerTraps(key,Script.S("some trigger value")); + else if(action.equals("put")) args[1].putAndTriggerTraps(key,JSU.S("some value")); + else if(action.equals("trigger")) return target.justTriggerTraps(key,JSU.S("some trigger value")); return null; } return null;