- private static final JSFunction newBrowserWindow = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- if (args.length != 1 || args[0] == null) return null;
- Platform.newBrowserWindow(args[0].toString());
- return null;
- }
- };
-
- 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(), "");
- }
- };
-
- private static final JSFunction soap = new JSFunction() {
- public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
- if (args.length == 1 && args[0] != null) return new SOAP(args[0].toString(), "", null, null);
- else if (args.length == 2 && args[0] != null && args[1] != null)
- return new SOAP(args[0].toString(), "", args[1].toString(), null);
- else if (args.length == 3 && args[0] != null && args[1] != null && args[2] != null)
- return new SOAP(args[0].toString(), "", args[1].toString(), args[2].toString());
- else return null;
+ public Object callMethod(Object name, Object a, Object b, Object c, Object[] rest, int nargs) throws JSExn {
+ try {
+ //#switch(name)
+ case "date": return new JSDate(a, b, c, rest, nargs);
+ case "rpc.soap": return null;//new SOAP((String)a, "", (String)b, (String)c);
+ case "graft":
+ if (a instanceof Box) throw new JSExn("can't graft onto Boxes");
+ if (a instanceof String) throw new JSExn("can't graft onto Strings");
+ if (a instanceof Number) throw new JSExn("can't graft onto Numbers");
+ if (a instanceof Res) return new Res.Graft((Res)a, b, c);
+ // FEATURE: grafting onto JS
+ throw new JSExn("cannot graft onto "+a.getClass());
+ //#end
+
+ switch (nargs) {
+ case 0:
+ //#switch(name)
+ case "thread.yield": sleep(0); return null;
+ //#end
+ break;
+ case 1:
+ //#switch(name)
+ case "ui.browser": Platform.newBrowserWindow((String)a); return null;
+ case "clone": return new XWT((Res)a);
+ case "res.unzip": return new Res.Zip((Res)a);
+ case "res.uncab": return new Res.Cab((Res)a);
+ case "res.cache": try { return new Res.CachedRes((Res)a, "resources", true); }
+ catch (Res.NotCacheableException e) { throw new JSExn("this resource cannot be cached"); }
+ case "res.url": return url2res((String)a);
+ case "thread.sleep": sleep(JS.toInt(a)); return null;
+ case "log.print": Log.logJS(this, a== null ? "**null**" : a.toString()); return null;
+ case "log.println": Log.logJS(this, a== null ? "**null**" : a.toString()); return null;
+ case "log.dump": Log.recursiveLog("","",a); return null;
+ case "regexp": return new JSRegexp(a, null);
+ case "rpc.xml": return new XMLRPC((String)a, "");
+ case "crypto.rsa": /* FEATURE */ return null;
+ case "crypto.md5": /* FEATURE */ return null;
+ case "crypto.sha1": /* FEATURE */ return null;
+ case "crypto.rc4": /* FEATURE */ return null;
+ case "stream.parse.html": /* FEATURE */ return null;
+ case "stream.parse.xml": /* FEATURE */ return null;
+ case "stream.parse.utf8": /* FEATURE */ return null;
+ //#end
+ break;
+ case 2:
+ //#switch(name)
+ case "res.watch": return new Res.ProgressWatcher((Res)a, (JSFunction)b);
+ case "apply":
+ if (b instanceof Res) Template.getTemplate((Res)b).apply((Box)a, XWT.this);
+ else {
+ JS to = (JS)a, from = (JS)b; Object k;
+ for (Enumeration e = from.keys(); e.hasMoreElements();) {
+ k = e.nextElement(); to.put(k, from.get(k));
+ }
+ }
+ return a;
+ //#end
+ break;