- private static final JSFunction yield = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- sleep.call(cx, null, null, null);
- return null;
- }
- };
-
- private static final JSFunction println = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- if (args.length == 1)
- if (Log.on)
- Log.log(cx.interpreterSourceFile, args[0] == null ? "null" : args[0].toString());
- return null;
- }
- };
-
- private static final JSFunction date = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Date", args);
- } catch (Exception e) {
- if (Log.on) Log.log(this, "Exception in Context.newObject() -- this should never happen");
- if (Log.on) Log.log(this, e);
- return null;
- }
- }
- };
-
- private static final JSFunction regexp = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Regexp", args);
- } catch (Exception e) {
- if (Log.on) Log.log(this, "Exception in Context.newObject() -- this should never happen");
- if (Log.on) Log.log(this, e);
- return null;
- }
- }
- };
-
- private static final JSFunction listfonts = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- return Context.enter().newArray(org.xwt.util.JSObject.defaultObjects, Platform.listFonts());
- }
- };
-
- private static final JSFunction theme = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- if (args.length != 2) return null;
- if (args[0] == null || args[1] == null) return null;
- Template.retheme(args[0].toString(), args[1].toString());
- return null;
- }
- };
-
- private static final JSFunction xmlrpc = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- if (args.length != 1 || args[0] == null) return null;
- return new XMLRPC(args[0].toString(), "");
+ public Object call(Object name, JSArray args) throws JS.Exn {
+ Object a = args.elementAt(0);
+ Object b = args.elementAt(1);
+ Object c = args.elementAt(2);
+ if (name.equals("date")) return new org.xwt.js.JSDate(args);
+ else if (args.length() == 0 && name.equals("thread.yield")) { sleep(0); return null; }
+ else if (args.length() == 2) {
+ //#switch(name)
+ case "res.watch": return new Res.ProgressWatcher((Res)a, (JSFunction)b);
+ case "soap": return new SOAP((String)args.elementAt(0), "", (String)args.elementAt(1), null);
+ case "apply":
+ Template.getTemplate((Res)args.elementAt(1)).apply((Box)args.elementAt(0), XWT.this);
+ return args.elementAt(0);
+ //#end
+ } else if (args.length() == 3 && name.equals("soap")) {
+ if (name.equals("soap")) {
+ return new SOAP((String)args.elementAt(0), "", (String)args.elementAt(1), (String)args.elementAt(2));
+ } else if (name.equals("graft")) {
+ if (a instanceof Box) throw new JS.Exn("can't graft onto Boxes (yet)");
+ if (a instanceof Number) throw new JS.Exn("can't graft onto Numbers (yet)");
+ if (a instanceof String) throw new JS.Exn("can't graft onto Strings (yet)");
+ if (a instanceof Res) return new Res.Graft((Res)a, b, c);
+ return new JS.Graft((JS)a, b, c);