- public Object callMethod(Object method, JS.Array args, boolean checkOnly) throws JS.Exn {
- if(checkOnly) return Boolean.FALSE;
- Object o = get(method);
- if(o instanceof JS.Callable) {
- return ((JS.Callable)o).call(args);
- } else if(o == null) {
- throw new JS.Exn("Attempted to call non-existent method: " + method);
- } else {
- throw new JS.Exn("Attempted to call a non-method: " +method);
- }
- }
- }
-
- /** An exception which can be thrown and caught by JavaScript code */
- public static class Exn extends RuntimeException {
- private Object js = null;
- public Exn(Object js) { this.js = js; }
- public String toString() { return "JS.Exn: " + js; }
- public String getMessage() { return toString(); }
- public Object getObject() { return js; }
- }
-
- /** The publicly-visible face of JavaScript Array objects */
- public static class Array extends ArrayImpl {
- public Array() { }
- public Array(int size) { super(size); }
- public void setSize(int i) { super.setSize(i); }
- public int length() { return super.length(); }
- public Object elementAt(int i) { return super.elementAt(i); }
- public void addElement(Object o) { super.addElement(o); }
- public void setElementAt(Object o, int i) { super.setElementAt(o, i); }
- public Object get(Object key) { return super._get(key); }
- public void put(Object key, Object val) { super._put(key, val); }
- }
-
- /** Any object which becomes part of the scope chain must support this interface */
- public static class Scope extends ScopeImpl {
- public Scope(Scope parentScope) { this(parentScope, false); }
- public Scope(Scope parentScope, boolean sealed) { super(parentScope, sealed); }
- /** transparent scopes are not returned by THIS */
- public boolean isTransparent() { return super.isTransparent(); }
- public boolean has(Object key) { return super.has(key); }
- public Object get(Object key) { return super._get(key); }
- public void put(Object key, Object val) { super._put(key, val); }
- public void declare(String s) { super.declare(s); }
- }
-
- /** anything that is callable with the () operator */
- public static abstract class Callable extends JS.Obj {
- public abstract Object call(JS.Array args) throws JS.Exn;
- }
-
- /** a Callable which was compiled from JavaScript code */
- public static class CompiledFunction extends CompiledFunctionImpl {
- CompiledFunction(String sourceName, int firstLine, Reader sourceCode, Scope scope) throws IOException {
- super(sourceName, firstLine, sourceCode, scope);