2002/10/03 23:40:09
[org.ibex.core.git] / src / org / xwt / XWT.java
1 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.xwt;
3
4 import java.io.*;
5 import java.net.*;
6 import java.text.*;
7 import java.util.*;
8 import org.xwt.util.*;
9 import org.mozilla.javascript.*;
10 import org.bouncycastle.util.encoders.Base64;
11
12 /** Singleton class that provides all functionality in the xwt.* namespace */
13 public final class XWT extends JSObject {
14
15     public static final XWT singleton = new XWT();
16
17     /** each key is a string representing a filename which the user has already given XWT permission to write to */
18     private static Hashtable safeFiles = new Hashtable();
19
20     public String getClassName() { return "XWT"; }
21     private XWT() { setSeal(true); }
22
23     public Object get(String name, Scriptable start) {
24         if (name == null) return null;
25         else if (name.equals("maxdim")) return new Integer(Short.MAX_VALUE);
26         else if (name.equals("parseFloat")) return JSObject.defaultObjects.get("parseFloat", null);
27         else if (name.equals("parseInt")) return JSObject.defaultObjects.get("parseInt", null);
28         else if (name.equals("alt")) return Surface.alt ? Boolean.TRUE : Boolean.FALSE;
29         else if (name.equals("control")) return Surface.control ? Boolean.TRUE : Boolean.FALSE;
30         else if (name.equals("shift")) return Surface.shift ? Boolean.TRUE : Boolean.FALSE;
31         else if (name.equals("date")) return date;
32         else if (name.equals("listfonts")) return listfonts;
33         else if (name.equals("regexp")) return regexp;
34         else if (name.equals("sleep")) return sleep;
35         else if (name.equals("yield")) return yield;
36         else if (name.equals("newBrowserWindow")) return newBrowserWindow;
37         else if (name.equals("textwidth")) return textwidth;
38         else if (name.equals("textheight")) return textheight;
39         else if (name.equals("newBox")) return newBox;
40         else if (name.equals("soap")) return soap;
41         else if (name.equals("xmlrpc")) return xmlrpc;
42         else if (name.equals("origin")) return Main.origin;
43         else if (name.equals("clipboard")) return Platform.getClipBoard();
44         else if (name.equals("altKeyName")) return Platform.altKeyName();
45         else if (name.equals("screenWidth")) return new Integer(Platform.getScreenWidth());
46         else if (name.equals("screenHeight")) return new Integer(Platform.getScreenHeight());
47         else if (name.equals("static")) return Static.getStatic("");
48         else if (name.equals("theme")) return theme;
49         else if (name.equals("openFile")) return openFile;
50         else if (name.equals("saveFile")) return saveFile;
51         else if (name.equals("saveFileAs")) return saveFileAs;
52         else if (name.equals("utfEncode")) return utfEncode;
53         else if (name.equals("fileSeparator")) return File.separator;
54         else if (name.equals("homeDir")) return System.getProperty("user.home");
55         else if (name.equals("tempDir")) return System.getProperty("java.io.tempdir");
56         else if (name.equals("recursivePrintObject")) return recursivePrintObject;
57         else if (name.equals("parseHTML")) return parseHTML;
58         else if (name.equals("button")) {
59             if (Surface.button1 && !Surface.button2 && !Surface.button3) return new Integer(1);
60             else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(1);
61             else if (!Surface.button1 && !Surface.button2 && Surface.button3) return new Integer(1);
62             else return new Integer(0);
63         }
64         else if (name.equals("println")) return println;
65         else if (name.equals("math")) return org.xwt.util.JSObject.defaultObjects.get("Math", null);
66         else if (name.equals("loadArchive")) return loadArchive;
67         else if (name.equals("prefetchImage")) return prefetchImage;
68         else if (name.equals("prefs")) return prefs;
69         else if (name.equals("encodeURI")) return JSObject.defaultObjects.get("encodeURI", null);
70         else if (name.equals("encodeURIComponent")) return JSObject.defaultObjects.get("encodeURIComponent", null);
71         else if (name.equals("decodeURI")) return JSObject.defaultObjects.get("decodeURI", null);
72         else if (name.equals("decodeURIComponent")) return JSObject.defaultObjects.get("decodeURIComponent", null);
73         else return super.get(name, start);
74     }
75
76     public void put(String name, Scriptable start, Object value) {
77         if (name == null) return;
78         else if (name.equals("thread") && value != null && value instanceof Function) ThreadMessage.newthread((Function)value);
79         else if (name.equals("clipboard")) Platform.setClipBoard(value.toString());
80
81         // FIXME: undocumented, possibly insecure
82         else if (name.equals("proxyAuthorization")) {
83             Proxy.Authorization.authorization = value.toString();
84             Proxy.Authorization.waitingForUser.release();
85         }
86
87         else super.put(name, start, value);
88     }
89
90
91     // Prefs Object //////////////////////////////////////////////////////////////////////////
92
93     static Scriptable prefsRPC = new XMLRPC("http://megacz:mypassword@localhost/RPC2", "prefs");
94
95     private static final JSObject prefs = new JSObject(false, true) {
96             public Object get(String name, Scriptable start) {
97                 if (name.equals("get")) return prefsGet;
98                 else if (name.equals("list")) return prefsList;
99                 else if (name.equals("put")) return prefsPut;
100                 else return null;
101             }
102         };
103
104     private static final JSObject.JSFunction prefsGet = new JSObject.JSFunction() {
105             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
106                 if (args.length != 1 || args[0] == null) return null;
107                 try {
108                     return ((Function)prefsRPC.get("get", null)).call(cx, null, null, new Object[] { args[0] });
109                 } catch (JavaScriptException jse) {
110                     Object val = jse.getValue();
111                     if (val instanceof JSObject && new Integer(1).equals(((JSObject)val).get("faultCode")))
112                         return null;
113                     throw jse;
114                 } catch (Exception e) {
115                     // FIXME
116                     throw new JavaScriptException(e.toString());
117                 }
118             }
119         };
120
121     private static final JSObject.JSFunction prefsPut = new JSObject.JSFunction() {
122             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
123                 if (args.length < 2 || args[0] == null) return null;
124                 try {
125                     return ((Function)prefsRPC.get("put", null)).call(cx, null, null, new Object[] { args[0].toString(), args[1] });
126                 } catch (JavaScriptException jse) {
127                     Object val = jse.getValue();
128                     if (val instanceof JSObject && new Integer(1).equals(((JSObject)val).get("faultCode")))
129                         return null;
130                     throw jse;
131                 } catch (Exception e) {
132                     // FIXME
133                     throw new JavaScriptException(e.toString());
134                 }
135             }
136         };
137
138     private static final JSObject.JSFunction prefsList = new JSObject.JSFunction() {
139             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
140                 if (args.length < 2 || args[0] == null) return null;
141                 try {
142                     return ((Function)prefsRPC.get("list", null)).call(cx, null, null, new Object[] { args[0].toString(), args[1] });
143                 } catch (JavaScriptException jse) {
144                     Object val = jse.getValue();
145                     if (val instanceof JSObject && new Integer(1).equals(((JSObject)val).get("faultCode")))
146                         return null;
147                     throw jse;
148                 } catch (Exception e) {
149                     // FIXME
150                     throw new JavaScriptException(e.toString());
151                 }
152             }
153         };
154
155     private static final JSObject.JSFunction prefsInvoke = new JSObject.JSFunction() {
156             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
157                 if (args.length < 2 || args[0] == null) return null;
158                 try {
159                     return ((Function)prefs.get("invoke")).call(cx, null, null, new Object[] { args[0].toString(), args[1], "megacz", "mypassword" });
160                 } catch (JavaScriptException jse) {
161                     Object val = jse.getValue();
162                     if (val instanceof JSObject && new Integer(1).equals(((JSObject)val).get("faultCode")))
163                         return null;
164                     throw jse;
165                 } catch (Exception e) {
166                     // FIXME
167                     throw new JavaScriptException(e.toString());
168                 }
169             }
170         };
171
172
173
174     // JSFunction Instances ///////////////////////////////////////////////////////////////////
175
176     private static final JSObject.JSFunction newBrowserWindow = new JSObject.JSFunction() {
177             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
178                 if (args.length != 1 || args[0] == null) return null;
179                 Platform.newBrowserWindow(args[0].toString());
180                 return null;
181             }
182         };
183
184     public static final JSObject.JSFunction yield = new JSObject.JSFunction() {
185             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
186                 sleep.call(cx, null, null, null);
187                 return null;
188             }
189         };
190
191     private static final JSObject.JSFunction println = new JSObject.JSFunction() {
192             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
193                 if (args.length == 1)
194                     if (Log.on) {
195                         String source = cx.interpreterSourceFile;
196                         if (source.endsWith("._")) source = source.substring(0, source.length() - 2);
197                         Log.log(source, args[0] == null ? "null" : args[0].toString());
198                     }
199                 return null;
200             }
201         };
202
203     private static final JSObject.JSFunction date = new JSObject.JSFunction() {
204             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
205                 try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "Date", args);
206                 } catch (Exception e) {
207                     if (Log.on) Log.log(this, "Exception in Context.newObject() -- this should never happen");
208                     if (Log.on) Log.log(this, e);
209                     return null;
210                 }
211             }
212         };
213
214     private static final JSObject.JSFunction regexp = new JSObject.JSFunction() {
215             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
216                 try { return Context.enter().newObject(org.xwt.util.JSObject.defaultObjects, "RegExp", args);
217                 } catch (Exception e) {
218                     if (Log.on) Log.log(this, "Exception in Context.newObject() -- this should never happen");
219                     if (Log.on) Log.log(this, e);
220                     return null;
221                 }
222             }
223         };
224
225     private static final JSObject.JSFunction listfonts = new JSObject.JSFunction() {
226             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
227                 return Context.enter().newArray(org.xwt.util.JSObject.defaultObjects,  Platform.listFonts());
228             }
229         };
230
231     private static final JSObject.JSFunction theme = new JSObject.JSFunction() {
232             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
233                 if (args.length != 2) return null;
234                 if (args[0] == null || args[1] == null) return null;
235
236                 for(int i=1; i<args.length; i++) {
237                     if (args[i] instanceof String) {
238                         String from = (String)args[0];
239                         String to = (String)args[i];
240                         if (Log.on) Log.log(this, "retheming from " + from + " to " + to);
241                         Resources.mapFrom.addElement(from);
242                         Resources.mapTo.addElement(to);
243                     }
244                 }
245
246                 Function callback = args[args.length - 1] instanceof Function ? (Function)args[args.length - 1] : null;
247                 Template.retheme(callback);
248                 return null;
249             }
250         };
251
252     private static final JSObject.JSFunction xmlrpc = new JSObject.JSFunction() {
253             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
254                 if (args.length != 1 || args[0] == null) return null;
255                 return new XMLRPC(args[0].toString(), "");
256             }
257         };
258
259     private static final JSObject.JSFunction soap = new JSObject.JSFunction() {
260             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
261                 if (args.length == 1 && args[0] != null) return new SOAP(args[0].toString(), "", null, null);
262                 else if (args.length == 2 && args[0] != null && args[1] != null)
263                     return new SOAP(args[0].toString(), "", args[1].toString(), null);
264                 else if (args.length == 3 && args[0] != null && args[1] != null && args[2] != null)
265                     return new SOAP(args[0].toString(), "", args[1].toString(), args[2].toString());
266                 else return null;
267             }
268         };
269
270     private static final JSObject.JSFunction textwidth = new JSObject.JSFunction() {
271             public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException {
272                 if (args.length < 1 || args.length > 2) return null;
273                 if (args[0] == null || (args.length == 2 && args[1] == null)) return null;
274                 String font = args.length == 1 ? Platform.getDefaultFont() : args[0].toString();
275                 String text = args.length == 1 ? args[0].toString() : args[1].toString();
276                 XWF xwf = XWF.getXWF(font);
277                 if (xwf == null) return new Integer(Platform.stringWidth(font, text));
278                 else return new Integer(xwf.stringWidth(text));
279             }
280         };
281
282
283     private static final JSObject.JSFunction textheight = new JSObject.JSFunction() {
284             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
285                 if (args.length > 1) return null;
286                 if (args.length == 1 && args[0] == null) return null;
287                 String font = args.length == 0 || args[0] == null ? Platform.getDefaultFont() : args[0].toString();
288                 XWF xwf = XWF.getXWF(font);
289                 if (xwf == null) return new Integer(Platform.getMaxAscent(font) + Platform.getMaxDescent(font));
290                 else return new Integer(xwf.getMaxAscent() + xwf.getMaxDescent());
291             }
292         };
293
294     private static final JSObject.JSFunction newBox = new JSObject.JSFunction() {
295             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
296
297                 if (args.length > 0)
298                     if (Log.on) Log.log(XWT.class, "DEPRECATED: xwt.newBox() with multiple arguments is deprecated; use xwt.newBox().apply() " +
299                                         Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
300
301                 Function callback = null;
302                 for(int i=1; i<args.length; i++)
303                     if (args[i] instanceof Function && callback == null)
304                         callback = (Function)args[i];
305
306                 Box ret = new Box(args.length == 0 || args[0] == null ? "box" : args[0].toString(), Template.defaultImportList, callback);
307
308                 for(int i=1; i<args.length; i++)
309                     if (args[i] instanceof Box)
310                         ret.put(ret.numChildren(), null, (Box)args[i]);
311                 for(int i=1; i<args.length; i++)
312                     if (args[i] instanceof Scriptable && !(args[i] instanceof Box) && !(args[i] instanceof Function)) {
313                         Scriptable s = (Scriptable)args[i];
314                         Object[] keys = s.getIds();
315
316                         // FIXME: need to ensure that this is putGlobally(), but still run traps...
317                         for(int j=0; j<keys.length; j++) ret.put(keys[j].toString(), null, s.get(keys[j].toString(), s));
318                     }
319                 return ret;
320             }
321         };
322
323     private static final JSObject.JSFunction sleep = new JSObject.JSFunction() {
324             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
325                 if (args != null && (args.length != 1 || args[0] == null)) return null;
326                 int i = args == null ? 0 : SpecialBoxProperty.stoi(args[0].toString());
327
328                 Thread thread = Thread.currentThread();
329                 if (!(thread instanceof ThreadMessage)) {
330                     if (Log.on) Log.log(this, "cannot sleep() or yield() in the foreground thread");
331                     return null;
332                 }
333                 ThreadMessage mythread = (ThreadMessage)thread;
334                 mythread.done.release();
335
336                 if (i > 0) try { Thread.sleep(i); } catch (Exception e) { }
337                 
338                 MessageQueue.add(mythread);
339                 mythread.go.block();
340                 return null;
341             }
342         };
343
344     private static final JSObject.JSFunction openFile = new JSObject.JSFunction() {
345             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
346                 if (args.length != 1) return null;
347                 String file = Platform.fileDialog(args[0].toString(), false);
348                 return file == null ? null : new ByteStream(file);
349             }
350         };
351
352     private static final JSObject.JSFunction saveFile = new JSObject.JSFunction() {
353             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
354                 if (args.length != 2) return null;
355                 if (!(args[1] instanceof ByteStream)) return null;
356                 String file = args[0].toString();
357                 if (safeFiles.get(Platform.isCaseSensitive() ? file : file.toLowerCase()) == null) {
358                     file = Platform.fileDialog(file, true);
359                     if (file == null) return null;
360                     safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object());
361                 }
362                 try {
363                     ((ByteStream)args[1]).writeTo(new FileOutputStream(file));
364                     return null;
365                 } catch (IOException e) {
366                     if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file");
367                     if (Log.on) Log.log(ByteStream.class, e);
368                     throw new JavaScriptException("error while writing a ByteStream to a file");
369                 }
370             }
371         };
372
373     private static final JSObject.JSFunction saveFileAs = new JSObject.JSFunction() {
374             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
375                 if (args.length != 2) return null;
376                 if (!(args[1] instanceof ByteStream)) return null;
377                 String file = args[0].toString();
378                 file = Platform.fileDialog(file, true);
379                 if (file == null) return null;
380                 safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object());
381                 try {
382                     ((ByteStream)args[1]).writeTo(new FileOutputStream(file));
383                     return null;
384                 } catch (IOException e) {
385                     if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file");
386                     if (Log.on) Log.log(ByteStream.class, e);
387                     throw new JavaScriptException("error while writing a ByteStream to a file");
388                 }
389             }
390         };
391
392     private static final JSObject.JSFunction utfEncode = new JSObject.JSFunction() {
393             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
394                 if (args == null || args.length != 1) return null;
395                 return new ByteStream(args[0].toString().getBytes());
396             }
397         };
398
399     
400     private static final JSObject.JSFunction parseHTML = new JSObject.JSFunction() {
401             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
402                 if (args == null || args.length != 1 || args[0] == null) return null;
403                 try {
404                     if (args[0] instanceof ByteStream) {
405                         return HTML.parseReader(new InputStreamReader(((ByteStream)args[0]).getInputStream()));
406                     } else {
407                         return HTML.parseReader(new StringReader(args[0].toString()));
408                     }
409                 } catch (IOException e) {
410                     if (Log.on) Log.log(HTML.class, "IO Exception while parsing HTML");
411                     if (Log.on) Log.log(HTML.class, e);
412                     throw new JavaScriptException("error while parsing HTML");
413                 }
414             }
415         };
416     
417     private static void recurse(String indent, String name, Object o, Context cx) {
418         if (!name.equals("")) name += " : ";
419
420         if (o == null) {
421             Log.log(cx.interpreterSourceFile, indent + name + "<null>");
422
423         } else if (o instanceof NativeArray) {
424             Log.log(cx.interpreterSourceFile, indent + name + "<array>");
425             NativeArray na = (NativeArray)o;
426             for(int i=0; i<na.jsGet_length(); i++)
427                 recurse(indent + "  ", i + "", na.get(i, null), cx);
428
429         } else if (!(o instanceof NativeDate) && (o instanceof JSObject || o instanceof ScriptableObject)) {
430             Log.log(cx.interpreterSourceFile, indent + name + "<object>");
431             Scriptable s = (Scriptable)o;
432             Object[] keys = s.getIds();
433             for(int i=0; i<keys.length; i++)
434                 recurse(indent + "  ", keys[i].toString(),
435                         keys[i] instanceof Integer ? s.get(((Integer)keys[i]).intValue(), null) : s.get(keys[i].toString(), null), cx);
436
437         } else {
438             Log.log(cx.interpreterSourceFile, indent + name + o);
439
440         }
441     }
442
443     static final JSObject.JSFunction recursivePrintObject = new JSObject.JSFunction() {
444             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
445                 if (args == null || args.length != 1) return null;
446                 recurse("", "", args[0], cx);
447                 return null;
448             }
449         };
450
451     private static final JSObject.JSFunction loadArchive = new JSObject.JSFunction() {
452             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
453                 if (!ThreadMessage.suspendThread()) return null;
454
455                 try {
456                     if (args == null || args.length < 1 || args[0] == null) return null;
457                     URL u = new URL(args[0].toString());
458                     
459                     Function callback = null;
460                     if (args.length == 2 && args[1] != null && args[1] instanceof Function) callback = (Function)args[1];
461                     
462                     if (!u.getFile().endsWith(".xwar")) {
463                         if (Log.on) Log.log(this, "Error: archive names must end with .xwar: " + u.getFile());
464                         throw new JavaScriptException("Error: archive names must end with .xwar: " + u.getFile());
465                     }
466                     
467                     if (u.getProtocol().equals("http")) {
468                         HTTP http = new HTTP(u.toString());
469                         if (Main.originAddr == null) {
470                             try {
471                                 Main.originAddr = InetAddress.getByName(u.getHost());
472                             } catch (UnknownHostException e) {
473                                 if (Log.on) Log.log(this, "couldn't resolve " + u.getHost() + "; proceeding without permissions");
474                                 Main.originAddr = InetAddress.getByName("0.0.0.0");
475                             }
476                         } else {
477                             Main.originAddr = InetAddress.getByName("0.0.0.0");
478                         }
479                         HTTP.HTTPInputStream in = http.GET();
480                         Resources.loadArchive(in, in.getContentLength(), callback);
481
482                     } else if (u.getProtocol().equals("file")) {
483                         if (Main.originAddr != null) {
484                             if (Log.on) Log.log(this, "scripts downloaded from the network may not load xwars from the local filesystem");
485                             throw new JavaScriptException("scripts downloaded from the network may not load xwars from the local filesystem");
486                         }
487                         Resources.loadArchive(new FileInputStream(u.getFile()), (int)new File(u.getFile()).length(), callback);
488                         
489                     } else {
490                         if (Log.on) Log.log(this, "unknown protocol \"" + u.getProtocol() + "\"");
491                         throw new JavaScriptException("unknown protocol \"" + u.getProtocol() + "\"");
492                     }
493                     
494                 } catch (MalformedURLException me) {
495                     if (Log.on) Log.log(this, "Malformed URL: " + args[0]);
496                     if (Log.on) Log.log(this, me);
497                     throw new JavaScriptException(me.toString());
498                     
499                 } catch (IOException ioe) {
500                     if (Log.on) Log.log(this, "IOException while loading archive:");
501                     if (Log.on) Log.log(this, ioe);
502                     throw new JavaScriptException(ioe.toString());
503
504                 } finally {
505                     ThreadMessage.resumeThread();
506
507                 }
508                 return null;
509             }
510         };
511
512     private static final JSObject.JSFunction prefetchImage = new JSObject.JSFunction() {
513             public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
514                 if (args == null || args.length < 1 || args[0] == null) return null;
515                 Box.getImage(args[0].toString(), args.length > 1 && args[1] instanceof Function ? (Function)args[1] : null);
516                 return null;
517             }
518         };
519
520 }
521
522
523
524
525