else return rr.get(name);
}
- public void put(Object name, Object value) {
- if (name.equals("thread") && value != null && value instanceof JS.Callable) ThreadMessage.newthread((JS.Callable)value);
- else if (name.equals("clipboard")) Platform.setClipBoard(value.toString());
+ public void put(Object name, final Object value) {
+ if (name.equals("thread") && value != null && (value instanceof JS.Callable || value instanceof JS.CompiledFunction)) {
+ Scheduler.add(new Scheduler.Task() { public Object call(Object arg) {
+ new JS.Thread((CompiledFunction)value).resume();
+ return null;
+ } });
+ } else if (name.equals("clipboard")) Platform.setClipBoard(value.toString());
+ else if (name.equals("frame")) Platform.createSurface((Box)value, true, true);
+ else if (name.equals("window")) Platform.createSurface((Box)value, false, true);
else if (name.equals("proxyAuthorization")) {
HTTP.Proxy.Authorization.authorization = value.toString();
HTTP.Proxy.Authorization.waitingForUser.release();
} else if (method.equals("watchProgress")) {
if (checkOnly) return Boolean.TRUE;
- return new Res.ProgressWatcher((Res)args.elementAt(0), (JS.Callable)args.elementAt(1));
+ return new Res.ProgressWatcher((Res)args.elementAt(0), (JS.CompiledFunction)args.elementAt(1));
} else if (method.equals("yield")) {
if (checkOnly) return Boolean.TRUE;
}
}
- public static void sleep(int i) {
- java.lang.Thread thread = java.lang.Thread.currentThread();
- if (!(thread instanceof ThreadMessage)) {
- if (Log.on) Log.log(XWT.class, "cannot sleep() or yield() in the foreground thread");
- } else {
- ThreadMessage mythread = (ThreadMessage)thread;
- mythread.done.release();
- if (i > 0) try { java.lang.Thread.sleep(i); } catch (Exception e) { }
- Message.Q.add(mythread);
- mythread.go.block();
- }
+ public static void sleep(final int i) {
+ final JS.Thread jsthread = JS.Thread.current();
+ final long currentTime = System.currentTimeMillis();
+ final Scheduler.Task task = new Scheduler.Task() { public Object call(Object arg) {
+ if (System.currentTimeMillis() - currentTime < i) {
+ Scheduler.add(this);
+ } else {
+ jsthread.resume();
+ }
+ return null;
+ } };
+ jsthread.pause();
+ Scheduler.add(task);
}
- private static class XWTMath extends JS.Obj {
+ private static class XWTMath extends org.xwt.js.Math {
public XWTMath() {
JS gs = new JS.GlobalScope();
put("isNaN",gs.get("isNaN"));