package org.ibex.js;
import java.io.*;
+import org.ibex.util.*;
-public class Test extends JS {
- static JS.UnpauseCallback up = null;
+public class Test extends JS.Obj {
+ private static final JS.Method METHOD = new JS.Method();
static String action;
public static void main(String[] args) throws Exception {
s.put(JS.S("sys"),new Test());
f = JS.cloneWithNewGlobalScope(f,s);
//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"));
+ 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 {
System.out.println("got a background put " + action);
- ret = up.unpause();
+ ret = (JS)i.run(null);
}
- }
- System.out.println("Script returned: " + JS.toString(ret));
+ } } catch (Pausable.AlreadyRunningException e) {}
+ System.out.println("Script returned: " + Script.toString(ret));
}
public JS get(JS key) throws JSExn {
- if(!JS.isString(key)) return null;
- if("print".equals(JS.toString(key))) return METHOD;
- if("clone".equals(JS.toString(key))) return METHOD;
- if("firethis".equals(JS.toString(key))) return METHOD;
- if("bgget".equals(JS.toString(key))) {
+ 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))) {
action = "bgget";
try {
- up = JS.pause();
- } catch(NotPauseableException e) {
+ Script.pause();
+ } catch(Pausable.NotPausableException e) {
throw new Error("should never happen");
}
return null;
if("bgput".equals(JS.toString(key))) {
action = JS.toString(val);
try {
- up = JS.pause();
- } catch(NotPauseableException e) {
+ Script.pause();
+ } catch(Pausable.NotPausableException e) {
throw new Error("should never happen");
}
return;